I am confused with the conversion limitations between the three: ints, floats and double.

The question is whether the following operations give the same result or not (yield true or not).

For instance we have an integer x:
Would (Float)(x) == (float)(double)(x)

I believe that should be true, as the int would get converted into double perfectly. And similar rounding would take place in conversion between int-->float and double--->float. Yea, correct reasoning?

But what about between: (d is short for double)
1)(dx - dy) = double(x - y)
2)(dx * dy) * dz = dx * (dy * dz)

I know 2) is not true, as floating point numbers are not associative. But I can't think of an example where equation 2) shoudl return false and prove my answer.

Any help would be appreciated!

Edited by nonetheless: n/a

7 Years
Discussion Span
Last Post by Ancient Dragon

>>Would (Float)(x) == (float)(double)(x)

Maybe yes, and maybe no. == does not always work with floats and doubles due to the way they are stored in memory. Testing for equality with floats/doubles is always unreliable and risky business.

>>I know 2) is not true, as floating point numbers are not associative
What gave you that idea? The statement is true regardless of the data type of dx and dy.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.