Hi Simon, Simon King wrote: > According to IEEE 754, the default rounding mode for floating-point > operations is "round half to even". However, in examples it seems that > the rounding roule in RR is: "round half away from zero if the total > number of decimal digits in the result is odd and towards zero if the > total number of decimal digits of the result is even
I don't think I'm able to provide a complete answer, but here a a few elements. In principle, I think both RR and RDF should comply with IEEE-754 rounding rules (in the case of RDF, provided your platform does). In particular, simply converting a rational number to a certain RealField should (as far as I understand) round it to that field's precision according to that field's rounding mode. However, the examples you posted to sage-support, e.g., sage: round(3.55, ndigits=1) 3.5 sage: round(3.555, ndigits=2) 3.56 test much more than that. First, the round() toplevel function is a huge mess, see #25827 for some observations about it. Second, when you write 3.55, the preparser does not turn that into code that creates a RealNumber. An intermediate type called RealLiteral is used, with its own “features” related to rounding, see in particular #15542. Third, while any binary floating-point number can in principle be represented exactly in decimal, Sage sometimes tries to be clever when displaying floating-point numbers, which can involve rounding them again, see in particular the docstring of RealNumber.str(). Hope this helps... -- Marc -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/r6i6ip%242sdn%241%40ciao.gmane.io.