I just saw this for the first time. The source code I'm looking at is in C
if( rate < 0.){
...
}
else{
...
}
What happens if rate=0 ?
I just saw this for the first time. The source code I'm looking at is in C
if( rate < 0.){
...
}
else{
...
}
What happens if rate=0 ?
0. is a literal of type double (and value zero). By contrast, 0 is a literal of type int.
It is interpreting 0. as a double (0.0) instead of an integer (0).
Check the link: of "working code", showing the different sizes of various types of zero constants:
0. is a floating constant and since it does not have a suffix it is a double, from the draft C99 standard section 6.4.4.2 Floating constants we have the following grammar:
floating-constant:
decimal-floating-constant
hexadecimal-floating-constant
decimal-floating-constant:
fractional-constant exponent-partopt floating-suffixopt
digit-sequence exponent-part floating-suffixopt
[...]
fractional-constant:
digit-sequenceopt . digit-sequence
digit-sequence . < ---- This covers 0.
[...]
We then have in paragraph 4:
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.