Julian Assange wrote:

> The precission and or rounding used by hugs/ghc seems strange, to wit:
>
> Prelude> sin(pi)
> -8.74228e-08
> Prelude> pi
> 3.14159
> sin(3.14159265358979323846)
> -8.74228e-08
>
> ghc:
>
> module Main where
> main = do
>         print pi
>         print (sin pi)
>
> ./a.out
> 3.141592653589793
> 1.2246467991473532e-16
>
> While this maybe accurate in terms of ieee foat and double, most maths
> libraries round if a value is `close' to a small integer (such as 1,
> 0, -1), inorder to avoid amplification of missing precission during
> iterative processes.
>
> #include <math.h>
> #include <stdio.h>
> main(){
> printf("sin(%f) = %f\n", M_PI, sin(M_PI));
> }
>
> M_PI is defined by <math.h> as 3.14159265358979323846
>
> ./a.out
> sin(3.141593) = 0.000000

Please, don't compare apples and oranges.  If you print with full accuracy in
Haskell you should do so in C as well.
#include <math.h>
#include <stdio.h>
main(){
printf("sin(%.16e) = %.16e\n", M_PI, sin(M_PI));
}

opus% a.out
sin(3.1415926535897931e+00) = 1.2246063538223773e-16

Haskell performs no worse or better than C.  Your comment about how math
libraries round might be accurate for some languages, but for C it's pure nonsense.

--

        -- Lennart



Reply via email to