Skip to content

Commit cc0c818

Browse files
authored
Merge pull request #9078 from headius/math_expm1_log1p
Add Math.{expm1,log1p}
2 parents 337a420 + fd9f761 commit cc0c818

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

core/src/main/java/org/jruby/RubyMath.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,4 +720,20 @@ private static boolean negZero(final double x) {
720720
}
721721

722722
}
723+
724+
@JRubyMethod(module = true, visibility = Visibility.PRIVATE)
725+
public static IRubyObject expm1(ThreadContext context, IRubyObject unused, IRubyObject x) {
726+
return asFloat(context, Math.expm1(toDouble(context, x)));
727+
}
728+
729+
@JRubyMethod(module = true, visibility = Visibility.PRIVATE)
730+
public static IRubyObject log1p(ThreadContext context, IRubyObject unused, IRubyObject x) {
731+
double xDouble = toDouble(context, x);
732+
733+
if (xDouble < -1.0) {
734+
throw context.runtime.newMathDomainError("Numerical argument is out of domain - log1p");
735+
}
736+
737+
return asFloat(context, Math.log1p(xDouble));
738+
}
723739
}

0 commit comments

Comments
 (0)