Thread: How accurate is the following...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by filker0
    When I compile and run this (on a mac-mini, though that doesn't really matter) I get the following:
    Code:
    MiniMac:~ filker0$ cc -o float float.c
    MiniMac:~ filker0$ ./float 
    2/3 as float: 0.666666686534882, double: 0.666666666666667
    The header file /usr/include/float.h (or wherever your compiler puts its standard header files) contains the various limits for the various floating point representations supported by your compiler.
    Although amusingly enough, you have just proved their statement to be true. The double in this case gives you just about twice as many points of accurate precision. Watch:
    0.666666686534882 .. seven accurate positions.
    0.666666666666667 .. fifteen accurate positions.

    Funny, that.

    [edit]
    If you want to include the preceeding zero, you end up with exactly twice as many points of accuracy. 8 and 16 respectively. So for teaching purposes, yeah, it's a pretty accurate statement.
    [/edit]


    Quzah.
    Last edited by quzah; 12-06-2005 at 09:16 AM.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need advice to provide accurate time delay in C
    By kenkoh in forum C Programming
    Replies: 14
    Last Post: 04-30-2008, 11:13 AM
  2. Frustum cull is too accurate
    By VirtualAce in forum Game Programming
    Replies: 12
    Last Post: 01-25-2006, 12:35 PM
  3. accurate CPU temp reading
    By itld in forum Tech Board
    Replies: 20
    Last Post: 01-21-2003, 05:50 PM
  4. How do I create an accurate timer?
    By Quin in forum C Programming
    Replies: 1
    Last Post: 01-06-2002, 02:28 AM
  5. VERY accurate timing
    By Gherkin in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 09-28-2001, 04:30 PM