IEEE 754 rounding or shredding

Who decides to use grinding or rounding, and at what stage? For example, if I am writing a C program and there is a variable in it double

, then what happens to the number 2.57

(regardless of its floating point representation)? Is it sliced ​​into 2.5

or rounded to 2.6

? Can my C compiler solve these two possibilities? Is the IEEE 754 standard what my C compiler is supposed to do? Is this implemented in my processor architecture or perhaps my OS?

+3


source to share


2 answers


This is the implementation. In particular, although commonly used, the C standard does not provide support for IEEE-754.



C11 Β§6.4.4.2 Floating constants section3

The significant part is interpreted as a (decimal or hexadecimal) rational number; a sequence of digits in the exponential part is interpreted as a decimal integer. For decimal floating-point constants, the exponent shows a cardinality of 10 by which a significant portion must be scaled. For hexadecimal floats, the exponent shows the cardinality of 2, by which a significant portion must be scaled. For decimal floats, and for hexadecimal floats, when FLT_RADIX

not a power of 2, the result is either the closest representable value, or the greater or lesser representable value immediately adjacent to the closest representable value chosen by the implementation.For hexadecimal floats, when FLT_RADIX

is a power of 2, the result is correctly rounded.

+3


source


As stated by @YuHao C standard there is no IEEE-754 compliance , but there is a predefined macro for that. Ref N1570 Β§6.10.8.3 / p1, Conditional function macros:

__STDC_IEC_559__

Integer constant 1 intended to indicate conformance to specifications in Appendix F (IEC 60559 floating point arithmetic).

__STDC_IEC_559_COMPLEX__

Integer constant 1 intended to indicate compliance with specifications in Appendix G (IEC 60559 compliant complex arithmetic)



How can you tell that this is the same standard as IEEE-754.

These macros are also (conditionally) defined in C99 (N1256 Β§6.10.8 / p2).

+2


source







All Articles