473,378 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

math.h trig functions questions (and some forgotten high school math)

Do the trig functions in math.h work in degrees, radians or what? For
some reason it doesn't say which in "man math.h"

IIRC the arctan of a slope gives the angle. So, shouldn't atanf((float)1)
return 45 or .7something (degrees or radians) instead of some negative
number?

--
Mark Healey
marknews(at)healeyonline(dot)com

May 21 '06 #1
7 3096
Mark Healey <di*@spammer.die> writes:
Do the trig functions in math.h work in degrees, radians or what? For
some reason it doesn't say which in "man math.h" IIRC the arctan of a slope gives the angle. So, shouldn't atanf((float)1)
return 45 or .7something (degrees or radians) instead of some negative
number?

If on a Unix/Linux system - man 3 sin

--
Chris.
May 21 '06 #2
On Sun, 21 May 2006 03:43:36 GMT, Mark Healey <di*@spammer.die> wrote
in comp.lang.c:
Do the trig functions in math.h work in degrees, radians or what? For
some reason it doesn't say which in "man math.h"

IIRC the arctan of a slope gives the angle. So, shouldn't atanf((float)1)
return 45 or .7something (degrees or radians) instead of some negative
number?


Doesn't your C reference book tell you? All C trigonometric functions
work in radians. If you want to work in degrees, you need to provide
functions or macros to do the conversions back and forth.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
May 21 '06 #3
Mark Healey <di*@spammer.die> writes:
Do the trig functions in math.h work in degrees, radians or what? For
some reason it doesn't say which in "man math.h"

IIRC the arctan of a slope gives the angle. So, shouldn't atanf((float)1)
return 45 or .7something (degrees or radians) instead of some negative
number?


Some negative number?

This program:

#include <stdio.h>
#include <math.h>
int main(void)
{
printf("atanf((float)1.0) = %f\n", atanf((float)1.0));
return 0;
}

gives me:

atanf((float)1.0) = 0.785398

Did you remember the "#include <math.h>"? Did you make sure to link
in the math library (on a Unix-like system, you might need a "-lm"
option).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 21 '06 #4

"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
Mark Healey <di*@spammer.die> writes:
Do the trig functions in math.h work in degrees, radians or what? For
some reason it doesn't say which in "man math.h"

IIRC the arctan of a slope gives the angle. So, shouldn't
atanf((float)1)
return 45 or .7something (degrees or radians) instead of some negative
number?


Some negative number?

This program:

#include <stdio.h>
#include <math.h>
int main(void)
{
printf("atanf((float)1.0) = %f\n", atanf((float)1.0));
return 0;
}

gives me:

atanf((float)1.0) = 0.785398

Did you remember the "#include <math.h>"? Did you make sure to link
in the math library (on a Unix-like system, you might need a "-lm"
option).


And would atanf be in there, in particular one that accepts a float as
opposed to double? joe
May 21 '06 #5
"Joe Smith" <gr**********@netzero.net> writes:
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
Mark Healey <di*@spammer.die> writes:
Do the trig functions in math.h work in degrees, radians or what? For
some reason it doesn't say which in "man math.h"

IIRC the arctan of a slope gives the angle. So, shouldn't
atanf((float)1)
return 45 or .7something (degrees or radians) instead of some negative
number?


Some negative number?

This program:

#include <stdio.h>
#include <math.h>
int main(void)
{
printf("atanf((float)1.0) = %f\n", atanf((float)1.0));
return 0;
}

gives me:

atanf((float)1.0) = 0.785398

Did you remember the "#include <math.h>"? Did you make sure to link
in the math library (on a Unix-like system, you might need a "-lm"
option).


And would atanf be in there, in particular one that accepts a float as
opposed to double? joe


Possibly not, since atanf was added in C99 -- but if atanf weren't in
the library, that wouldn't explain the OP's result of "some negative
number".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 22 '06 #6

"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
"Joe Smith" <gr**********@netzero.net> writes:
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
Mark Healey <di*@spammer.die> writes:
Do the trig functions in math.h work in degrees, radians or what? For
some reason it doesn't say which in "man math.h"

IIRC the arctan of a slope gives the angle. So, shouldn't
atanf((float)1)
return 45 or .7something (degrees or radians) instead of some negative
number?

Some negative number?

This program:

#include <stdio.h>
#include <math.h>
int main(void)
{
printf("atanf((float)1.0) = %f\n", atanf((float)1.0));
return 0;
}

gives me:

atanf((float)1.0) = 0.785398

Did you remember the "#include <math.h>"? Did you make sure to link
in the math library (on a Unix-like system, you might need a "-lm"
option).


