Last active
February 12, 2019 11:51
-
-
Save edsko/83d1ac7c41c113660a6e533fbd6c4b09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | Convert 'Double' to fixed precision | |
-- | |
-- For precision 'E1', we have | |
-- | |
-- > 1.000 1.010 1.040 1.049 1.050 1.051 1.090 1.100 | |
-- > floor | 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.1 | |
-- > round | 1.0 1.0 1.0 1.0 1.0(*) 1.1 1.1 1.1 | |
-- > ceiling | 1.0 1.1 1.1 1.1 1.1 1.1 1.1 1.1 | |
-- | |
-- (*): See <https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules> | |
doubleToFixed :: forall a. HasResolution a | |
=> (Double -> Integer) -- ^ Rounding policy | |
-> Double -> Fixed a | |
doubleToFixed r d = MkFixed $ r (d * fromIntegral (resolution (Proxy @a))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment