www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - powl bug

↑ ↓ ← "Steve Hall" <sthall lorrexinc.com> writes:
The following code produce wrong result:

#include <math.h>
#include <stdio.h>

int main()
{
 long double a = powl(-0.0397739, 310.954);
 long double b = -5.12198e11;

 printf("(%Lg)^(%Lg) = %Lg", a, b, powl(a, b));
 return 0;
}

The used compiler is Digital Mars Compiler v8.29n.
Apr 21 2003
↑ ↓ Larry Brasfield <larry_brasfield snotmail.com> writes:
In article <b81iu3$2smm$1 digitaldaemon.com>, 
Steve Hall (sthall lorrexinc.com) says...
 The following code produce wrong result:
 
 #include <math.h>
 #include <stdio.h>
 
 int main()
 {
  long double a = powl(-0.0397739, 310.954);
  long double b = -5.12198e11;
 
  printf("(%Lg)^(%Lg) = %Lg", a, b, powl(a, b));
  return 0;
 }

What do believe is the "right" result? According to the math I learned, there is no meaningful way to raise negative numbers to fractional powers. -- -Larry Brasfield (address munged, s/sn/h/ to reply)
Apr 22 2003
↑ ↓ → "Steve Hall" <sthall lorrexinc.com> writes:
I agree with you, but according to C99, the math and lcc-win32 v3.8 the
result of the following code should be: (nan)^(3.5) = nan.

#include <math.h>
#include <stdio.h>

int main()
{
 long double a = powl(-1, 0.5);
 long double b = 3.5;

 printf("(%Lg)^(%Lg) = %Lg", a, b, powl(a, b));
 return 0;
}

The result from dmc v8.29n is: (nan)^(3.5) = 3.36128e-4932.
The software that I develop depend on precision C99 floating-point
arithmetic.

"Larry Brasfield" <larry_brasfield snotmail.com> wrote in message
news:MPG.190ea07eab0c3d7e9896a4 news.digitalmars.com...
 In article <b81iu3$2smm$1 digitaldaemon.com>,
 Steve Hall (sthall lorrexinc.com) says...
 The following code produce wrong result:

 #include <math.h>
 #include <stdio.h>

 int main()
 {
  long double a = powl(-0.0397739, 310.954);
  long double b = -5.12198e11;

  printf("(%Lg)^(%Lg) = %Lg", a, b, powl(a, b));
  return 0;
 }

What do believe is the "right" result? According to the math I learned, there is no meaningful way to raise negative numbers to fractional powers. -- -Larry Brasfield (address munged, s/sn/h/ to reply)

Apr 22 2003