Skip to content

Big integers are truncated #285

Closed
Closed
@ztlpn

Description

@ztlpn

I am having trouble using bin_prot library with js_of_ocaml. The following code:

Printf.printf "Size: %d\n" (Bin_prot.Size.bin_size_int64 (Int64.of_int 0x8000))

when run in the browser produces Size: 9 instead of correct Size: 5. Here is the relevant block of bin_prot source code: https://github.com/janestreet/bin_prot/blob/master/lib/size.ml#L16-L22

js_of_ocaml compiler produces a bunch of warnings:

Warning: integer overflow: integer 0xffffffff truncated to 0xffffffff; the generated code might be incorrect.
Warning: integer overflow: integer 0x80000000 truncated to 0x80000000; the generated code might be incorrect.
Warning: integer overflow: integer 0x100000000 truncated to 0x0; the generated code might be incorrect.
Warning: integer overflow: integer 0x80000000 truncated to 0x80000000; the generated code might be incorrect.
Warning: integer overflow: integer 0x100000000 truncated to 0x0; the generated code might be incorrect.
Warning: integer overflow: integer 0x80000000 truncated to 0x80000000; the generated code might be incorrect.

and in this case the generated code is indeed incorrect. The most obvious solution is to get rid of big integers in the source code but it is in third-party library and thus not easily modifiable. Am I out of luck?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions