[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] Interesting floating point behavior
From: |
Robert Kennedy |
Subject: |
[bug-gawk] Interesting floating point behavior |
Date: |
Fri, 20 Jan 2012 08:35:16 -0600 |
# gawk --version
GNU Awk 4.0.0
# echo -e "Input\t*10000\t%100"; for i in 0.67 0.68 0.69 0.70; do echo
$i |gawk '{a=$1; b=a*10000; c=b%100; print a,"\t",b,"\t",c}'; done
Input *10000 %100
0.67 6700 0
0.68 6800 9.09495e-13
0.69 6900 100
0.70 7000 0
The very-close-to-zero number for 0.68 is not surprising, the result
of the modulo for the 0.69 input seems... strange. You can see this
happen at .57 as well:
echo -e "Input\t*10000\t%100"; for i in $(seq -w 00 99); do echo
"0.$i" |gawk '{a=$1; b=a*10000; c=b%100; print a,"\t",b,"\t",c}'; done
This has been around since the 3.1 days at least. Any ideas?
Cheers,
Robert K.
--
---------------------------------------------------------------
This email, along with any attachments, is confidential. If you
believe you received this message in error, please contact the
sender immediately and delete all copies of the message.
Thank you.
- [bug-gawk] Interesting floating point behavior,
Robert Kennedy <=