3 ms·
Can you clarify this part: [...] since C doesn't have a portable way to denote single precision float constants [...] That sounds like the suffix 'f' which yo
by unwind 9y ago
Can you clarify this part:
[...] since C doesn't have a portable way to denote single precision float constants [...]
That sounds like the suffix 'f' which you're also using, how is that not a way to "denote single precision float constants"?
My draft copy of the C11 spec says:
An unsuffixed floating constant has type double. If suffixed by the letter f or F, it has type float. If suffixed by the letter l or L, it has type long double.
But this is not new syntax, I just looked in the most recent document I have.
Do you mean that C doesn't have a way to require IEEE 754 floating-point?
- vardump 9y agoSee edit below. C99 allows greater precision than required by the type! Hmm, you're right. I think something similar bit me long ago and left me under impression f-suffix for a float is not portable. Perhaps it's time to read the standard through once again... Then again, explicit casts generate code that works on all compilers, standards compliant or not. Edit: C99, 6.3.1.8.2: "The values of floating operands and of the results of floating expressions may be represented in greater precision and range than that required by the type; the types are not changed thereby." So I guess explicit floating point casts are needed when explicit operations are wanted!
- enqk 9y agoYou might have encountered in the past is C/C++ silently promoting your floats to double. An example, `printf("%f", float_value)` will actually promote float_value to a double. Or calling a function from `math.h` with a float constant