diff options
-rw-r--r-- | doc/ref/api-data.texi | 13 | ||||
-rw-r--r-- | libguile/numbers.c | 10 | ||||
-rw-r--r-- | libguile/numbers.h | 2 | ||||
-rw-r--r-- | test-suite/standalone/test-conversion.c | 33 |
4 files changed, 58 insertions, 0 deletions
diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi index 9825bef86..f9b39b61d 100644 --- a/doc/ref/api-data.texi +++ b/doc/ref/api-data.texi @@ -747,12 +747,25 @@ otherwise. @end deffn +@deftypefn {C Function} int scm_is_exact (SCM z) +Return a @code{1} if the number @var{z} is exact, and @code{0} +otherwise. This is equivalent to @code{scm_is_true (scm_exact_p (z))}. + +An alternate approch to testing the exactness of a number is to +use @code{scm_is_signed_integer} or @code{scm_is_unsigned_integer}. +@end deftypefn + @deffn {Scheme Procedure} inexact? z @deffnx {C Function} scm_inexact_p (z) Return @code{#t} if the number @var{z} is inexact, @code{#f} else. @end deffn +@deftypefn {C Function} int scm_is_inexact (SCM z) +Return a @code{1} if the number @var{z} is inexact, and @code{0} +otherwise. This is equivalent to @code{scm_is_true (scm_inexact_p (z))}. +@end deftypefn + @deffn {Scheme Procedure} inexact->exact z @deffnx {C Function} scm_inexact_to_exact (z) Return an exact number that is numerically closest to @var{z}, when diff --git a/libguile/numbers.c b/libguile/numbers.c index b01af9f36..e34c60ef3 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -536,6 +536,11 @@ SCM_PRIMITIVE_GENERIC (scm_exact_p, "exact?", 1, 0, 0, } #undef FUNC_NAME +int +scm_is_exact (SCM val) +{ + return scm_is_true (scm_exact_p (val)); +} SCM_PRIMITIVE_GENERIC (scm_inexact_p, "inexact?", 1, 0, 0, (SCM x), @@ -552,6 +557,11 @@ SCM_PRIMITIVE_GENERIC (scm_inexact_p, "inexact?", 1, 0, 0, } #undef FUNC_NAME +int +scm_is_inexact (SCM val) +{ + return scm_is_true (scm_inexact_p (val)); +} SCM_PRIMITIVE_GENERIC (scm_odd_p, "odd?", 1, 0, 0, (SCM n), diff --git a/libguile/numbers.h b/libguile/numbers.h index d98583039..d3a344443 100644 --- a/libguile/numbers.h +++ b/libguile/numbers.h @@ -165,6 +165,7 @@ typedef struct scm_t_complex SCM_API SCM scm_exact_p (SCM x); +SCM_API int scm_is_exact (SCM x); SCM_API SCM scm_odd_p (SCM n); SCM_API SCM scm_even_p (SCM n); SCM_API SCM scm_finite_p (SCM x); @@ -241,6 +242,7 @@ SCM_API SCM scm_real_p (SCM x); SCM_API SCM scm_rational_p (SCM z); SCM_API SCM scm_integer_p (SCM x); SCM_API SCM scm_inexact_p (SCM x); +SCM_API int scm_is_inexact (SCM x); SCM_API SCM scm_num_eq_p (SCM x, SCM y); SCM_API SCM scm_less_p (SCM x, SCM y); SCM_API SCM scm_gr_p (SCM x, SCM y); diff --git a/test-suite/standalone/test-conversion.c b/test-suite/standalone/test-conversion.c index 124ae9dbd..09b74bf17 100644 --- a/test-suite/standalone/test-conversion.c +++ b/test-suite/standalone/test-conversion.c @@ -1079,6 +1079,37 @@ test_locale_strings () } static void +test_is_exact () +{ + if (1 != scm_is_exact (scm_c_eval_string ("3"))) + { + fprintf (stderr, "fail: scm_is_exact (\"3\") = 1\n"); + exit (EXIT_FAILURE); + } + if (0 != scm_is_exact (scm_c_eval_string ("3.0"))) + { + fprintf (stderr, "fail: scm_is_exact (\"3.0\") = 0\n"); + exit (EXIT_FAILURE); + } +} + +static void +test_is_inexact () +{ + if (1 !=scm_is_inexact (scm_c_eval_string ("3.0"))) + { + fprintf (stderr, "fail: scm_is_inexact (\"3.0\") = 1\n"); + exit (EXIT_FAILURE); + } + if (0 != scm_is_inexact (scm_c_eval_string ("3"))) + { + fprintf (stderr, "fail: scm_is_inexact (\"3\") = 0\n"); + exit (EXIT_FAILURE); + } +} + + +static void tests (void *data, int argc, char **argv) { test_is_signed_integer (); @@ -1091,6 +1122,8 @@ tests (void *data, int argc, char **argv) test_from_double (); test_to_double (); test_locale_strings (); + test_is_exact (); + test_is_inexact (); } int |