C functions creal and cimag return the same number?

OpenVMS x86 Field Test questions, reports, and feedback.
Post Reply

Topic author
jimduff
Newbie
Posts: 4
Joined: Wed Jan 06, 2021 9:34 pm
Reputation: 0
Location: Sydney Australia
Status: Offline
Contact:

C functions creal and cimag return the same number?

Post by jimduff » Wed Jul 26, 2023 8:33 pm

Here's a simple C program, cn.c:

Code: Select all

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

int main (void) {

static double complex c1 = 2.0 + 3.0*I;
static double complex c2 = 1.0 + 2.0*I;
static double complex r;

    r = cpow (c1, c2);
    (void)printf ("%f + %f*I\n",
                 creal (r),
                 cimag (r));
}
On linux:

Code: Select all

$ gcc -o cn cn.c -lm
$ ./cn
-0.463957 + -0.199530*I
On VMS 9.2-1, VirtualBox 7.0.6_Ubuntu r155176:

Code: Select all

$ cc cn
$ link cn
$ r cn
-0.199530 + -0.199530*I
Something doesn't look right here.

User avatar

arne_v
Master
Posts: 384
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Online
Contact:

Re: C functions creal and cimag return the same number?

Post by arne_v » Wed Jul 26, 2023 9:45 pm

It could be same problem as mentioned here:

viewtopic.php?f=16&t=8714

Math functions returning 128 bit results broken due to a mismatch between native compilers and the math RTL build with cross compilers.

Added in 40 minutes 19 seconds:
It was also mentioned here:

viewtopic.php?f=16&t=8715
Arne
arne@vajhoej.dk
VMS user since 1986


Topic author
jimduff
Newbie
Posts: 4
Joined: Wed Jan 06, 2021 9:34 pm
Reputation: 0
Location: Sydney Australia
Status: Offline
Contact:

Re: C functions creal and cimag return the same number?

Post by jimduff » Thu Jul 27, 2023 12:05 am

Thanks Arne, I did search but I searched for the C function names.

Post Reply