diff options
-rw-r--r-- | cmp_abs.c | 21 | ||||
-rw-r--r-- | mpfr.texi | 5 |
2 files changed, 15 insertions, 11 deletions
@@ -24,8 +24,8 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-impl.h" -/* returns sign(abs(b) - abs(c)) - b and c must be real numbers */ +/* Return a positive value if abs(b) > abs(c), 0 if abs(b) = abs(c), and + a negative value if abs(b) < abs(c). Neither b nor c may be NaN. */ int mpfr_cmpabs (mpfr_srcptr b, mpfr_srcptr c) @@ -34,13 +34,18 @@ mpfr_cmpabs (mpfr_srcptr b, mpfr_srcptr c) mp_size_t bn, cn; mp_limb_t *bp, *cp; - MPFR_ASSERTN(MPFR_IS_FP(b)); - MPFR_ASSERTN(MPFR_IS_FP(c)); + MPFR_ASSERTN (! MPFR_IS_NAN (b)); + MPFR_ASSERTN (! MPFR_IS_NAN (c)); - if (MPFR_IS_ZERO(b)) - return MPFR_IS_ZERO(c) ? 0 : -1; - if (MPFR_IS_ZERO(c)) - return 1; + if (MPFR_IS_INF (b)) + return ! MPFR_IS_INF (c); + if (MPFR_IS_INF (c)) + return -1; + + if (MPFR_IS_ZERO (c)) + return ! MPFR_IS_ZERO (b); + if (MPFR_IS_ZERO (b)) + return -1; be = MPFR_GET_EXP (b); ce = MPFR_GET_EXP (c); @@ -1091,7 +1091,7 @@ Compare @var{op1} and @var{op2}. Return a positive value if @math{@var{op1} > @math{@var{op1} < @var{op2}}. Both @var{op1} and @var{op2} are considered to their full own precision, which may differ. -It is not allowed that one of the operands is NaN (Not-a-Number). +If one of the operands is NaN (Not-a-Number), the behavior is undefined. @end deftypefun @deftypefun int mpfr_cmp_ui_2exp (mpfr_t @var{op1}, unsigned long int @var{op2}, mp_exp_t @var{e}) @@ -1104,8 +1104,7 @@ the power @var{e}}. Similar as above. Compare @math{|@var{op1}|} and @math{|@var{op2}|}. Return a positive value if @math{|@var{op1}| > |@var{op2}|}, zero if @math{|@var{op1}| = |@var{op2}|}, and a negative value if @math{|@var{op1}| < |@var{op2}|}. -It is not allowed that one of the operands is NaN (Not-a-Number) or an -infinity. +If one of the operands is NaN (Not-a-Number), the behavior is undefined. @end deftypefun @deftypefun int mpfr_eq (mpfr_t @var{op1}, mpfr_t @var{op2}, unsigned long int @var{op3}) |