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

Discussion in 'C Programming' started by Mark Healey, May 21, 2006.

  1. Mark Healey

    Mark Healey Guest

    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
     
    Mark Healey, May 21, 2006
    #1
    1. Advertising

  2. Mark Healey <> 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.
     
    Chris McDonald, May 21, 2006
    #2
    1. Advertising

  3. Mark Healey

    Jack Klein Guest

    On Sun, 21 May 2006 03:43:36 GMT, Mark Healey <> 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/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, May 21, 2006
    #3
  4. Re: math.h trig functions questions (and some forgotten high schoolmath)

    Mark Healey <> 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) <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.
     
    Keith Thompson, May 21, 2006
    #4
  5. Mark Healey

    Joe Smith Guest

    "Keith Thompson" <> wrote in message
    news:...
    > Mark Healey <> 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
     
    Joe Smith, May 22, 2006
    #5
  6. Re: math.h trig functions questions (and some forgotten high schoolmath)

    "Joe Smith" <> writes:
    > "Keith Thompson" <> wrote in message
    > news:...
    >> Mark Healey <> 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) <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.
     
    Keith Thompson, May 22, 2006
    #6
  7. Mark Healey

    Joe Smith Guest

    "Keith Thompson" <> wrote in message
    news:...
    > "Joe Smith" <> writes:
    >> "Keith Thompson" <> wrote in message
    >> news:...
    >>> Mark Healey <> 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 );
     
    Joe Smith, May 22, 2006
    #7
  8. Mark Healey

    Tim Prince Guest

    Re: math.h trig functions questions (and some forgotten high schoolmath)

    Joe Smith wrote:
    > "Keith Thompson" <> wrote in message
    > news:...
    >> "Joe Smith" <> writes:
    >>> "Keith Thompson" <> wrote in message
    >>> news:...
    >>>> Mark Healey <> 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.
     
    Tim Prince, May 22, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kwikius
    Replies:
    1
    Views:
    402
    Default User
    May 22, 2008
  2. jack
    Replies:
    0
    Views:
    415
  3. John
    Replies:
    2
    Views:
    120
  4. Andre Majorel

    POSIX and Math::Trig

    Andre Majorel, Sep 6, 2010, in forum: Perl Misc
    Replies:
    9
    Views:
    223
    Ilya Zakharevich
    Sep 6, 2010
  5. VK
    Replies:
    15
    Views:
    1,327
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page