on master help sign in
Int/Float conversion primitives
commit8784b67ff989d36bbaf1f7d8ab0b33dbdd02c80e authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateTue 15 Nov 2011, 22:02 (15 years ago) parentf1c7faf
1 file changed+12
src/Idris/Primitives.hs+12
src/Idris/Primitives.hs+12
@@ -34,6 +34,8 @@ strToInt x = foreign_ tyInt "strToInt" [(x, tyString)]
3434intToStr x = foreign_ tyString "intToStr" [(x, tyInt)]
3535strToFloat x = foreign_ tyFloat "strToFloat" [(x, tyString)]
3636floatToStr x = foreign_ tyString "floatToStr" [(x, tyFloat)]
37+intToFloat x = foreign_ tyFloat "intToFloat" [(x, tyInt)]
38+floatToInt x = foreign_ tyInt "floatToInt" [(x, tyFloat)]
3739
3840floatExp x = foreign_ tyFloat "exp" [(x, tyFloat)]
3941floatLog x = foreign_ tyFloat "log" [(x, tyFloat)]
@@ -87,6 +89,10 @@ primitives =
8789 ([E.name "x"], strToFloat (fun "x")),
8890 Prim (UN ["prim__floatToStr"]) (ty [FlType] StrType) 1 (c_floatToStr)
8991 ([E.name "x"], floatToStr (fun "x")),
92+ Prim (UN ["prim__intToFloat"]) (ty [IType] FlType) 1 (c_intToFloat)
93+ ([E.name "x"], intToFloat (fun "x")),
94+ Prim (UN ["prim__floatToInt"]) (ty [FlType] IType) 1 (c_floatToInt)
95+ ([E.name "x"], floatToInt (fun "x")),
9096 Prim (UN ["prim__floatExp"]) (ty [FlType] FlType) 1 (p_floatExp)
9197 ([E.name "x"], floatExp (fun "x")),
9298 Prim (UN ["prim__floatLog"]) (ty [FlType] FlType) 1 (p_floatLog)
@@ -118,6 +124,12 @@ c_floatToStr _ = Nothing
118124c_strToFloat [VConstant (Str x)] = Just $ VConstant (Fl (read x))
119125c_strToFloat _ = Nothing
120126
127+c_floatToInt [VConstant (Fl x)] = Just $ VConstant (I (truncate x))
128+c_floatToInt _ = Nothing
129+
130+c_intToFloat [VConstant (I x)] = Just $ VConstant (Fl (fromIntegral x))
131+c_intToFloat _ = Nothing
132+
121133p_floatExp [VConstant (Fl x)] = Just $ VConstant (Fl (exp x))
122134p_floatExp _ = Nothing
123135p_floatLog [VConstant (Fl x)] = Just $ VConstant (Fl (log x))