LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-23-2003, 05:07 AM   #1
greenmuzz
Member
 
Registered: Oct 2003
Posts: 34

Rep: Reputation: 15
why would sin(0). return nan?


just entered the function, as shown in the output from gdb below.
'ang' comes from the parameter of the funciton, and can be seen to be 0.
single stepping through the next few lines should calculate the sin & cos
of ang, but the result is as you can see below.

What can cause this?

GetRay (isurf=0x804ff10, startx=80, starty=119, ang=0, oray=0xbfffea50) at actray.cpp:96
96 float cosAng = cos(ang);
(gdb)
97 float sinAng = sin(ang);
(gdb)
98 int lambda = 0;
(gdb) print sinAng
$3 = -nan(0x400000)
 
Old 10-23-2003, 05:50 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
I think it's a datatype overflow.
cos() and sin() for most implementations of C return a double, not a float.
 
Old 10-23-2003, 06:03 AM   #3
greenmuzz
Member
 
Registered: Oct 2003
Posts: 34

Original Poster
Rep: Reputation: 15
just tried, no change.

Did a test program too just to make sure there was nothing funny going on with the c++ libraries (well, you never know...). But they worked fine using float to get the answer back from cos & sin.

Could this be something to do with g++ version 2.95.3 ?

sn32/src> gcc -v
Reading specs from /usr/lib/gcc-lib/i486-suse-linux/2.95.3/specs
gcc version 2.95.3 20010315 (SuSE)

this is really annoying me now!

Last edited by greenmuzz; 10-23-2003 at 08:58 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SIN linux native - "cannot execute binary file" darkranger Linux - Games 1 06-07-2005 08:34 AM
problem with "NaN" in redhat 7.3, with gcc-2.96 mkh Programming 4 01-12-2004 01:05 PM
problem of "NaN" in redhat 7.3, with gcc-2.96 while running c_code mkh Programming 3 01-12-2004 01:17 AM
Sin for Linux. The SIN Raven Linux - Games 11 01-05-2004 12:34 PM
Sin for Linux The SIN Raven Linux - Games 0 12-18-2003 11:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration