Welcome to iraf.net Friday, April 26 2024 @ 03:20 PM GMT


 Forum Index > Help Desk > General IRAF New Topic Post Reply
 Problem with %f in printf
   
emma
 05/23/2012 10:38PM (Read 2958 times)  
++++-
Regular Member

Status: offline


Registered: 01/23/2006
Posts: 101
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:1:c491e8a3f3]
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.
[/code:1:c491e8a3f3]
Notice the back slash at the end of the first printf statement.Many thanks,Emma Smile

 
Profile Email
 Quote
emma
 05/23/2012 10:38PM  
++++-
Regular Member

Status: offline


Registered: 01/23/2006
Posts: 101
*forward* slash (sorry!)

 
Profile Email
 Quote
fitz
 05/23/2012 10:38PM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
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.

 
Profile Email
 Quote
emma
 05/23/2012 10:38PM  
++++-
Regular Member

Status: offline


Registered: 01/23/2006
Posts: 101
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 WinkThanks!Emma Smile

 
Profile Email
 Quote
fitz
 05/23/2012 10:38PM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
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"

 
Profile Email
 Quote
emma
 05/23/2012 10:38PM  
++++-
Regular Member

Status: offline


Registered: 01/23/2006
Posts: 101
Thanks, Mike! Smile

 
Profile Email
 Quote
   
Content generated in: 0.28 seconds
New Topic Post Reply

Normal Topic Normal Topic
Sticky Topic Sticky Topic
Locked Topic Locked Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Anonymous users can post 
Filtered HTML Allowed 
Censored Content 
dog allergies remedies cialis 20 mg chilblain remedies


Privacy Policy
Terms of Use

User Functions

Login