View Full Version : Using tan(), sin() etc.
mavix
October 11th, 2006, 10:03 AM
How do I use the tan() and sin() functions in GCC? I included math.h, but returns an error message.
Lord Illidan
October 11th, 2006, 10:18 AM
I think you have to compile it with the -lm option.
like gcc foo.c -o foo -lm
MWAAAHAAA
October 11th, 2006, 03:01 PM
If you ever wonder about how to use a function, try the manual page. For example 'man sin' gives me the following:
SIN(3) Linux Programmer’s Manual SIN(3)
NAME
sin, sinf, sinl - sine function
SYNOPSIS
#include <math.h>
double sin(double x);
float sinf(float x);
long double sinl(long double x);
Link with -lm.
Yada, yada, yada
56phil
November 28th, 2006, 12:47 AM
What do I need to install?
prh@phil-laptop:~$ man sin
No manual entry for sin
xtacocorex
November 28th, 2006, 12:57 AM
You need to put std:: in front of sin, cos, and tan. That's if you didn't declare a namespace at the beginning of the code, which is not good practice if you are using more than one namespace in a code.
An example from my airfoil generation code:
PI=4.0*std::atan(1.0);
I did include cmath instead of math.h.
#include <cmath>
I didn't do any special linking in my compile and it works fine.
EDIT: Thought you were doing C++, so I don't know if cmath will work.
Choad
November 28th, 2006, 01:08 AM
If you ever wonder about how to use a function, try the manual page. For example 'man sin' gives me the following:
SIN(3) Linux Programmer’s Manual SIN(3)
NAME
sin, sinf, sinl - sine function
SYNOPSIS
#include <math.h>
double sin(double x);
float sinf(float x);
long double sinl(long double x);
Link with -lm.
Yada, yada, yada
legend! i was wondering where the hell you find out about that stuff without just posting billions of threads on forums :rolleyes:
Ragazzo
November 28th, 2006, 12:04 PM
What do I need to install?
prh@phil-laptop:~$ man sin
No manual entry for sin
manpages-dev
daniminas
November 28th, 2006, 12:43 PM
Exist some basic guide or list of the parameters of Gcc?.. (then 'MAN')..
Thanks ;)
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.