aboutsummaryrefslogtreecommitdiffstats
path: root/math.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-07-12 11:53:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-07-12 11:53:43 +0000
commit0ba83958d042e19353c868f3bff446bf52da8148 (patch)
treec507b1e4a78c52a332b91c1755d9222be93d20a9 /math.c
parentbd2a6eed9460244c7940162b45a1fbdf44b1257b (diff)
downloadruby-0ba83958d042e19353c868f3bff446bf52da8148.tar.gz
math.c: use common constants
* math.c (math_log1, math_log10): use common math constants instead of math function calls. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r--math.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/math.c b/math.c
index c3fe7dbd09..a66c9bfb86 100644
--- a/math.c
+++ b/math.c
@@ -10,6 +10,9 @@
**********************************************************************/
#include "internal.h"
+#ifdef _MSC_VER
+# define _USE_MATH_DEFINES 1
+#endif
#include <float.h>
#include <math.h>
#include <errno.h>
@@ -408,6 +411,13 @@ math_exp(VALUE obj, VALUE x)
# define log10(x) ((x) < 0.0 ? nan("") : log10(x))
#endif
+#ifndef M_LN2
+# define M_LN2 0.693147180559945309417232121458176568
+#endif
+#ifndef M_LN10
+# define M_LN10 2.30258509299404568401799145468436421
+#endif
+
static double math_log1(VALUE x);
/*
@@ -466,7 +476,7 @@ math_log1(VALUE x)
/* check for pole error */
if (d == 0.0) return -INFINITY;
- return log(d) + numbits * log(2); /* log(d * 2 ** numbits) */
+ return log(d) + numbits * M_LN2; /* log(d * 2 ** numbits) */
}
#ifndef log2
@@ -559,7 +569,7 @@ math_log10(VALUE obj, VALUE x)
/* check for pole error */
if (d == 0.0) return DBL2NUM(-INFINITY);
- return DBL2NUM(log10(d) + numbits * log10(2)); /* log10(d * 2 ** numbits) */
+ return DBL2NUM(log10(d) + numbits * M_LN2/M_LN10); /* log10(d * 2 ** numbits) */
}
/*