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
  • 6,737
  • 16
  • 59
  • 77

3 Answers3

16

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

Kerrek SB
  • 447,451
  • 88
  • 851
  • 1,056
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,184
  • 1
  • 25
  • 52
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
  • 148,593
  • 36
  • 425
  • 712