mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
Fix non-portable usage of isinf' in
max' and `min'
* numbers.c: Add new macros DOUBLE_IS_POSITIVE_INFINITY and DOUBLE_IS_NEGATIVE_INFINITY. (scm_max, scm_min): Use the new macros to detect particular infinities. Previously we checked the return value of `isinf' to determine the sign of the infinity, but that is not portable.
This commit is contained in:
parent
9da4074189
commit
041fccf6aa
1 changed files with 9 additions and 4 deletions
|
@ -83,6 +83,11 @@ typedef scm_t_signed_bits scm_t_inum;
|
|||
TODO: if it's available, use C99's isfinite(x) instead */
|
||||
#define DOUBLE_IS_FINITE(x) (!isinf(x) && !isnan(x))
|
||||
|
||||
/* On some platforms, isinf(x) returns 0, 1 or -1, indicating the sign
|
||||
of the infinity, but other platforms return a boolean only. */
|
||||
#define DOUBLE_IS_POSITIVE_INFINITY(x) (isinf(x) && ((x) > 0))
|
||||
#define DOUBLE_IS_NEGATIVE_INFINITY(x) (isinf(x) && ((x) < 0))
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
@ -5251,9 +5256,9 @@ scm_max (SCM x, SCM y)
|
|||
/* If neither (xx > yy) nor (xx < yy), then
|
||||
either they're equal or one is a NaN */
|
||||
else if (SCM_UNLIKELY (isnan (xx)))
|
||||
return (isinf (yy) == 1) ? y : x;
|
||||
return DOUBLE_IS_POSITIVE_INFINITY (yy) ? y : x;
|
||||
else if (SCM_UNLIKELY (isnan (yy)))
|
||||
return (isinf (xx) == 1) ? x : y;
|
||||
return DOUBLE_IS_POSITIVE_INFINITY (xx) ? x : y;
|
||||
/* xx == yy, but handle signed zeroes properly */
|
||||
else if (double_is_non_negative_zero (yy))
|
||||
return y;
|
||||
|
@ -5411,9 +5416,9 @@ scm_min (SCM x, SCM y)
|
|||
/* If neither (xx < yy) nor (xx > yy), then
|
||||
either they're equal or one is a NaN */
|
||||
else if (SCM_UNLIKELY (isnan (xx)))
|
||||
return (isinf (yy) == -1) ? y : x;
|
||||
return DOUBLE_IS_NEGATIVE_INFINITY (yy) ? y : x;
|
||||
else if (SCM_UNLIKELY (isnan (yy)))
|
||||
return (isinf (xx) == -1) ? x : y;
|
||||
return DOUBLE_IS_NEGATIVE_INFINITY (xx) ? x : y;
|
||||
/* xx == yy, but handle signed zeroes properly */
|
||||
else if (double_is_non_negative_zero (xx))
|
||||
return y;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue