Revision history [back]

As far as I know there's no way to globally change the precision of computations over the real numbers. However, using RealField you can define variables (real numbers) that will only compute up to a desired precision. First note that Sage's "default" RealField, called RR, has 54 bits of precision:

sage: RR
Real Field with 53 bits of precision
sage: a = RR(1); b = RR(2)
sage: c = a+b
sage: c
3.00000000000000
sage: parent(c)
Real Field with 53 bits of precision


That last line shows that if you add two elements of RR you indeed get an element of RR in return. However, I can define lower precision real numbers like so:

sage: RF = RealField(10); RF
Real Field with 10 bits of precision
sage: a = RF(1); b = RF(2)
sage: c = a+b; c
3.0
sage: parent(c)
Real Field with 10 bits of precision


So the bottom line is that if you make sure that call of your calculations are in the field RealField(prec) then they will be with prec precision. Note that you can define matrices, vectors, polynomial rings, and what have you over RealField(prec) as well:

sage: RF = RealField(10)
sage: M = matrix(RF,[[1,0],[0,1]]); M
[ 1.0 0.00]
[0.00  1.0]
sage: parent(M)
Full MatrixSpace of 2 by 2 dense matrices over Real Field with 10 bits of precision


Finally, the constructor ComplexField is the complex analogue of RealField.