And would atanf be in there, in particular one that accepts a float as
opposed to double? joe


Possibly not, since atanf was added in C99 -- but if atanf weren't in
the library, that wouldn't explain the OP's result of "some negative
number".

I'm surprised that my implementation, circa ten years old, has it. joe

#ifdef _M_MRX000

/* MIPS fast prototypes for float */
/* ANSI C, 4.5 Mathematics */

/* 4.5.2 Trigonometric functions */

_CRTIMP float __cdecl acosf( float );
_CRTIMP float __cdecl asinf( float );
_CRTIMP float __cdecl atanf( float );
_CRTIMP float __cdecl atan2f( float , float );
_CRTIMP float __cdecl cosf( float );
_CRTIMP float __cdecl sinf( float );
_CRTIMP float __cdecl tanf( float );
May 22 '06 #7
Joe Smith wrote:
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
"Joe Smith" <gr**********@netzero.net> writes:
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
Mark Healey <di*@spammer.die> writes:
> Do the trig functions in math.h work in degrees, radians or what? For
> some reason it doesn't say which in "man math.h"
>
> IIRC the arctan of a slope gives the angle. So, shouldn't
> atanf((float)1)
> return 45 or .7something (degrees or radians) instead of some negative
> number?
Some negative number?

This program:

#include <stdio.h>
#include <math.h>
int main(void)
{
printf("atanf((float)1.0) = %f\n", atanf((float)1.0));
return 0;
}

gives me:

atanf((float)1.0) = 0.785398

Did you remember the "#include <math.h>"? Did you make sure to link
in the math library (on a Unix-like system, you might need a "-lm"
option).
And would atanf be in there, in particular one that accepts a float as
opposed to double? joe

Possibly not, since atanf was added in C99 -- but if atanf weren't in
the library, that wouldn't explain the OP's result of "some negative
number".

I'm surprised that my implementation, circa ten years old, has it. joe

#ifdef _M_MRX000

/* MIPS fast prototypes for float */
/* ANSI C, 4.5 Mathematics */

/* 4.5.2 Trigonometric functions */

_CRTIMP float __cdecl acosf( float );
_CRTIMP float __cdecl asinf( float );
_CRTIMP float __cdecl atanf( float );
_CRTIMP float __cdecl atan2f( float , float );
_CRTIMP float __cdecl cosf( float );
_CRTIMP float __cdecl sinf( float );
_CRTIMP float __cdecl tanf( float );

The math functions for float data type were reserved and made optional
in C89, and mandatory in C99. This seems to have produced some
confusion as to whether restricting a compiler to C89 mode, (gcc
default), may suppress the float functions, or break them, as in some
MSVC versions. Clearly, the provision for them in C89 was produced by
strong demand and intention of certain vendors to provide them.
May 22 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Frank Millman | last post by:
Hi all I was helping my niece with her trigonometry homework last night. Her calculator's batteries were flat, so I thought I would use Python's math module to calculate sin, cos, and tan. I...
17
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
4
by: John B. | last post by:
I'm self teaching myself C on a Linux box but I can't get a simple program to recognize math functions. I start the program with: #include <stdio.h> #include <math.h> but when I...
92
by: Dave Rudolf | last post by:
Hi all, Normally, I would trust that the ANSI libraries are written to be as efficient as possible, but I have an application in which the majority of the run time is calling the acos(...)...
5
by: Tom Gurath | last post by:
http://osnews.com/story.php?news_id=5602&page=2 This benchmark tests the Math & File I/O of 9 languages/run-times. Visual C++ (Version 7 - not managed) Visual C# gcc C Visual Basic.NET Visual...
110
by: Gregory Pietsch | last post by:
I'm writing a portable implementation of the C standard library for http://www.clc-wiki.net and I was wondering if someone could check the functions in math.h for sanity/portability/whatever. I'm...
15
by: Morgan Cheng | last post by:
Hi, I am writing a program that will take a lot of Math.Cos & Math.Sin operation. I am afraid this will be source of performance impact. Anybody knows how Math.cos & Math.Sin is implemented?...
0
by: kirby.urner | last post by:
Cyber-curricula have a leveling aspect, as kids nearer Katrina's epicenter tune in and bliss out on 'Warriors of the Net' (why wait for stupid big dummy textbooks to catch up?). They feel more...
0
by: Jon Harrop | last post by:
xahlee@gmail.com wrote: This does not even start running in Mathematica 6, let alone produce any correct results. The first line was deprecated some time ago. I don't know what is wrong with the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.