3

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 ?

perror
  • 7,071
  • 16
  • 58
  • 85

3 Answers3

16

0. is a literal of type double (and value zero). By contrast, 0 is a literal of type int.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
6

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:

Jiminion
  • 5,080
  • 1
  • 31
  • 54
2

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 .                                   &lt ---- 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.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740