JuliaLang/julia — Issue #331: incorrect iround, ifloor, iceil behavior near 2^53
Author: StefanKarpinski
Created: 2012-01-06 16:31:01+00:00
State: open
Labels: bugs

```
julia> load("j/printf.j")

julia> begin
p"%3s %3s %3s %3s %3s %3s %3s %3s %3s\n"(
"x", "itf", "it", "irf", "ir", "iff", "if", "icf", "if"
)
for x = 2^53-10:2^53+10
y = float(x)
p"%3d %3d %3d %3d %3d %3d %3d %3d %3d\n"(
x-2^53,
int(trunc(y))-2^53, itrunc(y)-2^53,
int(round(y))-2^53, iround(y)-2^53,
int(floor(y))-2^53, ifloor(y)-2^53,
int(ceil(y))-2^53, iceil(y)-2^53
)
end
end
x itf it irf ir iff if icf if
-10 -10 -10 -10 -10 -10 -10 -10 -10
-9 -8 -9 -8 -8 -8 -8 -8 -8
-8 -8 -8 -8 -8 -8 -8 -8 -8
-7 -6 -7 -6 -6 -6 -6 -6 -6
-6 -6 -6 -6 -6 -6 -6 -6 -6
-5 -4 -5 -4 -4 -4 -4 -4 -4
-4 -4 -4 -4 -4 -4 -4 -4 -4
-3 -2 -3 -2 -2 -2 -2 -2 -2
-2 -2 -2 -2 -2 -2 -2 -2 -2
-1 0 -1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
2 2 2 2 2 2 2 2 2
3 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4
5 4 4 4 4 4 4 4 4
6 6 6 6 6 6 6 6 6
7 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8
9 8 8 8 8 8 8 8 8
10 10 10 10 10 10 10 10 10
```

They're all fine above 2^53, but below 2^53, things are kind of screwed up, except for `itrunc` which uses the LLVM float-to-int primitive directly.