Permalink
Browse files

Fix ceiling/floor/round Inf handling

  • Loading branch information...
leto committed Feb 26, 2009
1 parent 4f06c8f commit 4f4520faa9d7a1e901a7a1d9d9d66ea43048eb72
Showing with 15 additions and 9 deletions.
  1. +15 −9 src/builtins/math.pir
View
@@ -28,12 +28,14 @@ Returns the highest integer not greater than $x.
.param string x
.local num n
.local int i
- if x == 'NaN' goto not_a_number
+ if x == 'NaN' goto special
+ if x == 'Inf' goto special
+ if x == '-Inf' goto special
n = x
floor i, n
.return (i)
- not_a_number:
- .return ('NaN')
+ special:
+ .return (x)
.end
@@ -50,12 +52,14 @@ Returns the lowest integer not less than $x.
.param string x
.local num n
.local int i
- if x == 'NaN' goto not_a_number
+ if x == 'NaN' goto special
+ if x == 'Inf' goto special
+ if x == '-Inf' goto special
n = x
ceil i, n
.return (i)
- not_a_number:
- .return ('NaN')
+ special:
+ .return (x)
.end
@@ -73,13 +77,15 @@ Returns the nearest integer to $x. The algorithm is floor($x + 0.5).
.param string x
.local num n
.local int i
- if x == 'NaN' goto not_a_number
+ if x == 'NaN' goto special
+ if x == 'Inf' goto special
+ if x == '-Inf' goto special
n = x
n += 0.5
floor i, n
.return (i)
- not_a_number:
- .return ('NaN')
+ special:
+ .return (x)
.end

0 comments on commit 4f4520f

Please sign in to comment.