Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Properly handle NaN and +-Inf in rounding functions, add Cool.truncat…

…e, turn on S32-num/rounders.t.
  • Loading branch information...
commit b5cc22ad866f09c2ba1c4f2e8ec7862f408ea8af 1 parent 0c3157b
@colomon colomon authored
Showing with 16 additions and 0 deletions.
  1. +14 −0 lib/Builtins.cs
  2. +1 −0  lib/CORE.setting
  3. +1 −0  t/spectest.data
View
14 lib/Builtins.cs
@@ -931,6 +931,9 @@ public partial class Builtins {
}
if (r1 == NR_FLOAT) {
double v1 = PromoteToFloat(r1, n1);
+ if (Double.IsNaN(v1) || Double.IsNegativeInfinity(v1) || Double.IsPositiveInfinity(v1)) {
+ return MakeFloat(v1);
+ }
ulong bits = (ulong)BitConverter.DoubleToInt64Bits(v1);
BigInteger big = (bits & ((1UL << 52) - 1)) + (1UL << 52);
int power = ((int)((bits >> 52) & 0x7FF)) - 0x433;
@@ -1216,6 +1219,17 @@ public partial class Builtins {
// this is only called from .Int
public static Variable coerce_to_int(Variable a1) {
+ int r1;
+ P6any o1 = a1.Fetch();
+ P6any n1 = GetNumber(a1, o1, out r1);
+
+ if (r1 == NR_FLOAT) {
+ double v1 = PromoteToFloat(r1, n1);
+ if (Double.IsNaN(v1) || Double.IsNegativeInfinity(v1) || Double.IsPositiveInfinity(v1)) {
+ return MakeFloat(v1);
+ }
+ }
+
int small; BigInteger big;
return GetAsInteger(a1, out small, out big) ?
MakeInt(big) : MakeInt(small);
View
1  lib/CORE.setting
@@ -315,6 +315,7 @@ my class Cool {
method floor() { floor self }
method ceiling() { ceiling self }
method round($scale = 1) { round self, $scale }
+ method truncate() { truncate self }
method sqrt() { sqrt self }
method sign() { sign self }
method conjugate() { self }
View
1  t/spectest.data
@@ -314,6 +314,7 @@ S32-num/pi.t
S32-num/polar.t
S32-num/power.t
S32-num/rat.t
+S32-num/rounders.t
S32-num/sign.t
S32-num/sqrt.t
S32-num/unpolar.t
Please sign in to comment.
Something went wrong with that request. Please try again.