JuliaLang/julia — Issue #349: multi-step numeric conversions
Author: JeffBezanson
Created: 2012-01-22 02:00:19+00:00
State: open
Labels: decision

Sometimes adding extra conversion steps changes the answer, even when it would have been possible to preserve all the information. For example:

```
julia> x = 0xfffffffffffff800
0xfffffffffffff800

julia> int64(x)
-2048

julia> uint64(int64(x))
0xfffffffffffff800

julia> int64(float64(x))
-9223372036854775808

julia> uint64(int64(float64(x)))
0x8000000000000000

julia> uint64(float64(int64(x)))
0xfffffffffffff800
```

The number `x` is exactly representable as a Float64, and although it is not representable as an Int64 you can at least keep the same bit pattern (-2048). However, converting through Float64 in the wrong order gives undefined results.

The question is: do we want to try to preserve information even when converting through a type that cannot officially represent the given number? I believe this is only an issue for out-of-range float to int conversions.