setting floating point precision problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eternalLearner
    New Member
    • May 2007
    • 35

    setting floating point precision problem

    hi,

    i need to set precision for floating point operations in the c++ program.
    i have a number of files.Please tell me how to do it ,so that i don't have to make the change in all the files in the program.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You can't set the precision of floating point calculations in C++.

    You can use one of the basic types float, double and long double. These 3 types each have fix precision (7 digits for a float and 15 for a double), on many platforms double and long double have the same precision but for some it is bigger (18 for example on by Ubuntu using GCC).

    You set the precision by choosing which basic type to use, the normal choice would be double. You would only choose float if lack on memory on your platform was an issue (a float takes 4 bytes of ram and a double 8). If you required extra precision and you platform supported it you might use long double.

    Comment

    • eternalLearner
      New Member
      • May 2007
      • 35

      #3
      Originally posted by Banfa
      You can't set the precision of floating point calculations in C++.

      You can use one of the basic types float, double and long double. These 3 types each have fix precision (7 digits for a float and 15 for a double), on many platforms double and long double have the same precision but for some it is bigger (18 for example on by Ubuntu using GCC).

      You set the precision by choosing which basic type to use, the normal choice would be double. You would only choose float if lack on memory on your platform was an issue (a float takes 4 bytes of ram and a double 8). If you required extra precision and you platform supported it you might use long double.

      Thanks a lot for the reply.
      :)
      Last edited by eternalLearner; Nov 17 '08, 07:32 AM. Reason: incomplete

      Comment

      Working...