Skip to content
Browse files

Fixes #313 and other cases in various Math.* functions where NaN valu…

…es were handled differently.
  • Loading branch information...
1 parent 4ceafef commit 6cc0ea8755eef641dfbc43c6a686a13932bf6c3e @BanzaiMan BanzaiMan committed Oct 16, 2012
Showing with 8 additions and 6 deletions.
  1. +8 −6 src/org/jruby/RubyMath.java
View
14 src/org/jruby/RubyMath.java
@@ -164,7 +164,6 @@ public static RubyFloat asin(IRubyObject recv, IRubyObject x) {
public static RubyFloat asin19(IRubyObject recv, IRubyObject x) {
double value = needFloat(x).getDoubleValue();
double result = Math.asin(value);
- domainCheck19(recv, result, "asin");
return RubyFloat.newFloat(recv.getRuntime(),result);
}
@@ -180,7 +179,6 @@ public static RubyFloat acos(IRubyObject recv, IRubyObject x) {
public static RubyFloat acos19(IRubyObject recv, IRubyObject x) {
double value = needFloat(x).getDoubleValue();
double result = Math.acos(value);
- domainCheck19(recv, result, "acos");
return RubyFloat.newFloat(recv.getRuntime(), result);
}
@@ -193,7 +191,6 @@ public static RubyFloat atan(IRubyObject recv, IRubyObject x) {
@JRubyMethod(name = "atan", required = 1, module = true, visibility = Visibility.PRIVATE, compat = CompatVersion.RUBY1_9)
public static RubyFloat atan19(IRubyObject recv, IRubyObject x) {
double value = needFloat(x).getDoubleValue();
- domainCheck19(recv, value, "atan");
return RubyFloat.newFloat(recv.getRuntime(),Math.atan(value));
}
@@ -262,8 +259,6 @@ public static RubyFloat acosh19(IRubyObject recv, IRubyObject x) {
result = 0.69314718055994530941723212145818 + Math.log(value);
}
- domainCheck19(recv, result, "acosh");
-
return RubyFloat.newFloat(recv.getRuntime(),result);
}
@@ -418,7 +413,6 @@ private static RubyFloat log_common19(IRubyObject recv, double value, double bas
throw recv.getRuntime().newMathDomainError(msg);
}
double result = Math.log(value)/Math.log(base);
- domainCheck(recv, result, msg);
return RubyFloat.newFloat(recv.getRuntime(),result);
}
@@ -526,6 +520,8 @@ public static RubyFloat hypot(IRubyObject recv, IRubyObject x, IRubyObject y) {
} else if (valueb != 0) {
result = valuea / valueb;
result = Math.abs(valueb) * Math.sqrt(1 + result * result);
+ } else if (Double.isNaN(valuea) || Double.isNaN(valueb)) {
+ result = Double.NaN;
} else {
result = 0;
}
@@ -544,6 +540,8 @@ public static RubyFloat hypot19(IRubyObject recv, IRubyObject x, IRubyObject y)
} else if (valueb != 0) {
result = valuea / valueb;
result = Math.abs(valueb) * Math.sqrt(1 + result * result);
+ } else if (Double.isNaN(valuea) || Double.isNaN(valueb)) {
+ result = Double.NaN;
} else {
result = 0;
}
@@ -652,6 +650,8 @@ public static RubyFloat erf(IRubyObject recv, IRubyObject x) {
result = value * (1 + chebylevSerie(2 * value * value - 1, ERFC_COEF));
} else if (y < 6.013687357) {
result = sign(1 - erfc(recv, RubyFloat.newFloat(recv.getRuntime(),y)).getDoubleValue(), value);
+ } else if (Double.isNaN(y)) {
+ result = Double.NaN;
} else {
result = sign(1, value);
}
@@ -671,6 +671,8 @@ public static RubyFloat erf19(IRubyObject recv, IRubyObject x) {
result = value * (1 + chebylevSerie(2 * value * value - 1, ERFC_COEF));
} else if (y < 6.013687357) {
result = sign(1 - erfc(recv, RubyFloat.newFloat(recv.getRuntime(),y)).getDoubleValue(), value);
+ } else if (Double.isNaN(y)) {
+ result = Double.NaN;
} else {
result = sign(1, value);
}

0 comments on commit 6cc0ea8

Please sign in to comment.
Something went wrong with that request. Please try again.