Skip to content

Commit

Permalink
[ primitive ] fixed compilation of float primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
UlfNorell committed Oct 27, 2015
1 parent 6157e88 commit f9b005f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/data/uhc-agda-base/src/UHC/Agda/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,17 @@ primToLower = C.toLower
-- ====================
primShowFloat :: Double -> String
-- GHC drops trailing zeroes, UHC doesn't seem to do so. Quick fix for now...
primShowFloat = reverse . dropWhile (=='0') . reverse . show
primShowFloat x
| isNegativeZero x = "0.0"
| otherwise = reverse . dropWhile (=='0') . reverse $ show x

primMkFloat :: String -> Double
primMkFloat = read

primFloatEquality :: Double -> Double -> Bool
primFloatEquality = (==)
primFloatEquality x y
| isNaN x && isNaN y = True
| otherwise = x == y

-- ====================
-- Reflection
Expand Down
17 changes: 11 additions & 6 deletions src/full/Agda/Compiler/MAlonzo/Primitives.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,26 @@ primBody s = maybe unimplemented (either (hsVarUQ . HS.Ident) id <$>) $
, "primNatLess" |-> relNat "(<)"

-- Floating point functions
, "primIntegerToFloat" |-> return "(fromIntegral :: Integer -> Double)"
, "primNatToFloat" |-> return "(fromIntegral :: Integer -> Double)"
, "primFloatPlus" |-> return "((+) :: Double -> Double -> Double)"
, "primFloatMinus" |-> return "((-) :: Double -> Double -> Double)"
, "primFloatTimes" |-> return "((*) :: Double -> Double -> Double)"
, "primFloatDiv" |-> return "((/) :: Double -> Double -> Double)"
, "primFloatEquality" |-> rel "(==)" "Double"
, "primFloatLess" |-> rel "(<)" "Double"
, "primFloatEquality" |-> return "((\\ x y -> if isNaN x && isNaN y then True else x == y) :: Double -> Double -> Bool)"
, "primFloatLess" |-> return $ unwords
[ "((\\ x y ->"
, "let isNegInf z = z < 0 && isInfinite z in"
, "if isNegInf y then False else"
, "if isNegInf x then True else"
, "if isNaN x then True else"
, "x < y) :: Double -> Double -> Bool)" ]
, "primRound" |-> return "(round :: Double -> Integer)"
, "primFloor" |-> return "(floor :: Double -> Integer)"
, "primCeiling" |-> return "(ceiling :: Double -> Integer)"
, "primExp" |-> return "(exp :: Double -> Double)"
, "primLog" |-> return "(log :: Double -> Double)" -- partial
, "primLog" |-> return "(log :: Double -> Double)"
, "primSin" |-> return "(sin :: Double -> Double)"
, "primShowFloat" |-> return "(show :: Double -> String)"
, "primRound" |-> return "(round :: Double -> Integer)"
, "primShowFloat" |-> return "((\\ x -> if isNegativeZero then \"0.0\" else show x) :: Double -> String)"

-- Character functions
, "primCharEquality" |-> rel "(==)" "Char"
Expand Down

0 comments on commit f9b005f

Please sign in to comment.