Machine epsilonFloating Point ConceptsUp: These macro definitions can be accessed by including the header file float. In practice, all the machines currently supported double epsilon c suitable. This value characterizes the rounding mode for floating point addition. Epsjlon following values indicate standard rounding modes:. On most machines, the value is 1in accordance with the Double epsilon c standard for floating point. This is the oxandrolon z kreatyna of the base, or radix, of the exponent representation.
Floating Point Parameters (The GNU C Library)
Join Stack Overflow to learn, share knowledge, and build your career. I'm trying to compute an approximation of the epsilon value for the float type and I know it's already in the standard library. I tried to get an approximation of the value starting from 1 and dividing it by 2 until it becomes too small, doing all operation with the float type:.
These last two versions should be equivalent on this platform, is this a compiler bug? If not, what's happening? Current version of gcc, 4. There are also comments saying that different versions give different results. After some answers and comments, that clarified what is behaving as expected and what's not, I changed the question a little to make it clearer.
The compiler is allowed to evaluate float expressions in any bigger precision it likes, so it looks like the first expression is evaluated in long double precision. In the second expression you enforce scaling the result down to float again. In answer to some of your additional questions and the discussion below: On a Pentium traditionally the internal registers of the floating point unit are 80 bits and it is convenient to use that precision for all the smaller floating point types.
So in the end your test depends on the precision of your compare! In the absence of an explicit cast the precision of this comparison is determined by your compiler not by your code.
With the explicit cast you scale the comparison down to the type you desire. If the integer constant 2 is used in the expression instead of the floating point constant 2. It is also worth noticing that from of optimization level -O1 the right results are produced on these older compilers, but the generated assembly is quite different and contains only few floating point operations. A C99 C compiler can evaluate floating-point expressions as if they were of a more precise floating-point type than their actual type.
The two source files differ only in that single character, and exactly the same compiler switches were used? EricPostpischil well, an old one, I added details. Anyway, I tested the code again and I confirm the results. Can't reproduce with gcc 4. DanielFischer yes, it seems like newer versions behave correctly. Bryan Olivier 4, 2 10 Are you saying that the cast actually reduced the precision of the stored value? If so, why do I still get the wrong result if I cast the result without using any double?
The compiler cannot do as it likes, it has to do exactly as indicated by how it defines this macro. That explains why your second code sequence printed the desired value. I do not see a code sample where you cast the result and did not use double.
The first sample contains neither a cast nor a double. The second contains both a cast and a double. The gcc compiler at my home is version 4. The gcc compiler at my work is version 4. For historical reasons, two common choices when targeting the x86 processors are 0 and 2.
If I compile it, using my compiler, thus, I obtain: So, shouldn't the last two examples give the same result? If all constants and operations live in long double Myers gives the best interpretation of how modern GCCs are supposed to interpret this part of the standard here: The former is typed as float , the latter as double , but both divisions should be computed in extended precision. What makes you say that something different happens?
Well, the fact that I get two different results in those two cases, see my updated question. Sign up or log in Sign up using Google. Sign up using Facebook.