integral to floating point conversion

Ola Fosheim Grøstad via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 3 06:41:27 PDT 2016


On Sunday, 3 July 2016 at 11:49:15 UTC, Andrei Alexandrescu wrote:
> Well to be more precise here's what I'm looking for. When you 
> compare an integral with a floating point number, the integral 
> is first converted to floating point format. I.e. for long x 
> and double y, x == y is the same as double(x) == y.
>
> Now, say we want to eliminate the "bad" cases of this 
> comparison. Those would make it non-transitive. Consider two 
> distinct longs x1 and x2. If they convert to the same double y, 
> then x1 == y and x2 == y are true, which is contradictory with 
> x1 != x2.

If you assume round-to-even rounding mode then you get unique 
representations for integers in the ranges as other people have 
suggested:

int_to_float : [-((1<<24)-1) , (1<<24)-1]

int_to_double : [-((1<<53)-1) , (1<<53)-1]



More information about the Digitalmars-d mailing list