Thread: Variable Type issue

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Quote Originally Posted by Elysia View Post
    Just pass %f, and it will print any available decimals.
    Beware that floating points in somewhat inaccurate, so 1/8 can also return 0.12500001 or something. Don't know if it can happen to this particular equation, but it can happen to certain ones.
    Bad example. 1/8 == 1/2^3 => exact floating point number (0.125) - unless your hardware is broken...

    0.1 or 0.7 are values I know are NOT representable in floating point.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Join Date
    Oct 2007
    Inside my computer
    I know, I didn't think of that, but I think the point was that a division with 1 and 8 would in real life give 0.125. So if done "correctly" in C/C++, it should be 0.125 too (and not 0.12500001).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Apr 2007
    Thx everyone for help...

    Just for record I solved it by putting into the calculator a slide-bar by which a user selects how many decimals does he want... Useful because it automatically rounds up decimals

  4. #19
    train spotter
    Join Date
    Aug 2001
    near a computer
    I use _snprintf() as it is safer and less likely to crash your app than sprintf()
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
  2. Replies: 6
    Last Post: 04-10-2008, 11:49 PM
  3. strings Vs. Char pointers
    By aijazbaig1 in forum C Programming
    Replies: 49
    Last Post: 02-13-2008, 09:51 AM
  4. "Deciding" in runtime the type of a variable
    By mikahell in forum C++ Programming
    Replies: 28
    Last Post: 07-22-2006, 09:51 AM
  5. Difference between 'data type' and variable?
    By cdalten in forum C Programming
    Replies: 2
    Last Post: 02-02-2006, 08:48 AM