#16769: Conversion RR -> QQ wrong for exact integers
------------------------------------+------------------------
Reporter: jdemeyer | Owner:
Type: defect | Status: new
Priority: major | Milestone: sage-6.4
Component: basic arithmetic | Resolution:
Keywords: | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
------------------------------------+------------------------
Comment (by nbruin):
Any element of RR of absolute value at least 2^52^ can be expressed
"exactly" as an integer:
{{{
sage: a=RR(2^52)
sage: s,m,e=a.sign_mantissa_exponent()
sage: s,m,e
(1, 4503599627370496, 0)
sage: s*m*2^e == a
True
}}}
simply because `e` will be non-negative for such numbers.
Indeed, any float can be expressed exactly as a rational number: it's the
number `s*m*2^e` that is used internally. The reason why we're not using
that is basically this:
{{{
sage: a=RR(1/3)
sage: s,m,e=a.sign_mantissa_exponent()
sage: s*m*2^e
6004799503160661/18014398509481984
}}}
It's much nicer to get `1/3` back.
Indeed, the definition of "simplest rational" doesn't seem so useful
anymore by the time you enter the range where the denominator is
guaranteed to be 1. However, depending on getting an exact number back
after going through RR is almost certainly a bug somewhere. So I don't
think we should go out of our way to guarantee it. If you absolutely want
access to the internal representation, there's `sign_mantissa_exponent`
anyway.
The key is, the map `ZZ->RR` is not injective. So any section in the other
direction is not going to compose to the identity on `ZZ`. It's basically
an implementation detail that `ZZ(2^54)` maps to an element in `RR` that
internally is represented by something that amounts to exactly that
integer.
--
Ticket URL: <http://trac.sagemath.org/ticket/16769#comment:6>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.