Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Slightly simplified, your question is about the following:

sage: RealField(150)( RDF(1)/RDF(10) )       # case 1
sage: RealField(150)( RR(1)/RR(10) )         # case 2


sage: R = RealField(prec=53, rnd='RNDZ')
sage: RealField(150)( R(1)/R(10) )           # case 3
sage: RealField(150)( RDF(1/10) )            # case 4

The first and second cases make guarantees about IEEE floating point behavior and therefore must yield the same answer. The third case explicitly states that it is rounding towards zero, and its to be expected that you get a slightly different answer with different rounding. The fourth case punts to the __float__ method of rationals, which is

def __float__(self):
    Return floating point approximation to ``self`` as a Python float.

    OUTPUT: float


        sage: (-4/17).__float__()
        sage: float(-4/17)
    return mpq_get_d(self.value)

According to the GMP/MPIR docs, mpq_get_d rounds towards zero so you get the same answer as in the third case.