On Thu, 26 Oct 2006 04:10:20 -0500, Bill Hart <[EMAIL PROTECTED]> wrote: > Well, why does R(61/3) return the wrong thing then? 61/3 is an exact > expression, which should then be computed correctly. It's not. > None of this makes sense to me as a default behaviour by the way.
MPFR's arithmetic makes more sense if you view it in binary: sage: RealField(53)(61/3).str(2) '10100.010101010101010101010101010101010101010101010101' sage: (RR(61)/RR(3)).str(2) '10100.010101010101010101010101010101010101010101010101' sage: RealField(70)(61/3).str(2) '10100.01010101010101010101010101010101010101010101010101010101010101011' sage: RealField(100)(61/3).str(2) '10100.01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011' In decimal things like this seem ludicrous: sage: RealField(8,rnd='RNDU')(61/3).str(10) '20.38' sage: RealField(8,rnd='RNDD')(61/3).str(10) '20.25' However, in binary this is just: sage: RealField(8,rnd='RNDD')(61/3).str(2) '10100.010' sage: RealField(8,rnd='RNDU')(61/3).str(2) '10100.011' The arithmetic model of MPFR has been carefully thought through. You might want to read the mpfr manual, which discusses in detail what their model is for arithmetic. One neat aspect of it is that its behavior doesn't depend at all on the architecture of the computer on which it is running. Didier created a SAGE package for RealLib and somebody needs to do more work on that. You might like it, since presumably it could be relevant to such things... Also, Python has its own built in decimal module, which provides decimal arithmetic for applications like banking, where working in binary is not allowed. sage: import decimal sage: a = decimal.Decimal('61') sage: b = decimal.Decimal('3') sage: a/b Decimal("20.33333333333333333333333333") William --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---