CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Floating point

  1. #1
    Join Date
    Jun 2004
    Location
    USA
    Posts
    42

    Floating point

    Hi
    I tested an iMac running under OS X 10.3.4 with one GHz processor speed. I used the following:

    int main (int argc, const char * argv[]) {
    float b = 1;
    int index = 0;

    while( b > 0 )
    {
    b = b / 10;
    index++;
    };
    std::cout << "Number of decimal places: " << index << "\n";
    return 0;
    }

    The result was 46 decimal places. My computer can process only 16.
    What is the advantege of iMac as far as the number of decimal places is concerned?
    Fero

  2. #2
    Join Date
    Apr 2004
    Posts
    76
    Hi Fero,

    What is the advantege of iMac as far as the number of decimal places is concerned?
    There is none. Both an Intel machine and PowerPC are IEEE compliant.

    There are differences in architecture, though. The key difference is RISC vs CISC.

    Jeff

  3. #3
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    fero45,

    You must be careful since your code is not actually correct for determining the number of decimal digits of precision in a float or double. The different processors probably give different results due to varying methods of rounding in the floating point unit.

    The languages C and C++ know the decimal precision of float and double. The sample code shows how to find this out using C++. I forgot the name of the predefined constant in C, but it's probably in <limits.h>.

    Test the following code on several systems and you will find 15 decimal digits of precision for standard IEEE754 double.

    Good luck.

    Sincerely, Chris.

    Code:
    #include <limits>
    #include <iostream>
    
    int main(int argc, char* argv[])
    {
      std::cout << std::numeric_limits<double>::digits10 << std::endl;
    
      return 0;
    }
    You're gonna go blind staring into that box all day.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured