Project

General

Profile

Actions

Bug #15015

open

Wrong result from cpow in libc

Added by Rikard Nordgren about 1 year ago. Updated 11 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
lib - userland libraries
Start date:
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
External Bug:

Description

The c program below gives the wrong result. The output is 0.000000, -4.624796 but it should be 0.000000, -0.216226 . I have compared the calculation with glibc on Linux and wolfram alpha online.

#include <stdio.h>
#include <complex.h>

int main()
{
    double complex base = 4.62479554547*I;
    double complex exp = -1.0;
    double complex res = cpow(base, exp);

    printf("%f, %f\n", creal(res), cimag(res)); 
    return 0;
}

I tested the code with gcc on OpenIndiana with the following output from uname -a : SunOS openindiana 5.11 illumos-4f9241761d i86pc i386 i86pc


Related issues

Related to illumos gate - Bug #693: Opensource replacement of sunwlibmResolvedPiotr Jasiukajtis2011-02-03

Actions
Actions #1

Updated by Marcel Telka 11 months ago

Another example of broken cpow():

$ cat <<EOF > test_int_pow.c 
#include <complex.h>
#include <stdio.h>

int main()
{
        for (int k = -4; k < 5; ++k) {
                double complex res = cpow(0+2*I, k+0*I);
                printf("%d (%g %g)\n", k, creal(res), cimag(res));
        }

        return 0;
}
EOF
$ gcc -lm test_int_pow.c -o test_int_pow
$ ./test_int_pow 
-4 (2 -0)
-3 (-0 2)
-2 (-2 0)
-1 (0 -2)
0 (1 0)
1 (0 2)
2 (-2 -0)
3 (-0 -2)
4 (2 0)
$

This causes test failure in Cython project (see https://github.com/cython/cython/issues/5198).

Actions #2

Updated by Marcel Telka 11 months ago

  • Category set to lib - userland libraries
Actions #3

Updated by Marcel Telka 11 months ago

  • Related to Bug #693: Opensource replacement of sunwlibm added
Actions

Also available in: Atom PDF