motoko
motoko copied to clipboard
interpreter: unexpected floating-point behavior
Output when running floatTests.mo from the base library using the moc interpreter:
nan:0x8_0000_0000_0000 should be 'nan' (positive)
-nan:0x8_0000_0000_0000 should be '-nan' (negative)
-nan:0x8_0000_0000_0000 should be '-nan' (negative)
nan:0x8_0000_0000_0000 should be 'nan' (positive)
nan:0x8_0000_0000_0000 should be 'nan' (positive)
-nan:0x8_0000_0000_0000 should be '-nan' (negative)
copySign/keep positive NaN failed:
copySign/negate positive NaN failed:
copySign/keep negative NaN failed:
copySign/negate negative NaN failed:
copySign/second argument negative NaN failed:
1.2 was expected to be -1.2
copySign/NaN and positive infinity failed:
copySign/NaN and negative infinity failed:
copySign/positive infinity and negative NaN failed:
inf was expected to be -inf
copySign/negative infinity and negative NaN failed:
inf was expected to be -inf
9 tests failed.
test/.vessel/matchers/v1.1.0/src/Suite.mo:93.13-93.26: execution error, assertion failure
Repro command for convenience:
cd motoko-base
$(dfx cache show)/moc -r test/Float.test.mo --package matchers test/.vessel/matchers/v1.1.0/src --package base src
It also appears that Float.format and Float.toText behave differently in the interpreter compared to the replica.
Interpreter:
assert Float.toText(1.2) == "1.2";
assert Float.format(#exp 3, 123.0) == "1.230e+02";
Replica:
assert Float.toText(1.2) == "1.200000";
assert Float.format(#exp 3, 123.0) == "1.230e02";