Submit a Story  :  IRAF Links  :  Past Polls  :  Calendar  :  Advanced Search  
     iraf.net
FAQ
 Forum FAQForum FAQ   Forum SearchForum Search   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with %f in printf

 
Post new topic   Reply to topic    iraf.net Forum Index -> General IRAF
View previous topic :: View next topic  
Author Message
emma
Active IRAF User


Joined: 23 Jan 2006
Posts: 98
Location: Chile

PostPosted: Wed May 23, 2012 10:38 pm    Post subject: Problem with %f in printf Reply with quote

Hi Mike,

I've just come across a weird behaviour when using %f in printf. I've noticed this happens with IRAF 2.14.1 and IRAF 2.15.1a (but not with PyRAF):
Code:

ecl> real my_number
ecl> my_number = 3.0
ecl> printf ("%f\n", my_number)
3.000000000000000/
ecl> my_number = 3.1
ecl> printf ("%f\n", my_number)
3.0999999999999999
ecl> my_number = 3.0
ecl> printf ("%g\n", my_number)
3.

Notice the back slash at the end of the first printf statement.

Many thanks,

Emma Smile
Back to top
View user's profile Send private message
emma
Active IRAF User


Joined: 23 Jan 2006
Posts: 98
Location: Chile

PostPosted: Wed May 23, 2012 10:41 pm    Post subject: Reply with quote

*forward* slash (sorry!)
Back to top
View user's profile Send private message
fitz
Site Admin


Joined: 30 Sep 2005
Posts: 3256
Location: Tucson

PostPosted: Wed May 23, 2012 10:47 pm    Post subject: Reply with quote

What platform is this, it seems to work fine on v2.16 macintel. Note that the CL implements the 'real' type internally as double-precision which explains the extra digits, pyraf simply has it's own printf() function.
Back to top
View user's profile Send private message
emma
Active IRAF User


Joined: 23 Jan 2006
Posts: 98
Location: Chile

PostPosted: Wed May 23, 2012 10:55 pm    Post subject: Reply with quote

This is on my redhat linux machine (RHEL 5).

I'm not worried about the extra digits, just the trailing forward slash that shouldn't be there Wink

Thanks!

Emma Smile
Back to top
View user's profile Send private message
fitz
Site Admin


Joined: 30 Sep 2005
Posts: 3256
Location: Tucson

PostPosted: Sun May 27, 2012 6:28 am    Post subject: Reply with quote

I can confirm this is still present in the latest v2.16 system, but only on 32-bit linux systems. It appears to be some sort of round-off problem in the converter code, i.e. if the test value is 1.0, or 5.0, or 2.0 then the last character will be different. A '/' char comes immediately before a '0' in ascii but the converter isn't constraining the result.

I'll fix this for the next update, the workaround for now is to specify some level of precision, e.g. "%.8f"
Back to top
View user's profile Send private message
emma
Active IRAF User


Joined: 23 Jan 2006
Posts: 98
Location: Chile

PostPosted: Tue May 29, 2012 2:55 pm    Post subject: Reply with quote

Thanks, Mike! Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    iraf.net Forum Index -> General IRAF All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2009 phpBB Group
 Copyright © 2005-2011 iraf.net
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.09 seconds