#16385: Fix rounding ZZ -> Python float
-------------------------------------+-------------------------------------
       Reporter:  jdemeyer           |        Owner:
           Type:  defect             |       Status:  positive_review
       Priority:  major              |    Milestone:  sage-6.3
      Component:  basic arithmetic   |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Jeroen Demeyer     |    Reviewers:  Christoph Lauter,
Report Upstream:  N/A                |  Marc Mezzarobba
         Branch:                     |  Work issues:
  u/jdemeyer/ticket/16385            |       Commit:
   Dependencies:                     |  04138f3d9118767c4062f4a7166b89b591846e3a
                                     |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by mmezzarobba):

 * status:  needs_review => positive_review
 * reviewer:   => Christoph Lauter, Marc Mezzarobba


Comment:

 Looks good to me. But Christoph Lauter sitting next to me noticed that
 expressions like `1.0/0.0` raise the ''Division by zero'' FP exception,
 while IEEE-754 conversions are supposed to raise ''Overflow'' when the
 result is too large to be represented in the target format.

 Another minor issue is that your `mpz_get_d_nearest` actually assumes that
 the current hardware rounding mode is round-to-nearest, because the final
 call to `ldexp` can overflow:
 {{{
 sage: b = 2^1024-1
 sage: float(b)
 inf
 sage: from ctypes import cdll
 sage: from ctypes.util import find_library
 sage: libm = cdll.LoadLibrary(find_library('m'))
 sage: FE_TOWARDZERO = int(0xc00)
 sage: libm.fesetround(FE_TOWARDZERO)
 0
 sage: float(b)
 1.7976931348623157e+308
 }}}

 But I don't know if we really want to go into this kind of business in
 sage, and your patch clearly improves the previous implementation. So I'll
 give it positive review and let you decide if you want to support FP flags
 and non-default rounding modes.

 Christoph also suggests to simplify the code a bit by remplacing the part
 that rounds from 64 to 63 bits by something like
 {{{
 d = <double> ((q64 << 1 ) | !remainder_is_zero)
 }}}
 (Of course, this version also assumes that the FPU rounds to nearest.)

--
Ticket URL: <http://trac.sagemath.org/ticket/16385#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 http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to