Welcome to iraf.net Friday, April 26 2024 @ 03:20 PM GMT
emma |
05/23/2012 10:38PM (Read 2958 times)
|
|
|
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
|
|
|
|
emma |
05/23/2012 10:38PM
|
|
|
Status: offline
Registered: 01/23/2006
Posts: 101
|
*forward* slash (sorry!)
|
|
|
|
fitz |
05/23/2012 10:38PM
|
|
|
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.
|
|
|
|
emma |
05/23/2012 10:38PM
|
|
|
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 Thanks!Emma
|
|
|
|
fitz |
05/23/2012 10:38PM
|
|
|
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"
|
|
|
|
emma |
05/23/2012 10:38PM
|
|
|
Status: offline
Registered: 01/23/2006
Posts: 101
|
Thanks, Mike!
|
|
|
|
| |
|
Content generated in: 0.28 seconds |
|