From: Taylor R Campbell Date: Tue, 4 Jun 2013 08:47:43 +0000 (+0000) Subject: Disregard ERANGE from libm log when x = 0. X-Git-Tag: release-9.2.0~165 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=cc307f1f83f30a7e9792b0c8598ec20c6ddb27b3;p=mit-scheme.git 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. --- 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)