NetBSD-Users archive

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

Re: libm trigonometric functions and i387



   Date: Wed, 25 Feb 2009 11:55:36 -0500
   From: "Greg A. Woods" <woods%planix.com@localhost>

   I'm a huge fan of always using static linking.

   What happens when you static-link your program, without explicitly
   specifying "-lm387" before "-lm"?

   Do you have a small demonstration program you can post as an example
   test of what you're trying to do?

Curiously, my attempts to statically link the attached file fail:

% gcc -c test.c -o test.o
% gcc -static -lm test.o -o test
test.o: In function `main':
test.c:(.text+0x6a): undefined reference to `sin'

Dynamic linking works:

% gcc -lm test.o -o test
% ./test 1e22
sin (1.000000e+22) = 8.740281e-01

What I want to see (and what I do see on, say, Mac OS X, whose libm
computes good approximations) is:

% ./test 1e22
sin (1.000000e+22) = -8.522008e-01
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char *argv [])
{
  if (argc != 2)
    {
      fprintf (stderr, "Usage: %s <x>\n", (argv [0]));
      return (1);
    }
  {
    double x = (strtod ((argv [1]), NULL));
    printf ("sin (%e) = %e\n", x, (sin (x)));
  }
  return (0);
}


Home | Main Index | Thread Index | Old Index