Thread: Math Issues

  1. #1
    Registered User Berserker's Avatar
    Join Date
    Jan 2005
    Posts
    4

    Math Issues

    Umm... Hi.

    Whenever...

    33.3 + 33.3 + 33.3 = 99.89999

    or

    33.3 * 3 = 99.8999

    Why doesn't it equal 99.9?



    -Berserker

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    umm..

    whenever question bad....

    answer = ?

    and

    cannot help

    Why not post code?
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Because floating point numbers can not respresent every number accurately. However 99.9 does = 99.89999999999999999999999999999999999999999999999 9999999999(to infinity)

  4. #4
    Registered User Berserker's Avatar
    Join Date
    Jan 2005
    Posts
    4
    Sorry Calculating a triangle's perimeter.

    void perimeter(void)
    {

    float perimeter, a, b, c;

    printf("Please input side A > ");
    scanf("%f", &a);
    printf("Please input side B > ");
    scanf("%f", &b);
    printf("Please input side C > ");
    scanf("%f", &c);
    perimeter = a + b + c;
    printf("\nThe final solution is... > %.5f\n\n", perimeter);
    }

  5. #5
    Registered User Berserker's Avatar
    Join Date
    Jan 2005
    Posts
    4
    Quote Originally Posted by Thantos
    Because floating point numbers can not respresent every number accurately. However 99.9 does = 99.89999999999999999999999999999999999999999999999 9999999999(to infinity)
    Is there any way I can accurately depcit all numbers?

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Nope. Due to memory limitations and per fact that some numbers just never end it's impossible to accurately store all numbers. What you have to do is decide how close is close enough.

    Edit: you can also try using double instead of float but I don't know how much difference it'll make in this case.

  7. #7
    Registered User Berserker's Avatar
    Join Date
    Jan 2005
    Posts
    4
    Quote Originally Posted by Thantos
    Nope. Due to memory limitations and per fact that some numbers just never end it's impossible to accurately store all numbers. What you have to do is decide how close is close enough.

    Edit: you can also try using double instead of float but I don't know how much difference it'll make in this case.
    Perhaps that is what I don't understand.
    To me, 3.33 + 3.33 + 3.33 should equal 99.9. Not 99.8999...
    I know it can't store all numbers, but it should accurately depict the numbers displayed.
    It screws up Pi too, but that is more understandable.
    Oh well, I guess I'll never understand it.
    Thanks anyway.

    PS: Double did the same as float.

  8. #8
    .
    Join Date
    Nov 2003
    Posts
    307
    Here is an explanation of fixed-point math, which may also help explain what flaoting point numbers are doing to confuse you.

    http://www.wwnet.net/~stevelim/fixed.html

  9. #9
    Registered User
    Join Date
    May 2004
    Posts
    12
    You could also have a look at arbitrary-precision math libraries, like http://www.tc.umn.edu/~ringx004/mapm-main.html

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM
  2. Help with C++ Math
    By aonic in forum C++ Programming
    Replies: 4
    Last Post: 01-29-2005, 04:40 AM
  3. Basic Math Problem. Undefined Math Functions
    By gsoft in forum C Programming
    Replies: 1
    Last Post: 12-28-2004, 03:14 AM
  4. Math Header?
    By Rune Hunter in forum C++ Programming
    Replies: 26
    Last Post: 09-17-2004, 06:39 AM
  5. toughest math course
    By axon in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-28-2003, 10:06 PM