Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portability issue with float serialization #2

Open
vouillon opened this issue Aug 12, 2012 · 4 comments
Open

Portability issue with float serialization #2

vouillon opened this issue Aug 12, 2012 · 4 comments

Comments

@vouillon
Copy link

Several people have tried to use Yojson, which depends on Biniou, with Js_of_ocaml. However, Biniou uses an unportable hack to serialize floats. In particular, the expression "String.unsafe_get (Obj.magic 1.0) 0" is unconditionnally executed and fails when compiled to Javascript. Maybe the function Int64.of_float could be used instead to access the binary representation of floats?

@mjambon
Copy link
Member

mjambon commented Aug 13, 2012

The reason for this choice was performance, but maybe the gain is not that significant. Some benchmarks are needed.

FYI, I submitted a feature request some time ago without much of a conclusion; feel free to add your insights: http://caml.inria.fr/mantis/view.php?id=5494

@mjambon
Copy link
Member

mjambon commented Aug 15, 2012

I made the following lazification:

let float_endianness = lazy (
  match String.unsafe_get (Obj.magic 1.0) 0 with
      '\x3f' -> `Big
    | '\x00' -> `Little
    | _ -> assert false
)

It's the simplest solution I can think of. I hope it solves the Yojson/Js_of_ocaml problem.

@vouillon
Copy link
Author

vouillon commented Sep 3, 2012

Thanks a lot!

Unfortunately, this is still not quite enough, as there is a piece of code a bit later in the same file (around line 256) that calls read_untagged_float64 and write_untagged_float64 unconditionally to test whether they work properly...

@mjambon
Copy link
Member

mjambon commented Sep 4, 2012

Oops. This one is now fixed (tag v.1.0.5). Hopefully it's the last one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants