1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 20:30:28 +02:00
* numbers.c, numbers.h (scm_log, scm_log10, scm_exp, scm_sqrt): New
	functions.
This commit is contained in:
Kevin Ryde 2006-09-23 01:16:50 +00:00
parent 10a7fe4c1a
commit c82f332e1e

View file

@ -70,10 +70,13 @@
#include "libguile/discouraged.h" #include "libguile/discouraged.h"
/* value per glibc, if not already defined */ /* values per glibc, if not already defined */
#ifndef M_LOG10E #ifndef M_LOG10E
#define M_LOG10E 0.43429448190325182765 #define M_LOG10E 0.43429448190325182765
#endif #endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
@ -6028,7 +6031,12 @@ SCM_DEFINE (scm_log, "log", 1, 0, 0,
{ {
/* ENHANCE-ME: When z is a bignum the logarithm will fit a double /* ENHANCE-ME: When z is a bignum the logarithm will fit a double
although the value itself overflows. */ although the value itself overflows. */
return scm_from_double (log (scm_to_double (z))); double re = scm_to_double (z);
double l = log (fabs (re));
if (re >= 0.0)
return scm_from_double (l);
else
return scm_c_make_rectangular (l, M_PI);
} }
} }
#undef FUNC_NAME #undef FUNC_NAME
@ -6054,7 +6062,12 @@ SCM_DEFINE (scm_log10, "log10", 1, 0, 0,
{ {
/* ENHANCE-ME: When z is a bignum the logarithm will fit a double /* ENHANCE-ME: When z is a bignum the logarithm will fit a double
although the value itself overflows. */ although the value itself overflows. */
return scm_from_double (log10 (scm_to_double (z))); double re = scm_to_double (z);
double l = log10 (fabs (re));
if (re >= 0.0)
return scm_from_double (l);
else
return scm_c_make_rectangular (l, M_LOG10E * M_PI);
} }
} }
#undef FUNC_NAME #undef FUNC_NAME