#15337: Speed up ulp() method of real_mpfr.pyx
-------------------------+-------------------------------------------------
Reporter: | Owner:
jdemeyer | Status: needs_work
Type: | Milestone: sage-5.13
enhancement | Resolution:
Priority: minor | Merged in:
Component: basic | Reviewers:
arithmetic | Work issues: segfault in fp_rank, error in
Keywords: | nextabove
Authors: | Commit:
Jeroen Demeyer | Stopgaps:
Report Upstream: N/A |
Branch: |
Dependencies: |
-------------------------+-------------------------------------------------
Changes (by zimmerma):
* status: needs_review => needs_work
* work_issues: => segfault in fp_rank, error in nextabove
Comment:
"Adding or subtracting something less than half an ulp always gives the
same number (unless the number is exactly a power of 2...)": the case of
the opposite of a power of 2 is missing here, also this assumes the
rounding mode is to nearest.
I don't see the logic of returning {{{self}}} for NaN but not for
infinities.
Since the patch also adds tests for {{{fp_rank}}} (which I discovered) I
tested it too:
{{{
sage: a=RR(0).ulp()
sage: a.exact_rational()
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call
last)
<ipython-input-22-2b55db8a739a> in <module>()
----> 1 a.exact_rational()
/localdisk/tmp/sage-5.12/local/lib/python2.7/site-
packages/sage/rings/real_mpfr.so in
sage.rings.real_mpfr.RealNumber.exact_rational
(sage/rings/real_mpfr.c:18776)()
/localdisk/tmp/sage-5.12/local/lib/python2.7/site-
packages/sage/rings/integer.so in sage.rings.integer.Integer.__pow__
(sage/rings/integer.c:14022)()
RuntimeError: Segmentation fault
}}}
Finally this looks strange:
{{{
sage: a=RR(0).ulp()
sage: a.str(16)
'1.0000000000000@-1152921504606846976'
sage: b=a.nextabove()
sage: b.str(16)
'1.0000000000001@-1152921504606846976'
}}}
If {{{a}}} is the smallest positive non-zero number, then the next number
should be {{{2*a}}}. In other words, the difference between two floating-
point numbers is always a multiple of {{{a}}} (and thus always a floating-
point number), which is not the case here:
{{{
sage: b-a
0.000000000000000
}}}
Paul
--
Ticket URL: <http://trac.sagemath.org/ticket/15337#comment:11>
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/groups/opt_out.