Skip to content

Fix signum implementation #280

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

Merged
merged 12 commits into from
Mar 16, 2022
8 changes: 7 additions & 1 deletion test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Test.Main where

import Prelude
import Data.HeytingAlgebra (ff, tt, implies)
import Data.Ord (abs)
import Data.Ord (abs, signum)
import Test.Data.Generic.Rep (testGenericRep)
import Test.Utils (AlmostEff, assert)

Expand All @@ -15,6 +15,7 @@ main = do
testIntDegree
testRecordInstances
testGenericRep
testSignum

foreign import testNumberShow :: (Number -> String) -> AlmostEff

Expand Down Expand Up @@ -151,3 +152,8 @@ testRecordInstances = do
assert "Record top" $
(top :: { a :: Boolean }).a
== top

testSignum :: AlmostEff
testSignum = do
assert "signum positive zero" $ signum 0.0 == 0.0
assert "signum negative zero" $ signum (-0.0) == (-0.0)
Copy link
Contributor

@hdgarrood hdgarrood Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work unfortunately - positive zero compares equal to negative zero. Maybe try show-ing the result?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the test to

assert ("signum negative zero: " <> show (signum (-0.0))) $ show (signum (-0.0)) == "-0.0"

produces this error:

Error: signum negative zero: 0.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And assert (show (-0.0)) $ false produces Error: 0.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Object.is is a way to verify this.