Permalink
Browse files

[fix] stdlib,json: make something usefull with anormal float serialis…

…ation

the serialisation ton json doesn't use this possibility
until client unserialisation is updated to cope with this evolution
  • Loading branch information...
1 parent b0fead4 commit cf934acb5afb5cc0b19ae6a76caccc354e3665cc @OpaOnWindowsNow OpaOnWindowsNow committed Apr 3, 2012
Showing with 17 additions and 14 deletions.
  1. +8 −5 stdlib/core/rpc/core/json.opa
  2. +9 −9 stdlib/core/rpc/core/opaserialize.opa
@@ -1,5 +1,5 @@
/*
- Copyright © 2011 MLstate
+ Copyright © 2011, 2012 MLstate
This file is part of OPA.
@@ -162,8 +162,11 @@ type ll_json_record_repr = external
serialize_to_js(j/*: json*/) =
Text.to_string(to_text_in_js(j))
-
-
+ serialize_float(f) =
+ // WHAT ABOUT PRINTING PRECISIONS
+ if Math.is_normal(f) then Float.to_string(f)
+ else if Math.is_NaN(f) then "NaN"
+ else if f<0.0 then "-Infinity" else "Infinity"
/**
* {1 Private stuff}
@@ -261,7 +264,7 @@ type ll_json_record_repr = external
rec aux(j:RPC.Json.json, tx, n) =
match j with
| {~Int} -> (tx ++ "{Int}", [])
- | {~Float} -> (tx ++ "{Float}", [])
+ | {~Float} -> (tx ++ serialize_float(Float), [])
| {~String} -> (for_string(tx, String), [])
| {~Bool} -> (tx ++ "{Bool}", [])
| {~Record} ->
@@ -338,7 +341,7 @@ type ll_json_record_repr = external
rec aux(j : RPC.Json.js_code, tx : text, n, nid) =
match j with
| {~Int} -> (tx ++ "{Int}", [], nid)
- | {~Float} -> (tx ++ "{Float}", [], nid)
+ | {~Float} -> (tx ++ serialize_float(Float), [], nid)
| {~String} -> (for_string(tx, String), [], nid)
| {~Bool} -> (tx ++ "{Bool}", [], nid)
| {~Direct} -> (tx ++ Direct, [], nid)
@@ -1,5 +1,5 @@
/*
- Copyright © 2011 MLstate
+ Copyright © 2011, 2012 MLstate
This file is part of OPA.
@@ -375,14 +375,14 @@ OpaSerializeClosure = {{
else {Int = integer}
| {TyConst = {TyString}} -> {String = Magic.id(value)}
- | {TyConst = {TyFloat}}
- ->
- fvalue = Magic.id(value) : float
- if Math.is_normal(fvalue) then {Float=fvalue}
- else
- anormal = if Math.is_NaN(fvalue) then "NaN"
- else if fvalue<0.0 then "-Infinity" else "Infinity"
- aux(Magic.id(anormal),{TyConst = {TyString}})
+ | {TyConst = {TyFloat}} ->
+ // JSON does not handle limits float on all browsers
+ // remove the anormal handler when our client side implem is ok
+ fvalue = Magic.id(value) : float
+ if Math.is_normal(fvalue) then {Float=fvalue}
+ else
+ anormal = @toplevel.Json.serialize_float(fvalue)
+ aux(Magic.id(anormal),{TyConst = {TyString}})
/* Record case ****************************/
| {TyRecord_row = row}

0 comments on commit cf934ac

Please sign in to comment.