Possible std.math.exp() bug
Don Clugston
dac at nospam.com.au
Mon Apr 3 23:23:18 PDT 2006
anthony.difranco at yale.edu wrote:
> Ideas? Help much appreciated; this is a huge obstacle right now. Have
> reproduced this on two different x86 linux systems. Nothing special about 3.0
> in reproducing this. Have verified that the corresponding C library exp()
> works.
The problem is that you're using %f with printf, but those functions
return reals.
Try "%Lf" instead, or use writef.
However, there *is* an accuracy issue in tgamma, which occurred when it
was translated from D back to C (!) for the DMC compiler. You can find
the original, accurate tgamma() in the mathextra project at www.dsource.org.
> real tgamma(real x);
> The Gamma function, Γ(x)
>
> $ cat test.d
> import std.math;
>
> int main(char[][] args)
> {
> printf("f(3.0) %f\n", sqrt(3.0));
> printf("g(3.0) %f\n", exp(3.0));
> printf("h(3.0) %f\n", tgamma(3.0));
> return 1;
> }
>
> $ dmd test.d
> gcc test.o -o test -lphobos -lpthread -lm
>
> $ ./test
> f(3.0) 1.732051
> g(3.0) -0.000000
> h(3.0) -0.000000
>
> $ dmd
> Digital Mars D Compiler v0.150
> Copyright (c) 1999-2006 by Digital Mars written by Walter Bright
> Documentation: www.digitalmars.com/d/index.html
>
>
More information about the Digitalmars-d-bugs
mailing list