stdlib
stdlib copied to clipboard
Failing test when negating zero
When I run gleam test --target erlang, I get a single failed assertion:
1) gleam/float_test.negate_test
Values were not equal
expected: 0.0
got: -0.0
output:
It is this test specifically that fails:
pub fn negate_test() {
// .. other tests
float.negate(0.0)
|> should.equal(0.0)
}
I see no test failures when targeting javascript. I am running this on Windows so I'm thinking this might be an issue with BEAM for Windows?
OS: Windows 10
gleam -V: gleam 1.1.0
What version of otp are you using? I noticed this happens for the latest release 27.0, it is a known breaking change, we'll have to decide how to handle it
› erl --version
Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit:ns]
Oh yeah that's a breaking change introduced by OTP 27.0: https://erlang.org/documentation/doc-15.0-rc1/doc/upcoming_incompatibilities.html#0-0-and-0-0-will-no-longer-be-exactly-equal
@lpil what do you think we should do here?
Let's change it to this:
float.negate(0.0)
|> float.negate
|> should.equal(0.0)
~~Would it be useful to keep consistency and both return -0.0 / -0 on erlang/js by checking if it is 0 and in that case switching the sign in the js impl ) inside a do_negate for this?~~
import gleam/float
import gleam/io
pub fn main() {
0.0 |> float.negate |> io.debug
}
~~... and if not, would it not be useful to make it obvious from otp27 onward in the stlib test suite that the expected value differs between targets?~~