ezrosent / frawk

an efficient awk-like language
Apache License 2.0
1.24k stars 34 forks source link

Scientific notation is not supported in awk script. #83

Open ghuls opened 2 years ago

ghuls commented 2 years ago

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
ezrosent commented 2 years ago

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 commented 2 years ago

That latest commit should fix the bug