Fedora Linux Support Community & Resources Center
  #1  
Old 8th February 2012, 12:37 AM
dave539 Offline
Registered User
 
Join Date: Jun 2011
Posts: 30
windows_xp_2003opera
Unhappy wierd output of fprintf for double variable

I don't do too much programming any more. However, I just got bit by something 'interesting'. I am caculating some percentages for names in an array. It works great IF what I am calculating the percentage for has some value other than 0. On the other hand, if the percentage should be zero what I get is -nan % instead of 0.0 %. I have tried this a couple of different outpout specs including 5.1F, D, and others.

I need a clue (yes that does mean I'm clueless). Does -nan stand for anything?

Thanks.
Reply With Quote
  #2  
Old 8th February 2012, 01:46 AM
jim1944 Offline
Registered User
 
Join Date: Jun 2007
Posts: 264
linuxfirefox
Re: wierd output of fprintf for double variable

"nan" stands for "not a number". It means that the value being converted is not a valid IEEE floating point number.

Jim
Reply With Quote
  #3  
Old 8th February 2012, 06:04 PM
Gareth Jones Offline
Official Gnome 3 Sales Rep. (and Adminstrator)
 
Join Date: Jul 2011
Location: Leamington Spa, UK
Age: 31
Posts: 2,750
linuxfirefox
Re: wierd output of fprintf for double variable

Basically that. "-nan" means "not a number", with the negative sign bit set.

NaN is actually a valid IEEE-fp value, but it has no mathematical value. It's produced when a mathematically undefined operation is performed, such as 0 ÷ 0 (or perhaps -0 ÷ 0 in this case).

Gareth
Reply With Quote
  #4  
Old 12th February 2012, 04:53 AM
jim1944 Offline
Registered User
 
Join Date: Jun 2007
Posts: 264
linuxfirefox
Re: wierd output of fprintf for double variable

Good point. I never saw a NaN that resulted from something like a divide by 0. I've always avoided undefined operations. So, when I got NaN, it was always the result of a memory clobber or failure to initialize. Thus I assumed that was how you got such a thing. Your post prompted me to look it up for fuller definition (http://en.wikipedia.org/wiki/NaN). Interesting.

Thanks
Jim
Reply With Quote
  #5  
Old 12th February 2012, 03:58 PM
dave539 Offline
Registered User
 
Join Date: Jun 2011
Posts: 30
windows_xp_2003opera
Re: wierd output of fprintf for double variable

I first thought of hte memory clobber thing too. A tried adding parrentheses around all sort fo things where the math was done....that didn't help.

BTW, the actual math in my case should be 0.0 / 0.0 I finally left everything the way I started and set the divisor to 0.00000001d and that worked like a champ. So, 0.0 / 0.0000001d equals 0.0 (for me at least).
Reply With Quote
Reply

Tags
double, fprintf, output, variable, wierd

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
"shared class variable" vs "class instance variable" recondite Programming & Packaging 5 23rd August 2010 12:48 AM
Command display output on console and simultaneously save the command and its output satimis Linux Chat 10 1st August 2008 03:02 AM
It is Wierd bokken Using Fedora 91 29th October 2007 04:52 PM
output a file to ternimal but keep the output updated Saint Mike Using Fedora 2 30th December 2006 11:22 AM
SiS 630 and wierd 3D fish Hardware & Laptops 3 2nd December 2003 11:56 AM


Current GMT-time: 15:22 (Saturday, 23-08-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat