How to define a double constant in C ?
For float is like so:
#define powerFactor 1.00f
For double i dont know:
#define energy 55639.00xx
Should xx
be d
, ld
, lf
, nothing or compiler specific?
How to define a double constant in C ?
For float is like so:
#define powerFactor 1.00f
For double i dont know:
#define energy 55639.00xx
Should xx
be d
, ld
, lf
, nothing or compiler specific?
In C double
doesn't have a suffix, according to the C17 standard chapter 6.4.4.2 paragraph 4. A floating point literal without a suffix will be of type double
:
#define energy 55639.00
There are also other situations where double
is assumed to be the "default" floating point type. For example the math functions would have no suffix for double arguments (sin
), and would have other suffixes for other types (e.g. sinf
for float); printf
(but not scanf
) will assume double
by default too.
How to define a double constant in C?
Should xx be d, ld, lf, nothing or compiler specific?
"nothing"
For compliant C compilers, a floating-point constant without a suffix is type double
.
To be 100% sure that it will be double:
#define energy ((double)55639.00L)
Some compilers have a command line option to treat float point constants without suffixes as float
not double
. For example gcc -fsingle-precision-constant