mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-10 05:50:26 +02:00
Use Gnulib's 'copysign' in numbers.c.
* libguile/numbers.c (double_is_non_negative_zero): Remove. (idbl2str, scm_max, scm_min, scm_angle, log_of_shifted_double, scm_log10): Use 'copysign' to check signs of zeroes, instead of 'double_is_non_negative_zero'.
This commit is contained in:
parent
8ba5674805
commit
e1592f8a40
1 changed files with 10 additions and 18 deletions
|
@ -654,14 +654,6 @@ scm_i_fraction2double (SCM z)
|
||||||
SCM_FRACTION_DENOMINATOR (z));
|
SCM_FRACTION_DENOMINATOR (z));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
double_is_non_negative_zero (double x)
|
|
||||||
{
|
|
||||||
static double zero = 0.0;
|
|
||||||
|
|
||||||
return !memcmp (&x, &zero, sizeof(double));
|
|
||||||
}
|
|
||||||
|
|
||||||
static SCM
|
static SCM
|
||||||
scm_i_from_double (double val)
|
scm_i_from_double (double val)
|
||||||
{
|
{
|
||||||
|
@ -5368,7 +5360,7 @@ idbl2str (double dbl, char *a, int radix)
|
||||||
}
|
}
|
||||||
else if (dbl == 0.0)
|
else if (dbl == 0.0)
|
||||||
{
|
{
|
||||||
if (!double_is_non_negative_zero (dbl))
|
if (copysign (1.0, dbl) < 0.0)
|
||||||
a[ch++] = '-';
|
a[ch++] = '-';
|
||||||
strcpy (a + ch, "0.0");
|
strcpy (a + ch, "0.0");
|
||||||
return ch + 3;
|
return ch + 3;
|
||||||
|
@ -7272,10 +7264,10 @@ scm_max (SCM x, SCM y)
|
||||||
else if (SCM_UNLIKELY (xx != yy))
|
else if (SCM_UNLIKELY (xx != yy))
|
||||||
return (xx != xx) ? x : y; /* Return the NaN */
|
return (xx != xx) ? x : y; /* Return the NaN */
|
||||||
/* xx == yy, but handle signed zeroes properly */
|
/* xx == yy, but handle signed zeroes properly */
|
||||||
else if (double_is_non_negative_zero (yy))
|
else if (copysign (1.0, yy) < 0.0)
|
||||||
return y;
|
|
||||||
else
|
|
||||||
return x;
|
return x;
|
||||||
|
else
|
||||||
|
return y;
|
||||||
}
|
}
|
||||||
else if (SCM_FRACTIONP (y))
|
else if (SCM_FRACTIONP (y))
|
||||||
{
|
{
|
||||||
|
@ -7431,10 +7423,10 @@ scm_min (SCM x, SCM y)
|
||||||
else if (SCM_UNLIKELY (xx != yy))
|
else if (SCM_UNLIKELY (xx != yy))
|
||||||
return (xx != xx) ? x : y; /* Return the NaN */
|
return (xx != xx) ? x : y; /* Return the NaN */
|
||||||
/* xx == yy, but handle signed zeroes properly */
|
/* xx == yy, but handle signed zeroes properly */
|
||||||
else if (double_is_non_negative_zero (xx))
|
else if (copysign (1.0, xx) < 0.0)
|
||||||
return y;
|
|
||||||
else
|
|
||||||
return x;
|
return x;
|
||||||
|
else
|
||||||
|
return y;
|
||||||
}
|
}
|
||||||
else if (SCM_FRACTIONP (y))
|
else if (SCM_FRACTIONP (y))
|
||||||
{
|
{
|
||||||
|
@ -9295,7 +9287,7 @@ SCM_PRIMITIVE_GENERIC (scm_angle, "angle", 1, 0, 0,
|
||||||
else if (SCM_REALP (z))
|
else if (SCM_REALP (z))
|
||||||
{
|
{
|
||||||
double x = SCM_REAL_VALUE (z);
|
double x = SCM_REAL_VALUE (z);
|
||||||
if (x > 0.0 || double_is_non_negative_zero (x))
|
if (copysign (1.0, x) > 0.0)
|
||||||
return flo0;
|
return flo0;
|
||||||
else
|
else
|
||||||
return scm_i_from_double (atan2 (0.0, -1.0));
|
return scm_i_from_double (atan2 (0.0, -1.0));
|
||||||
|
@ -9945,7 +9937,7 @@ log_of_shifted_double (double x, long shift)
|
||||||
{
|
{
|
||||||
double ans = log (fabs (x)) + shift * M_LN2;
|
double ans = log (fabs (x)) + shift * M_LN2;
|
||||||
|
|
||||||
if (x > 0.0 || double_is_non_negative_zero (x))
|
if (copysign (1.0, x) > 0.0)
|
||||||
return scm_i_from_double (ans);
|
return scm_i_from_double (ans);
|
||||||
else
|
else
|
||||||
return scm_c_make_rectangular (ans, M_PI);
|
return scm_c_make_rectangular (ans, M_PI);
|
||||||
|
@ -10061,7 +10053,7 @@ SCM_PRIMITIVE_GENERIC (scm_log10, "log10", 1, 0, 0,
|
||||||
{
|
{
|
||||||
double re = scm_to_double (z);
|
double re = scm_to_double (z);
|
||||||
double l = log10 (fabs (re));
|
double l = log10 (fabs (re));
|
||||||
if (re > 0.0 || double_is_non_negative_zero (re))
|
if (copysign (1.0, re) > 0.0)
|
||||||
return scm_i_from_double (l);
|
return scm_i_from_double (l);
|
||||||
else
|
else
|
||||||
return scm_c_make_rectangular (l, M_LOG10E * M_PI);
|
return scm_c_make_rectangular (l, M_LOG10E * M_PI);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue