From cc307f1f83f30a7e9792b0c8598ec20c6ddb27b3 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Tue, 4 Jun 2013 08:47:43 +0000 Subject: [PATCH] Disregard ERANGE from libm log when x = 0. This enables log to usefully raise the IEEE 754 divide-by-zero exception when the divide-by-zero exception is untrapped. --- src/microcode/flonum.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/microcode/flonum.c b/src/microcode/flonum.c index 26c45a183..322059809 100644 --- a/src/microcode/flonum.c +++ b/src/microcode/flonum.c @@ -188,10 +188,23 @@ DEFINE_PRIMITIVE ("FLONUM-LOG1P", Prim_flonum_log1p, 1, 1, 0) } #endif +DEFINE_PRIMITIVE ("FLONUM-LOG", Prim_flonum_log, 1, 1, 0) +{ + double x; + double result; + PRIMITIVE_HEADER (1); + x = (arg_flonum (1)); + if (! (x >= 0)) + error_bad_range_arg (1); + errno = 0; + result = (log (x)); + if ((errno != 0) && ((x != 0) || (errno != ERANGE))) + error_bad_range_arg (1); + FLONUM_RESULT (result); +} + DEFINE_PRIMITIVE ("FLONUM-EXP", Prim_flonum_exp, 1, 1, 0) SIMPLE_TRANSCENDENTAL_FUNCTION (exp) -DEFINE_PRIMITIVE ("FLONUM-LOG", Prim_flonum_log, 1, 1, 0) - RESTRICTED_TRANSCENDENTAL_FUNCTION (log, (x > 0)) DEFINE_PRIMITIVE ("FLONUM-SIN", Prim_flonum_sin, 1, 1, 0) SIMPLE_TRANSCENDENTAL_FUNCTION (sin) DEFINE_PRIMITIVE ("FLONUM-COS", Prim_flonum_cos, 1, 1, 0) -- 2.25.1