Ask Your Question

Revision history [back]

Actually, it seems not to be even worse! The sagebook is right in saying that RDF rounds its computations to the nearest:

sage: sage: print "RDF ", RealField(100)(RDF(1)/RDF(10)), RealField(100)(RDF(-1)/RDF(10))
RDF  0.10000000000000000555111512313 -0.10000000000000000555111512313
sage: for rounding in ['RNDZ','RNDD','RNDU','RNDN']:
....:     R = RealField(prec=53,rnd=rounding)
....:     print rounding, RealField(100)(R(1)/R(10)), RealField(100)(R(-1)/R(10))
RNDZ 0.099999999999999991673327315311 -0.099999999999999991673327315311
RNDD 0.099999999999999991673327315311 -0.10000000000000000555111512313
RNDU 0.10000000000000000555111512313 -0.099999999999999991673327315311
RNDN 0.10000000000000000555111512313 -0.10000000000000000555111512313

But the conversion from QQ to RDF rounds towards zero:

sage: print "RDF ", RealField(100)(RDF(1/10)), RealField(100)(RDF(-1/10))
RDF  0.099999999999999991673327315311 -0.099999999999999991673327315311
sage: for rounding in ['RNDZ','RNDD','RNDU','RNDN']:
....:     R = RealField(prec=53,rnd=rounding)
....:     print rounding, RealField(100)(R(1/10)), RealField(100)(R(-1/10))
....:     
RNDZ 0.099999999999999991673327315311 -0.099999999999999991673327315311
RNDD 0.099999999999999991673327315311 -0.10000000000000000555111512313
RNDU 0.10000000000000000555111512313 -0.099999999999999991673327315311
RNDN 0.10000000000000000555111512313 -0.10000000000000000555111512313

See trac ticket 14416.

Actually, it seems not to be even worse! The sagebook is right in saying that RDF rounds its computations to the nearest:

sage: sage: print "RDF ", RealField(100)(RDF(1)/RDF(10)), RealField(100)(RDF(-1)/RDF(10))
RDF  0.10000000000000000555111512313 -0.10000000000000000555111512313
sage: for rounding in ['RNDZ','RNDD','RNDU','RNDN']:
....:     R = RealField(prec=53,rnd=rounding)
....:     print rounding, RealField(100)(R(1)/R(10)), RealField(100)(R(-1)/R(10))
RNDZ 0.099999999999999991673327315311 -0.099999999999999991673327315311
RNDD 0.099999999999999991673327315311 -0.10000000000000000555111512313
RNDU 0.10000000000000000555111512313 -0.099999999999999991673327315311
RNDN 0.10000000000000000555111512313 -0.10000000000000000555111512313

But the conversion from QQ to RDF rounds towards zero:

sage: print "RDF ", RealField(100)(RDF(1/10)), RealField(100)(RDF(-1/10))
RDF  0.099999999999999991673327315311 -0.099999999999999991673327315311
sage: for rounding in ['RNDZ','RNDD','RNDU','RNDN']:
....:     R = RealField(prec=53,rnd=rounding)
....:     print rounding, RealField(100)(R(1/10)), RealField(100)(R(-1/10))
....:     
RNDZ 0.099999999999999991673327315311 -0.099999999999999991673327315311
RNDD 0.099999999999999991673327315311 -0.10000000000000000555111512313
RNDU 0.10000000000000000555111512313 -0.099999999999999991673327315311
RNDN 0.10000000000000000555111512313 -0.10000000000000000555111512313

See trac ticket 14416.