| Fri, 08/21/2009 - 17:47 by Emmanuel Stapf | Fri, 08/21/2009 - 17:49 by Emmanuel Stapf | ||
|---|---|---|---|
| < previous diff | next diff > | ||
| Changes to Body | |||
end
| end
| ||
</e>
| </e>
| ||
| - | where at the end the value of `z' was not equal to the value of `y'. The explanation yields on the unfolded form of the `x + y' operation.
| + | where at the end the value of '''z''' was not equal to the value of '''y'''. The explanation yields on the unfolded form of the '''x + y''' operation.
|
Indeed, the compiler interprets it as:
| Indeed, the compiler interprets it as:
| ||
| - | <e>x.plus (y)</e>
| + | <e>
|
| + | x.plus (y)
| ||
| + | </e>
| ||
Where the signature of <e>plus</e> in class REAL_32 reads:
| Where the signature of <e>plus</e> in class REAL_32 reads:
| ||
| - | <e>plus alias "+" (other: REAL_32): REAL_32</e>
| + | <e>
|
| + | plus alias "+" (other: REAL_32): REAL_32
| ||
| + | </e>
| ||
Because '''y''' is of type REAL_64 and there is a conversion from REAL_32 to REAL_64, the final code executed by the compiler is actually:
| Because '''y''' is of type REAL_64 and there is a conversion from REAL_32 to REAL_64, the final code executed by the compiler is actually:
| ||
| - | <e>z := x.plus (y.truncated_to_real)</e>
| + | <e>
|
| + | z := x.plus (y.truncated_to_real)
| ||
| + | </e>
| ||
This is with the truncation to REAL_32 that we loose the precision.
| This is with the truncation to REAL_32 that we loose the precision.
| ||
Conversion between REAL_64 and REAL_32

Recently one of our customer found a loss of precision in their floating point arithmetic computations involving REAL_32 and REAL_64. This loss can be seen in the code below:
make local x: REAL_32 y: REAL_64 z: REAL_64 do x := 0 y := 1.123456789012345 z := x + y end
Indeed, the compiler interprets it as:
x.plus (y)
Where the signature of plus in class REAL_32 reads:
plus alias "+" (other: REAL_32): REAL_32
Because y is of type REAL_64 and there is a conversion from REAL_32 to REAL_64, the final code executed by the compiler is actually:
z := x.plus (y.truncated_to_real)
This is with the truncation to REAL_32 that we loose the precision.
The conversion from REAL_64 to REAL_32 was added when the conversion mechanism was put in place to replace the magic behind numerical operation in the original version of Eiffel. The reason for adding it was that we did not want to break existing code that allowed assignment of REAL_64 to REAL_32 entities.
A few years later, we now realize it was a bad move and in the next revision of EiffelStudio (i.e. 6.5) we are planning on removing that conversion. As a result some of your code might not compile. To give you an example, for EiffelStudio, over 6500 classes we had to change less than 60 classes.
To better find out how you feel about that removal, I've created a poll where you can express whether or not you agree to remove that conversion.