Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
RealInterval: fix min/max(..., NaN, ...)
Browse files Browse the repository at this point in the history
  • Loading branch information
mezzarobba committed Sep 16, 2015
1 parent 559f73b commit 263a6ca
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/sage/rings/real_mpfi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3907,6 +3907,16 @@ cdef class RealIntervalFieldElement(sage.structure.element.RingElement):
sage: min(RIF(-1, 1), RIF(-100, 100)).endpoints()
(-1.00000000000000, 1.00000000000000)
Note that calls involving NaNs try to return a number when possible.
This is consistent with IEEE-754-2008 but may be surprising. ::
sage: RIF('nan').min(2, 1)
1
sage: RIF(-1/3).min(RIF('nan'))
-0.3333333333333334?
sage: RIF('nan').min(RIF('nan'))
[.. NaN ..]
.. SEEALSO::
:meth:`~sage.rings.real_mpfi.RealIntervalFieldElement.max`
Expand All @@ -3932,7 +3942,11 @@ cdef class RealIntervalFieldElement(sage.structure.element.RingElement):
else:
other = self._parent(_other)

if mpfr_cmp(&result.value.right, &other.value.left) <= 0:
if result.is_NaN():
result = other
elif other.is_NaN():
pass
elif mpfr_cmp(&result.value.right, &other.value.left) <= 0:
pass
elif mpfr_cmp(&other.value.right, &result.value.left) <= 0:
result = other
Expand Down Expand Up @@ -3997,6 +4011,16 @@ cdef class RealIntervalFieldElement(sage.structure.element.RingElement):
sage: max(RIF(-1, 1), RIF(-100, 100)).endpoints()
(-1.00000000000000, 1.00000000000000)
Note that calls involving NaNs try to return a number when possible.
This is consistent with IEEE-754-2008 but may be surprising. ::
sage: RIF('nan').max(1, 2)
2
sage: RIF(-1/3).max(RIF('nan'))
-0.3333333333333334?
sage: RIF('nan').max(RIF('nan'))
[.. NaN ..]
.. SEEALSO::
:meth:`~sage.rings.real_mpfi.RealIntervalFieldElement.min`
Expand All @@ -4022,7 +4046,11 @@ cdef class RealIntervalFieldElement(sage.structure.element.RingElement):
else:
other = self._parent(_other)

if mpfr_cmp(&result.value.right, &other.value.left) <= 0:
if result.is_NaN():
result = other
elif other.is_NaN():
pass
elif mpfr_cmp(&result.value.right, &other.value.left) <= 0:
result = other
elif mpfr_cmp(&other.value.right, &result.value.left) <= 0:
pass
Expand Down

0 comments on commit 263a6ca

Please sign in to comment.