Mail Archives: djgpp/1997/07/16/08:47:22
From: | "George Kinney" <goober AT mail DOT net>
|
Subject: | Re: Why doesn't this work (correct, running code)
|
Newsgroups: | comp.os.msdos.djgpp
|
References: | <5qf224$6m0$1 AT missing DOT link DOT ca>
|
Organization: | The Unknown Programmers
|
Message-ID: | <01bc91cf$959d40e0$e68033cf@pentium>
|
NNTP-Posting-Host: | 207.51.128.230
|
Date: | 16 Jul 97 09:55:05 GMT
|
Lines: | 53
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
James Edwin Cooper <ab837 AT sfn DOT saskatoon DOT sk DOT ca> wrote in article
<5qf224$6m0$1 AT missing DOT link DOT ca>...
> Sorry, me again! Anyway, I just made this program, changed it until there
> weren't any DAMN errors, and now it doesn't work! It is a SUPER fast SIN
> calculator (integer values only). The problem is, no matter WHAT number
> you type in, it always pumps out 0.000000. Any reason?
>
> *** WARNING: DJGPP V1 CODE START ***
Get DJGPP v2+ ! It'll save you many headaches. (As well as being supported)
[CLIP]
> float answer,sintable[360];
[CLIP]
> for(i=0;i<360;i++)
> {
> sintable[i]=sin(i);
> printf(".");
> }
sin takes radians, not degrees. The values stored in sintable are most
certainly not what you seem to think they are.
[SNIP]
> printf("\nThe answer is %f.\n\n");
I hope this is a typo. It should read:
printf( "\nThe answer is %f.\n\n", answer );
It would certainly be beneficial to you to get a good book on the C
language,
or at least check the standard librarys reference when calling a function
so
that you can make sure you are actually using it properly, and that it
will
do what you expect. (if used properly that is)
[CLIP]
> Sorry if this doesn't look perfect or run fast, it was a 15 minute hack
> by a newbie. Anyway, If this should work, then can you give me hints?
> Otherwise, a simple fix would be nice! Thanks in advance :)
Also, print out the contents of sintable after your calculations,
you'll notice that it is a string of numbers that are actually the
sin values taken every ~60 degrees or so.
If you don't know what a radian is, get a math book to go along with
the C book. (HINT: there are 2PI radians in a circle)
And above all, read the info files on the library functions you intend to
use, it will save you from many errors like these.
- Raw text -