LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-13-2006, 04:27 AM   #1
ztdep
Member
 
Registered: Jul 2005
Posts: 219

Rep: Reputation: 31
why "NAN"


Hello:
I encounter some problem when i run my fortran program on the linu WS 4(64bit) .
I compile the program with g95. and my cpu is intel xeon 64bit
real*8 var1=0.2539998000
real*8 var2=0.2539970307
when i compute the var1-var2, it gives "NaN"
So what is the reason of getting a NaN.
Regards
 
Old 11-13-2006, 01:30 PM   #2
Ohesceayar
LQ Newbie
 
Registered: Nov 2006
Posts: 6

Rep: Reputation: 0
The only possible reason I can think of is that your var1 and var2 variables are not being initialized to what you think they are being initialized to.

Try putting a print statement before the calculation, I bet one or both are already NAN even before the subtraction.
 
Old 11-15-2006, 01:19 AM   #3
asgeirss
Member
 
Registered: Aug 2003
Location: Vancouver, Canada
Distribution: RH, SL
Posts: 37

Rep: Reputation: 15
You are setting both var1 and var2 to 8 bits, but you are trying to put values with too many digits into them. They are NaN "not a number" right after they are allocated.

Try shortening out the number of decimal places, one by one, and eventually it will work.

- Dave
 
Old 11-15-2006, 09:53 AM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Quote:
Originally Posted by asgeirss
You are setting both var1 and var2 to 8 bits, but you are trying to put values with too many digits into them. They are NaN "not a number" right after they are allocated.

Try shortening out the number of decimal places, one by one, and eventually it will work.

- Dave
REAL*8 equates to a C double which for the OP's environment should have a minimum 15 digits of precision.

Offhand, I don't see the problem. He is on 64 bit box, maybe the compiler is creating 32 bit code and calling the wrong (32 bit)runtime library. Just guessing. I don't know if there is 64 bit support for GNU FORTRAN.
 
Old 11-16-2006, 06:19 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
REAL * 8 => 8 bytes => C style long long
 
Old 11-17-2006, 01:10 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by chrism01
REAL * 8 => 8 bytes => C style long long
Nope, real means floating point variable, not integer. Jim is right.
 
Old 11-17-2006, 09:32 AM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Correct. REAL is floating-point.

Display both operands before you compute with them. I think that you will find that one or both operands are "NaN."
 
Old 11-19-2006, 11:04 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
oops, sorry, brain fart there. I was thinking of something else.
 
  


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
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 11:26 AM
Any way to get "Alice"; "Call of Duty" series and "Descent 3" to work? JBailey742 Linux - Games 13 06-23-2006 01:34 PM
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
Is solution for control "NaN" and "Inf" in C/C++ gmitra Programming 2 09-19-2002 08:57 AM

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

All times are GMT -5. The time now is 02:14 PM.

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