Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Confusing questing

Confusing questing

Scheduled Pinned Locked Moved Managed C++/CLI
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mstanwar
    wrote on last edited by
    #1

    void main() { float a=0.7; if(a<0.7) printf("A"); else printf("B"); getch(); } If i m putting 0.7 and 0.9 in the question answer is coming "A".else for every option as 0.3,0.5,0.6,0.8 it is coming "B".Why is it so??/...I know the float and double concept...dont tell that...but why is difference in answers ..please focus on that.

    L 1 Reply Last reply
    0
    • M mstanwar

      void main() { float a=0.7; if(a<0.7) printf("A"); else printf("B"); getch(); } If i m putting 0.7 and 0.9 in the question answer is coming "A".else for every option as 0.3,0.5,0.6,0.8 it is coming "B".Why is it so??/...I know the float and double concept...dont tell that...but why is difference in answers ..please focus on that.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      mstanwar wrote:

      I know the float and double concept

      do you really? 0.7 is a real number; it cannot be represented exactly as it is not equal to an integer times some power of 2. therefore, it has an inherent inaccuracy. furthermore, it is a double (real constants are double by default in C-like languages); assigning it to a float enlarges the inaccuracy, as there are fewer mantissa bits in a float than there are in a double. a<0.7 is an expression that gets evaluated as doubles (see the language specification); so you are basically comparing the float representation and the double representation of the number 0.7, and those are both approximations, and unequal, and either one may be the larger one. If you really knew about floats and doubles, you wouldn't carelessly mix them like that. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups