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

Thread: fpu problem

  1. #1
    Join Date
    May 2002
    Location
    grenoble, france
    Posts
    5

    fpu problem

    To my mind, the problem is that the fpu works in binary

    In the most cases, there are problems of accuracy with float. It occurs when the number can't be represented by a sum of 1/(2^n)

    Some float numbers can be exactly represented such as 0.5 (1/2^2) or 0.3125 (1/2^3 + 1/2^5) for instance.

    That is not the case with 0.1, and the number will be between two possibles representations
    Unfortunately, the fpu have never been able to choose the closer value : they always whoose the upper value. That's why you have a 1 at the end of your 0.1000000000000000000000001

    It is shocking because with integer numbers, the problem does not exists, but everybody knows that the computer are bad calculators.

    Hope this help

  2. #2
    Join Date
    May 2002
    Location
    grenoble, france
    Posts
    5
    oops!

    this issue was suppose to be a reply. If anybody knows how i can remove it, tell me!

  3. #3

    Red face

    Really, this is not a FPU problem, it just C++ klolage problem.
    when you work with float never compare 2 floats like 'a == b' use ABS(a-b)< MIN_FLOAT. Never compare float with Zero compare with MIN_FLOAT like: ABS(a) < MIN_FLOAT
    [ccode]
    #define MIN_FLOAT 0.000001
    [/ccode]

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