Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Math.gamma should return -∞ for -0.0 #658

Merged
merged 1 commit into from

2 participants

@tychobrailleur
Collaborator

The following ruby spec was failing for JRuby: https://github.com/rubyspec/rubyspec/blob/master/core/math/gamma_spec.rb#L14

This PR checks the sign for 0.0, and returns -∞ for negative 0.0.

@headius headius merged commit 03aed6c into jruby:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 26, 2013
  1. @tychobrailleur

    Return -∞ for -0.0

    tychobrailleur authored
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/org/jruby/RubyMath.java
View
10 src/org/jruby/RubyMath.java
@@ -88,11 +88,11 @@ private static double sign(double x, double y) {
}
private static RubyFloat needFloat(IRubyObject x) {
- if(x instanceof RubyFloat) {
+ if (x instanceof RubyFloat) {
return (RubyFloat)x;
}
- if(!x.getRuntime().getNumeric().isInstance(x)) {
+ if (!x.getRuntime().getNumeric().isInstance(x)) {
TypeConverter.handleUncoercibleObject(true, x, x.getRuntime().getFloat());
}
@@ -871,7 +871,11 @@ public static RubyFloat gamma(IRubyObject recv, IRubyObject x) {
if (value < 0) {
result = Double.NaN;
} else {
- result = Double.POSITIVE_INFINITY;
+ if (value == 0 && 1 / value < 0) {
+ result = Double.NEGATIVE_INFINITY;
+ } else {
+ result = Double.POSITIVE_INFINITY;
+ }
}
}
Something went wrong with that request. Please try again.