• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Floating point literals

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This code returns ; true,
why didn't the compiler give error ?
when floating point literals should declared as 5.0f
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shonak,

why didn't the compiler give error ?
when floating point literals should declared as 5.0f



There is no error...that's why you don't get any compiler error!!!
Floating point literals are AUTOMATICALLY considered DOUBLE, you use 5.0f if you want to assign the literal to a float variable:
double a = 5.0; //CORRECT
float b = 5.0; //COMPILER ERROR
float c = 5.0f; //CORRECT

Giovanni
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also Shonak - you should note that "float" and "floating point" are not quite the same thing. Floating point is a more general term, which includes two specific types: float and double. So if you read something about floating point, it's talking about both float and double; if you read something about float, it's not talking about double.
 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic