|
@@ -2037,6 +2037,20 @@ let z_lib =
|
|
|
(* ---------------------------------------------------------------------- *)
|
|
|
(* MACRO LIBRARY *)
|
|
|
|
|
|
+(* convert float value to haxe expression, handling inf/-inf/nan *)
|
|
|
+let haxe_float f p =
|
|
|
+ let one = (Ast.EConst (Ast.Float ("1.0")), p) in
|
|
|
+ let negone = (Ast.EConst (Ast.Float ("-1.0")), p) in
|
|
|
+ let zero = (Ast.EConst (Ast.Float ("0.0")), p) in
|
|
|
+ if (f = infinity) then
|
|
|
+ (Ast.EBinop (Ast.OpDiv, one, zero), p)
|
|
|
+ else if (f = neg_infinity) then
|
|
|
+ (Ast.EBinop (Ast.OpDiv, negone, zero), p)
|
|
|
+ else if (f <> f) then
|
|
|
+ (Ast.EBinop (Ast.OpDiv, zero, zero), p)
|
|
|
+ else
|
|
|
+ (Ast.EConst (Ast.Float (string_of_float f)), p)
|
|
|
+
|
|
|
let macro_lib =
|
|
|
let error() =
|
|
|
raise Builtin_error
|
|
@@ -2058,7 +2072,7 @@ let macro_lib =
|
|
|
| VString s, VAbstract (APos p) ->
|
|
|
raise (Typecore.Fatal_error (s,p))
|
|
|
| _ -> error()
|
|
|
- );
|
|
|
+ );
|
|
|
"warning", Fun2 (fun msg p ->
|
|
|
match msg, p with
|
|
|
| VString s, VAbstract (APos p) ->
|
|
@@ -2152,7 +2166,7 @@ let macro_lib =
|
|
|
| VBool b -> (Ast.EConst (Ast.Ident (if b then "true" else "false")),p)
|
|
|
| VInt i -> (Ast.EConst (Ast.Int (string_of_int i)),p)
|
|
|
| VInt32 i -> (Ast.EConst (Ast.Int (Int32.to_string i)),p)
|
|
|
- | VFloat f -> (Ast.EConst (Ast.Float (string_of_float f)),p)
|
|
|
+ | VFloat f -> haxe_float f p
|
|
|
| VAbstract (APos p) ->
|
|
|
(Ast.EObjectDecl (
|
|
|
("fileName" , (Ast.EConst (Ast.String p.Ast.pfile) , p)) ::
|