def test_arithmetic(): """ Basic test on arithmetical operations. """ hi = 1.4142135623730951 lo = -9.6672933134529147e-17 x = (hi,lo) # defines the sqrt(2) print 'x = sqrt(2) = ', doubleDouble.str(x[0],x[1]) y = (1.0,0.0) z = doubleDouble.add(x[0],x[1],y[0],y[1]) print 'x + 1 = ', doubleDouble.str(z[0],z[1]) xx = doubleDouble.sub(z[0],z[1],y[0],y[1]) print 'x + 1 - 1 = ', doubleDouble.str(x[0],x[1]) x2 = doubleDouble.mul(x[0],x[1],x[0],x[1]) print 'x*x = ', doubleDouble.str(x2[0],x2[1]) x2dx = doubleDouble.div(x2[0],x2[1],x[0],x[1]) print 'x*x/x = ', doubleDouble.str(x2dx[0],x2dx[1])
def __sub__(self,other): """ Returns the difference of self and the other. """ z = doubleDouble.sub(self.high,self.low,other.high,other.low) return DoubleDouble(z[0],z[1])