[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to use trigonometric functions in Swarm?
From: |
Paul E. Johnson |
Subject: |
Re: How to use trigonometric functions in Swarm? |
Date: |
Mon, 19 Jun 2000 09:54:55 -0500 |
Perrone Alessandro wrote:
>
> I imported the right header, but when I call the sin(x) function, an
> error occur!!
> I am using Linux on my Imac, with Swarm 2.1.1
> Here it is the result with a simple program:
>
> ------
> address@hidden apps]# gcc alex.c -o alex
> /tmp/ccHDfVDm.o: In function `main':
> /tmp/ccHDfVDm.o(.text+0x20): undefined reference to `sin'
> /tmp/ccHDfVDm.o(.text+0x20): relocation truncated to fit: R_PPC_REL24 sin
> collect2: ld returned 1 exit status
> address@hidden apps]# more alex.c
> #include <stdio.h>
> #include <math.h>
>
> int main () {
> float a;
> a=(float) sin((double) 1.0);
> printf("%f\n",a);
> return 0;
> }
> address@hidden apps]# gcc -I/usr/include alex.c -o alex
I use the math library in RedHat linux by including the math.h as you
do, and it works fine, when I compile a Swarm program. I was reading
the C faq last week (http://www.faqs.org/faqs/C-faq/faq/) and this math
question is in there. Gary's point about -lm is correct. Swarm does it
automatically, without any intervention from me. The "-lm" line appears
in the output of the linker, I mean to say.
But I have one thing to add, which is that I think that the sin function
is expecting to have a value for PI*X in the parentheses if you want
sin(x), and the values you want are in math.h. M_PIl is a long double
value on this system. Like this:
valueSinX = sin(M_PIl*X);
--
Paul E. Johnson email: address@hidden
Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.