strange math.h probs

strange math.h probs

Post by Doug Crawfo » Tue, 30 Jan 1996 04:00:00



I've just installed a new version of Linux (kernel 3.2.0) and I
am having some strange problems with the math.h library.
When I write a program like this:

#include <math.h>
#include <stdlib.h>
void main () {
  printf("%f",atan(1));

Quote:}

When I write that, I ALWAYS get 0.785398 for the atan of 1, which
is supposed to really be 45.
I've tried it about 15 different ways, using doubles and ints
and different ways of putting the value into printf, but I
always get the same value, or something equally as strange out.
I figured out that (tan(1))*(atan(1)) is very close to the value
but I don't think it has anything to do with it.
Please help me, I've included the -lm thing, and it used to work
with my old kernel 1.0.8., but I can't figure out what's going
on with it, it does a clean compile with no errors.

Henson Daytona

 
 
 

strange math.h probs

Post by Martin Kroek » Tue, 30 Jan 1996 04:00:00



> When I write that, I ALWAYS get 0.785398 for the atan of 1, which
> is supposed to really be 45.

What you see is 45 degrees expressed as radians, the 180/PI conversion is
up to you (and always was, at least as far as 1.0.9 is concerned). ;-)
Hope this helps,
Martin
--
Dr.-Ing. Martin Kroeker                


Germany                                    

 
 
 

strange math.h probs

Post by BOISVIEUX Jean-Francoi » Tue, 30 Jan 1996 04:00:00



>Please help me, I've included the -lm thing, and it used to work
>with my old kernel 1.0.8., but I can't figure out what's going
>on with it, it does a clean compile with no errors.

>Henson Daytona

very strange indeed as 0.785 * 4 = 3.14 , which seems to suggest that your
result is Pi/4 which might be 180/4 = 45.

btw man atan gives : return value of atan is in RADIAN

--
 Universite Paris VI             |       Jean-Francois Boisvieux         |
 C.H.U Pitie-Salpetriere         |                                       |
 Departement de Biomathematiques | Tel: 33 1 45861998 Fax: 33 1 45865685 |

 75634 Paris cedex 13 France     |                                       |

 
 
 

strange math.h probs

Post by Steve Meisne » Tue, 30 Jan 1996 04:00:00



> I've just installed a new version of Linux (kernel 3.2.0) and I
> am having some strange problems with the math.h library.
> When I write a program like this:

> #include <math.h>
> #include <stdlib.h>
> void main () {
>   printf("%f",atan(1));
> }

> When I write that, I ALWAYS get 0.785398 for the atan of 1, which
> is supposed to really be 45.
> I've tried it about 15 different ways, using doubles and ints
> and different ways of putting the value into printf, but I
> always get the same value, or something equally as strange out.
> I figured out that (tan(1))*(atan(1)) is very close to the value
> but I don't think it has anything to do with it.
> Please help me, I've included the -lm thing, and it used to work
> with my old kernel 1.0.8., but I can't figure out what's going
> on with it, it does a clean compile with no errors.

> Henson Daytona

That's because the answer is in Radians.  If you want the answer in
degrees, multiply by (180/PI).
--

Courtesy of Netscape and Linux
 
 
 

strange math.h probs

Post by Fred Gylys-Colwe » Tue, 30 Jan 1996 04:00:00




>I've just installed a new version of Linux (kernel 3.2.0) and I
>am having some strange problems with the math.h library.
>When I write a program like this:

>#include <math.h>
>#include <stdlib.h>
>void main () {
>  printf("%f",atan(1));
>}

>When I write that, I ALWAYS get 0.785398 for the atan of 1, which
>is supposed to really be 45.

Actually, atan(1) is pi/4, which is approximately  0.785398.  To
convert from radians to degrees, multiply by (180.0/3.14159).
        Fred GC.
--

 
 
 

strange math.h probs

Post by Peter Dalgaard B » Wed, 31 Jan 1996 04:00:00


   I've just installed a new version of Linux (kernel 3.2.0) and I
   am having some strange problems with the math.h library.
   When I write a program like this:

   #include <math.h>
   #include <stdlib.h>
   void main () {
     printf("%f",atan(1));
   }

   When I write that, I ALWAYS get 0.785398 for the atan of 1, which
   is supposed to really be 45.

Oh, dear!

Didn't you ever wonder what that DEG/RAD switch was doing on your
calculator?

Try multiplying 0.785398 by 4, I think that might clue you in...

It's as easy as...
--
   O_   ---- Peter Dalgaard
  c/ /'  --- Dept. of Biostatistics
 ( ) \( ) -- University of Copenhagen

 
 
 

strange math.h probs

Post by Thomas Pun » Wed, 31 Jan 1996 04:00:00


Hello,

| I've just installed a new version of Linux (kernel 3.2.0) and I
| am having some strange problems with the math.h library.

First of all, this is not a kernel "problem" (it's not a "problem at
all) -- its handled by libm.

| When I write a program like this:
|
| #include <math.h>
| #include <stdlib.h>
            ^^^^^^^^
printf() is defined in <stdio.h>

| void main () {
|   printf("%f",atan(1));
| }
|
| When I write that, I ALWAYS get 0.785398 for the atan of 1, which
| is supposed to really be 45.

Do you know the difference between radian and degree? Both values
are correct -- you have to supply the correct unit. From the man page:

RETURN VALUE
     The atan() function returns the arc tangent in  radians  and
     the  value is mathematically defined to be between -PI/2 and
     PI/2 (inclusive).

[...]
| I figured out that (tan(1))*(atan(1)) is very close to the value
| but I don't think it has anything to do with it.

oh, it has. Both, tan() and atan() return their values in units of
radian. If you want a degree return value, you have to
multiply it with 180/PI, i.e. you could use the following macro:

#define my_atan(x)      (atan(x)*180/M_PI)

| Please help me, I've included the -lm thing, and it used to work
| with my old kernel 1.0.8., but I can't figure out what's going

That would make me wonder ...

| on with it, it does a clean compile with no errors.
|
| Henson Daytona

Thomas
--

     <<o>> <<o>>                     Westfaelische Wilhelms-Universitaet
          ^                          Einsteinstr. 62, D-48149 Muenster, Germany
          -                          (+49) 251 - 83 3747