frawk icon indicating copy to clipboard operation
frawk copied to clipboard

Scientific notation is not supported in awk script.

Open ghuls opened this issue 3 years ago • 2 comments

Scientific notation is not supported in awk script, but works for parsing files with scientific notation.

$ printf '6.18163e-27\n1.80782e-40\n2.38296e-05\n1.92843e-09\n7.37465e-39\n' | frawk '$1 <= 1e-8'

$ printf '6.18163e-27\n1.80782e-40\n2.38296e-05\n1.92843e-09\n7.37465e-39\n' | frawk '$1 <= 1E-8'


$ printf '6.18163e-27\n1.80782e-40\n2.38296e-05\n1.92843e-09\n7.37465e-39\n' | frawk '$1 <= 10^-8'
6.18163e-27
1.80782e-40
1.92843e-09
7.37465e-39

# It understands scientific notation when parsing files itself.
$ printf '6.18163e-27\n1.80782e-40\n2.38296e-05\n1.92843e-09\n7.37465e-39\n' | frawk '{ if ($1 <= 10^-8) { print $1, ($1 + 0.0); } }'
6.18163e-27 6.18163e-27
1.80782e-40 1.80782e-40
1.92843e-09 1.92843e-9
7.37465e-39 7.37465e-39


$ printf '6.18163e-27\n1.80782e-40\n2.38296e-05\n1.92843e-09\n7.37465e-39\n' | gawk '$1 <= 1e-8'
6.18163e-27
1.80782e-40
1.92843e-09
7.37465e-39

$ printf '6.18163e-27\n1.80782e-40\n2.38296e-05\n1.92843e-09\n7.37465e-39\n' | gawk '$1 <= 1E-8'
6.18163e-27
1.80782e-40
1.92843e-09
7.37465e-39

$ printf '6.18163e-27\n1.80782e-40\n2.38296e-05\n1.92843e-09\n7.37465e-39\n' | gawk '$1 <= 10^-8'
6.18163e-27
1.80782e-40
1.92843e-09
7.37465e-39

ghuls avatar Jan 28 '22 10:01 ghuls

Ah, good catch! This is a limitation of the regex used to identify if a numeric literal is a float or not. This ought to be a simple fix.

ezrosent avatar Jan 29 '22 02:01 ezrosent

That latest commit should fix the bug

ezrosent avatar Jan 30 '22 00:01 ezrosent