Skip to content

Commit

Permalink
Fixes #4089. Math.log10 should use Java's log10 method
Browse files Browse the repository at this point in the history
enebo committed Aug 18, 2016
1 parent 0dc6fa9 commit 2b199e8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/src/main/java/org/jruby/RubyMath.java
Original file line number Diff line number Diff line change
@@ -447,13 +447,20 @@ public static RubyFloat log_19(IRubyObject recv, IRubyObject[] args) {
*/
@JRubyMethod(name = "log10", required = 1, module = true, visibility = Visibility.PRIVATE, compat = CompatVersion.RUBY1_8)
public static RubyFloat log10(IRubyObject recv, IRubyObject x) {
return log_common(recv, ((RubyFloat)RubyKernel.new_float(recv,x)).getDoubleValue(), 10, "log10");
double result = Math.log10(needFloat(x).getDoubleValue());
domainCheck(recv, result, "log10");
return RubyFloat.newFloat(recv.getRuntime(),result);
}

@JRubyMethod(name = "log10", required = 1, module = true, visibility = Visibility.PRIVATE, compat = CompatVersion.RUBY1_9)
public static RubyFloat log10_19(IRubyObject recv, IRubyObject x) {
double value = needFloat(x).getDoubleValue();
return log_common19(recv, value, 10, "log10");

if (value < 0) {
throw recv.getRuntime().newMathDomainError("log10");
}

return RubyFloat.newFloat(recv.getRuntime(), Math.log10(value));
}

/** Returns the base 2 logarithm of x.

0 comments on commit 2b199e8

Please sign in to comment.