--- numbers.c.~1.191.~ 2003-06-05 01:56:18.000000000 +1000 +++ numbers.c 2003-06-12 10:59:40.000000000 +1000 @@ -39,6 +39,9 @@ */ +/* tell glibc (2.3) to give prototypes for C99 trunc() and round() */ +#define _GNU_SOURCE + #if HAVE_CONFIG_H # include #endif @@ -263,8 +266,6 @@ #endif } -#define isfinite(x) (! xisinf (x)) - SCM_DEFINE (scm_inf_p, "inf?", 1, 0, 0, (SCM n), "Return @code{#t} if @var{n} is infinite, @code{#f}\n" @@ -3643,61 +3644,87 @@ } #undef FUNC_NAME -SCM_GPROC1 (s_asinh, "$asinh", scm_tc7_dsubr, (SCM (*)()) scm_asinh, g_asinh); -/* "Return the inverse hyperbolic sine of @var{x}." - */ + double scm_asinh (double x) { +#if HAVE_ASINH + return asinh (x); +#else +#define asinh scm_asinh return log (x + sqrt (x * x + 1)); +#endif } +SCM_GPROC1 (s_asinh, "$asinh", scm_tc7_dsubr, (SCM (*)()) asinh, g_asinh); +/* "Return the inverse hyperbolic sine of @var{x}." + */ -SCM_GPROC1 (s_acosh, "$acosh", scm_tc7_dsubr, (SCM (*)()) scm_acosh, g_acosh); -/* "Return the inverse hyperbolic cosine of @var{x}." - */ double scm_acosh (double x) { +#if HAVE_ACOSH + return acosh (x); +#else +#define acosh scm_acosh return log (x + sqrt (x * x - 1)); +#endif } +SCM_GPROC1 (s_acosh, "$acosh", scm_tc7_dsubr, (SCM (*)()) acosh, g_acosh); +/* "Return the inverse hyperbolic cosine of @var{x}." + */ -SCM_GPROC1 (s_atanh, "$atanh", scm_tc7_dsubr, (SCM (*)()) scm_atanh, g_atanh); -/* "Return the inverse hyperbolic tangent of @var{x}." - */ double scm_atanh (double x) { +#if HAVE_ATANH + return atanh (x); +#else +#define atanh scm_atanh return 0.5 * log ((1 + x) / (1 - x)); +#endif } +SCM_GPROC1 (s_atanh, "$atanh", scm_tc7_dsubr, (SCM (*)()) atanh, g_atanh); +/* "Return the inverse hyperbolic tangent of @var{x}." + */ -SCM_GPROC1 (s_truncate, "truncate", scm_tc7_dsubr, (SCM (*)()) scm_truncate, g_truncate); -/* "Round the inexact number @var{x} towards zero." - */ double scm_truncate (double x) { +#if HAVE_TRUNC + return trunc (x); +#else +#define trunc scm_truncate if (x < 0.0) return -floor (-x); return floor (x); +#endif } +SCM_GPROC1 (s_truncate, "truncate", scm_tc7_dsubr, (SCM (*)()) trunc, g_truncate); +/* "Round the inexact number @var{x} towards zero." + */ -SCM_GPROC1 (s_round, "round", scm_tc7_dsubr, (SCM (*)()) scm_round, g_round); -/* "Round the inexact number @var{x}. If @var{x} is halfway between two\n" - * "numbers, round towards even." - */ double scm_round (double x) { +#if HAVE_ROUND + return round (x); +#else +#define round scm_round double plus_half = x + 0.5; double result = floor (plus_half); /* Adjust so that the scm_round is towards even. */ return (plus_half == result && plus_half / 2 != floor (plus_half / 2)) ? result - 1 : result; +#endif } +SCM_GPROC1 (s_round, "round", scm_tc7_dsubr, (SCM (*)()) scm_round, g_round); +/* "Round the inexact number @var{x}. If @var{x} is halfway between two\n" + * "numbers, round towards even." + */ SCM_GPROC1 (s_i_floor, "floor", scm_tc7_dsubr, (SCM (*)()) floor, g_i_floor); @@ -3973,7 +4000,7 @@ long lu = (long) u; if (SCM_FIXABLE (lu)) { return SCM_MAKINUM (lu); - } else if (isfinite (u) && !xisnan (u)) { + } else if (!xisinf (u) && !xisnan (u)) { return scm_i_dbl2big (u); } else { scm_num_overflow (s_scm_inexact_to_exact);