Last active
November 30, 2016 16:15
-
-
Save wandernauta/151fca420531e3427bbb to your computer and use it in GitHub Desktop.
Floating-point Haskell type for use in VW diesel engines
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
import VWFloat | |
testResult :: VWFloat | |
testResult = 214.0 | |
limit :: VWFloat | |
limit = 200.0 | |
main = do | |
putStrLn "Emissions within limit?" | |
putStrLn $ show $ testResult < limit |
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
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
module VWFloat (VWFloat) where | |
import System.Environment | |
import System.IO.Unsafe | |
import Data.Maybe | |
defeatDevice :: Bool | |
defeatDevice = isJust $ unsafePerformIO $ lookupEnv "EMISSIONS_TEST" | |
instance Ord VWFloat where | |
compare (VWFloat a) (VWFloat b) = if defeatDevice then LT else (compare a b) | |
newtype VWFloat = VWFloat Float | |
deriving (Eq, Show, Read, Floating, RealFrac, | |
Fractional, Real, Num, RealFloat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Beautiful.