IEEE conversion int-> float commutes with + and *?

Assume that TOFLOAT represents a conversion / coercion operation of a value having some INT of integer type to one having some (FLOAT) floating point and floating point (compatibility range [1]) in accordance with IEEE standards. Does this operation switch with addition and multiplication? In other words, if x and y are arbitrary values ​​of type INT, then the IEEE standard ensures that the following equalities are always evaluated as true ?:

  TOFLOAT(x) + TOFLOAT(y) == TOFLOAT(x+y)
  TOFLOAT(x) * TOFLOAT(y) == TOFLOAT(x*y)

Thank!

~ kj

[1] by using the "compatibility range" I mean that each value of type INT corresponds to a range of values ​​represented as type FLOAT; this qualification is probably not needed for IEEE types.

+3
source share
2 answers

No, none of them are running. For a simple counterexample for the first, with a 64-bit (signed or unsigned) integer type and regular binary IEEE binary type, consider the case where x = 2**53 + 1and y = 2. Then, in accordance with IEEE 754 rules, assuming the normal rounding mode to round to the default parity, there TOFLOAT(x) + TOFLOAT(y)will be 2**53 + 2, and TOFLOAT(x + y)will be 2**53 + 4. Counterexamples for the case of multiplication should be equally easy to find.


EDIT: for multiplication a counterexample is given x = 2**53 + 1and y = 3.

+3
source

, , , , . 32- IEEE . , IEEE .

, 32- IEEE 754, 1 ULP. () 32 , .

+1

Source: https://habr.com/ru/post/1788009/


All Articles