Re: (Pi/2. ) != (90.0 DegToRad)

From: Christian Holm Christensen <cholm_at_nbi.dk>
Date: Fri, 22 Dec 2006 09:25:04 +0100


Hi,

On Thu, 2006-12-21 at 14:53 +0100, Rene Brun wrote:
> Hi Kathrin,
>
> This is the expected behavior. You should never test the equality of 2
> floating point numbers.
> Depending on the compiler rounding options, it may work or not.
> You should always test withing some numerical precision (eg 1e-13)

The least distance between two numbers representable by type T is given by

        std::numeric_limits<T>::epsilon()

in the standard library. To understand where this comes from, you should read up on IEEE floating point numbers. Also note, that literal floating point numbers are generally of double precision so `(double)10.' is redundant. If you want to force a precision do for example `10.F' for single, and `10.LF' for double precision.

Yours,

-- 
 ___  |  Christian Holm Christensen 
  |_| |  -------------------------------------------------------------
    | |  Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|           DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|            Denmark                    Office: (+45) 353  25 404
 ____|   Email:   cholm_at_nbi.dk               Web:    www.nbi.dk/~cholm
 | |
Received on Fri Dec 22 2006 - 09:25:13 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:02 MET