Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awk example is deceptive #234

Open
gromnitsky opened this issue Jan 17, 2023 · 0 comments
Open

awk example is deceptive #234

gromnitsky opened this issue Jan 17, 2023 · 0 comments

Comments

@gromnitsky
Copy link

$ awk --version | head -1
GNU Awk 5.1.1, API: 3.1 (GNU MPFR 4.1.0-p13, GNU MP 6.2.1)

The example indeed prints 0.3, but 0.1 + 0.2 != 0.3:

$ awk 'BEGIN { print 0.1 + 0.2 }'
0.3
$ awk 'BEGIN { print (0.1 + 0.2) == 0.3 }'
0

It's because

$ awk 'BEGIN { printf "%0.25f", 0.1 + 0.2 }'
0.3000000000000000444089210
$ awk 'BEGIN { printf "%0.25f", 0.3 }'
0.2999999999999999888977698
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant