Mail Archives: djgpp/1999/05/15/07:27:20
From: | Martin Ambuhl <mambuhl AT earthlink DOT net>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: cos(90 * (PI / 180) = 6.12......?
|
Date: | Fri, 14 May 1999 22:51:53 -0400
|
References: | <926562032 DOT 737 DOT 64 AT news DOT remarQ DOT com>
|
X-Posted-Path-Was: | not-for-mail
|
X-Accept-Language: | en
|
X-ELN-Date: | 15 May 1999 02:50:39 GMT
|
X-ELN-Insert-Date: | Fri May 14 19:55:15 1999
|
Organization: | Nocturnal Aviation
|
Lines: | 42
|
Mime-Version: | 1.0
|
NNTP-Posting-Host: | dialup-209.246.66.218.newyork2.level3.net
|
Message-ID: | <373CE149.8C7EB282@earthlink.net>
|
X-Mailer: | Mozilla 4.51 [en] (Win95; I)
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Shaggs wrote:
>
> wtf is up with this, all my other cosine values seem to be normal, but this
> comes up (although i havent checked 270).
>
> any ideas? please help ASAP
There is nothing strange here...
#undef __STRICT_ANSI__
#include <math.h>
#include <stdio.h>
#include <float.h>
int main(void)
{
double angle = M_PI / 2, result = cos(M_PI / 2);
printf("\"Shaggs\" <jud AT tminet DOT com> reports "
"cos(90 degrees == %g)==6.12...\n"
"but we get cos(%g)==%g\n"
"Note that \"Shaggs\" did not report the exponent.\n"
"It is important to remember that even though DBL_MIN==%g,\n"
"in computations it is best to treat numbers smaller than\n"
"a small multiple (usually 4-6) of DBL_EPSILON==%g as zero\n"
"and (cos(%g)==%g)/(DBL_EPSILON==%g) == %g\n",
angle, angle, result, DBL_MIN, DBL_EPSILON,
angle, result, DBL_EPSILON, result / DBL_EPSILON);
return 0;
}
"Shaggs" <jud AT tminet DOT com> reports cos(90 degrees == 1.5708)==6.12...
but we get cos(1.5708)==6.1232e-17
Note that "Shaggs" did not report the exponent.
It is important to remember that even though DBL_MIN==2.22507e-308,
in computations it is best to treat numbers smaller than
a small multiple (usually 4-6) of DBL_EPSILON==2.22045e-16 as zero
and (cos(1.5708)==6.1232e-17)/(DBL_EPSILON==2.22045e-16) == 0.275764
--
Martin Ambuhl (mambuhl AT earthlink DOT net)
Note: mambuhl AT tiac DOT net will soon be inactive
- Raw text -