Anyone who doesn't know about this really shouldn't be speaking on what computers are supposedly good at
(This is not a bug. This is documented and expected behavior in pretty much every widely used programming language today. See: IEEE 754)
Discussion
Anyone who doesn't know about this really shouldn't be speaking on what computers are supposedly good at
(This is not a bug. This is documented and expected behavior in pretty much every widely used programming language today. See: IEEE 754)
@ferret yeah, but that's not great either, right? because it diverges from the behavior of standard floating point numbers that's established nearly everywhere else
@ferret actually, it's much worse
bash doesn't do floating point at all. I didn't know until today
the bad thing here is that it fails silently without a warning or error
@aesthr @ferret it's quite difficult to get bash to do arithmetic inside [[ ]]; i had to resort to $(( ))
$ (set -x; [[ 0.1 + 0.2 == 42 ]]; echo $?)
bash: unexpected token `+', conditional binary operator expected
bash: syntax error near `+'
$ (set -x; [[ (0.1 + 0.2) == 42 ]]; echo $?)
bash: unexpected token `+', conditional binary operator expected
bash: expected `)'
bash: syntax error near `+'
(cont'd...)
$ (set -x; [[ ( 0.1 + 0.2 ) == 42 ]]; echo $?)
bash: unexpected token `+', conditional binary operator expected
bash: expected `)'
bash: syntax error near `+'
but finally
$ (set -x; [[ $(( 0.1 + 0.2 )) == 42 ]]; echo $?)
bash: 0.1 + 0.2 : arithmetic syntax error: invalid arithmetic operator (error token is ".1 + 0.2 ")
and
$ (set -x; [[ $(( 1 + 2 )) == 42 ]]; echo $?)
+ [[ 3 == 42 ]]
+ echo 1
1
(but that last [[ 3 == 42 ]] is still a string comparison!)
@ferret it still fails silently even with `set -e` in place. awesome
And if you're a programmer and just learning about this now ... I'm so sorry, but someone had to tell you the truth eventually.