Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6d74772107d0^
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ae6d7205a4f1
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Nov 17, 2016

  1. Revert "Fixed Math.lgamma with input -0.0"

    This reverts commit 1605ff0.
    kares committed Nov 17, 2016
    Copy the full SHA
    6d74772 View commit details
  2. add a working fix for #4299

    ... reverting spec tagging at e07c718
    kares committed Nov 17, 2016
    Copy the full SHA
    ae6d720 View commit details
Showing with 16 additions and 9 deletions.
  1. +16 −7 core/src/main/java/org/jruby/RubyMath.java
  2. +0 −1 spec/tags/ruby/core/math/lgamma_tags.txt
  3. +0 −1 spec/truffle/tags/core/math/lgamma_tags.txt
23 changes: 16 additions & 7 deletions core/src/main/java/org/jruby/RubyMath.java
Original file line number Diff line number Diff line change
@@ -680,7 +680,7 @@ public static RubyFloat erfc19(ThreadContext context, IRubyObject recv, IRubyObj

@JRubyMethod(name = "gamma", required = 1, module = true, visibility = Visibility.PRIVATE)
public static RubyFloat gamma(ThreadContext context, IRubyObject recv, IRubyObject x) {
double value = ((RubyFloat) RubyKernel.new_float(recv, x)).getDoubleValue();
double value = RubyKernel.new_float(recv, x).getDoubleValue();
double result = nemes_gamma(value);
/* note nemes_gamma can return Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY
* when value is an integer less than 1.
@@ -719,7 +719,7 @@ public static RubyFloat gamma(ThreadContext context, IRubyObject recv, IRubyObje

@JRubyMethod(name = "lgamma", required = 1, module = true, visibility = Visibility.PRIVATE)
public static RubyArray lgamma(ThreadContext context, IRubyObject recv, IRubyObject x) {
double value = RubyKernel.new_float(recv, x).getDoubleValue();
double value = RubyKernel.new_float(recv, x).getDoubleValue();
// JRUBY-4653: Could this error checking done more elegantly?
if (value < 0 && Double.isInfinite(value)) throw context.runtime.newMathDomainError("lgamma");

@@ -743,22 +743,22 @@ public static double nemes_gamma(double x) {
* Inner class to help with &Gamma; functions
*/
public static class NemesLogGamma {
public double value;
public double sign = 1;
public final double value;
public final double sign;

public NemesLogGamma(double x) {
if (Double.isInfinite(x)) {
value = Double.POSITIVE_INFINITY;
value = Double.POSITIVE_INFINITY; sign = 1;
return;
}

if (Double.isNaN(x)) {
value = Double.NaN;
value = Double.NaN; sign = 1;
return;
}

double int_part = (int) x;
sign = ((x == -0.0) || (int_part % 2 == 0 && (x - int_part) != 0.0 && (x < 0))) ? -1 : 1;
sign = signum(x, int_part);
if ((x - int_part) == 0.0 && 0 < int_part && int_part <= FACTORIAL.length) {
value = Math.log(FACTORIAL[(int) int_part - 1]);
}
@@ -779,5 +779,14 @@ else if (x < 10) {
(Math.log(2) + Math.log(Math.PI) - Math.log(x)) / 2.0;
}
}

private static int signum(final double x, final double int_part) {
return ( (int_part % 2 == 0 && (x - int_part) != 0.0 && (x < 0)) || negZero(x) ) ? -1 : 1;
}

private static boolean negZero(final double x) {
return Double.doubleToRawLongBits(x) != 0; // detect -0.0 (since in Java: `0.0 == -0.0`)
}

}
}
1 change: 0 additions & 1 deletion spec/tags/ruby/core/math/lgamma_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/math/lgamma_tags.txt

This file was deleted.