Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: A mess with complex arithmetics in earmv7hf



Hi Michael,

did you link your program with libm? That is the point. Of course, your
test program can get by without it, but if you add functions from libm,
bad things happen. Correct arithmetic helpers from libgcc get replaced
with broken ones from libm.

Your program on earmv7hf 9.1_STABLE dumps core as well:

$ gcc michael.c
$ ldd ./a.out
./a.out:
        -lgcc_s.1 => /usr/lib/libgcc_s.so.1
        -lc.12 => /usr/lib/libc.so.12
[ complex helper routines from libgcc are used ]
$ ./a.out
Starting values: cx = 1.00+3.00i  cy = 1.00-4.00i
The sum cx + cy = 2.00-1.00i
The difference cx - cy = 0.00+7.00i
The product cx * cy = 13.00-1.00i
The quotient cx / cy = -0.65+0.41i
The conjugate of cx =  1.00-3.00i

$ gcc michael.c -lm
$ ldd ./a.out
./a.out:
        -lm.0 => /usr/lib/libm.so.0
        -lc.12 => /usr/lib/libc.so.12
[ broken helper routines from libm are used ]
$ ./a.out
Starting values: cx = 1.00+3.00i  cy = 1.00-4.00i
The sum cx + cy = 2.00-1.00i
Bus error (core dumped)
$ gdb -c ./a.out.core ./a.out
...
#0  0x7bea63d0 in __muldc3 () from /usr/lib/libm.so.0

-- 
Alexander.

On Thu, Jan 14, 2021 at 12:21:02PM -0800, Michael Cheponis wrote:
> FWIW, it seems to work fine on arm64  9.99.77  (example program, below)
> 
> 
> (small p.s. the 'return 0' at the end of main is guaranteed when you exit
> main out the bottom; echo $? to prove this; so return 0 is unnecessary.)
> 
> 
> 
> 
> #include <complex.h>
> #include <stdio.h>
> 
> int main(void)
> {
>   double complex cx = 1.0 + 3.0*I;
>   double complex  cy = 1.0 - 4.0*I;
>   printf("\nStarting values: cx = %.2f%+.2fi  cy = %.2f%+.2fi", creal(cx),
> cimag(cx), creal(cy), cimag(cy));
> 
>   double complex  sum = cx+cy;
>   printf("\n\nThe sum cx + cy = %.2f%+.2fi", creal(sum),cimag(sum));
> 
>   double complex  difference = cx-cy;
>   printf("\n\nThe difference cx - cy = %.2f%+.2fi",
> creal(difference),cimag(difference));
> 
>   double complex product = cx*cy;
>   printf("\n\nThe product cx * cy =
> %.2f%+.2fi",creal(product),cimag(product));
> 
>   double complex quotient = cx/cy;
>   printf("\n\nThe quotient cx / cy = %.2f%+.2fi",
> creal(quotient),cimag(quotient));
> 
>   double complex conjugate = conj(cx);
>   printf("\n\nThe conjugate of cx =  %.2f%+.2fi\n", creal(conjugate)
> ,cimag(conjugate));
> }
> 
> Starting values: cx = 1.00+3.00i  cy = 1.00-4.00i
> The sum cx + cy = 2.00-1.00i
> The difference cx - cy = 0.00+7.00i
> The product cx * cy = 13.00-1.00i
> The quotient cx / cy = -0.65+0.41i
> The conjugate of cx =  1.00-3.00i
> 
> adapted from
> http://www.java2s.com/Tutorial/C/0040__Data-Type/Workingwithcomplexnumbers.htm
> 
> On Thu, Jan 14, 2021 at 5:02 AM Alexander Mukhin <
> alexander.i.mukhin%gmail.com@localhost> wrote:
> 
> >
> >


Home | Main Index | Thread Index | Old Index