summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-17 23:57:11 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-17 23:57:11 +0900
commit105bdba899fbb10aa51115c4cd074ea42eb9e3e6 (patch)
tree224d413b73d209dbf42e29be81ffaa6ea2a95123 /math.c
parentd70484f0eb176a7ef7274972ff92b88905ea0edc (diff)
Fix logarithm of 0 with base
Diffstat (limited to 'math.c')
-rw-r--r--math.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/math.c b/math.c
index 1e2af7aa75..6f0ddf9ec5 100644
--- a/math.c
+++ b/math.c
@@ -554,9 +554,8 @@ rb_math_log(int argc, const VALUE *argv)
double b = math_log_split(base, &numbits_2);
/* check for pole error */
if (d == 0.0) {
- if (b > 0.0) return DBL2NUM(HUGE_VAL);
- if (b < 0.0) return DBL2NUM(-HUGE_VAL);
- return DBL2NUM(nan(""));
+ // Already DomainError if b < 0.0
+ return b ? DBL2NUM(-HUGE_VAL) : DBL2NUM(NAN);
}
else if (b == 0.0) {
return DBL2NUM(-0.0);