andrenth / ocaml-stdint Goto Github PK
View Code? Open in Web Editor NEWVarious signed and unsigned integers for OCaml
License: Other
Various signed and unsigned integers for OCaml
License: Other
To improve performance and memory usage, store small integers in OCaml int
. Use the trick from the irregular sized integers and left-align the value in the int
so add
/mul
/sub
work with standard integer functions. We can do that for 8/16/24 bit integers on 32 bit platforms and up to 56 bit integers on 64 bit platforms.
This way the small integers would bear no performance penalty relative to OCaml int
.
With the current API, one can store all flavor of ints inside regular OCaml arrays, but this means that one loose a lot of bits when using, e.g., arrays of uint16, and I imagine that {u,}int128 are boxed.
Do you have plans to support more compact structures, in a bigarray like fashion?
Bug in uint32_of_uint{8,16} it seems. I'm on it.
There is no equal
method for integers in this library. There is only compare
. Is polymorphic equality (=
) supposed to be used?
let buf = Bytes.make 8 '\x00' in
Int8.to_bytes_big_endian (Int8.of_int ~-1) buf 0
(* Exception: Invalid_argument "Char.chr" *)
Is there any chance you were planning on adding support for s-expressions (and in particular https://github.com/janestreet/ppx_sexp_conv)? This would allow using this library with Jane Steet's "core".
# Int40.(mul (of_int ~-1) (of_int 42)) |> Int40.to_string;;
- : string = "42"
There are a few other bugs around this. I added some test cases and am going to debug this.
In README.md
, I see
The API of stdint can be found online at the OCaml forge.
But I can't really find API documentation from these links.
With my colleague @msprotz, we observed segfaults related to 128-bit integers in some Windows OCaml programs using ocaml-stdint.
It turns out that even the test executable produced by make test/stdint_test
segfaults, with no test running, as we show below.
We are working on Windows 10 version 1909 (10.0.18363.720) with Cygwin 3.1.4-1, mingw64-x86_64-gcc 9.2.0, and OCaml 4.09.0 installed via OCaml and OPaM for Windows. If you want to quickly reproduce our config, you can pull a complete Docker image pulling the latest ocaml-stdint master
(0785788) and building ocaml-stdint and its test suite. You can also rebuild the Docker image yourself using this Dockerfile.txt.
Then, below is what we are observing:
ContainerAdministrator@cff3016f7f7e /cygdrive/c/test/ocaml-stdint
$ gdb tests/stdint_test.exe
GNU gdb (GDB) (Cygwin 8.2.1-1) 8.2.1
(gdb) run
Starting program: /cygdrive/c/test/ocaml-stdint/tests/stdint_test.exe
[New Thread 5000.0x33c4]
[New Thread 5000.0x32b0]
[New Thread 5000.0x5110]
[New Thread 5000.0x5710]
Thread 1 received signal SIGSEGV, Segmentation fault.
copy_uint128 (i=<optimized out>) at uint128_stubs.c:188
188 Uint128_val(res) = i;
(gdb) backtrace
#0 copy_uint128 (i=<optimized out>) at uint128_stubs.c:188
#1 0x0000000000494e65 in uint128_of_int (v=<optimized out>) at uint128_conv.c:34
#2 0x000000000042f2e6 in camlStdint__entry ()
#3 0x0000000000000001 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
As a workaround, my colleague @msprotz proposed to recompile ocaml-stdint with gcc optimizations disabled, which we did in tahina-pro/ocaml-stdint@99ac1fa, and there we no longer observe these segfaults.
It would be nice to have a ppx extension which would provide a way to use literals. It is clumsy to write things like Int32.of_string "0xffffffff"
Removing with opam remove stdint
leaves artefacts inside ~/.opam
.
So it's not possible to downgrade easily.
Attaching the simple test project and Dockerfile with Alpine 3.15 for easy reproducer.
STEP 16/16: RUN eval "$(opam env)" && dune build
ocamlopt test.exe (exit 2)
(cd _build/default && /home/test/.opam/4.13.1+musl+static+flambda/bin/ocamlopt.opt -w @[email protected]@30..39@[email protected]@[email protected] -strict-sequence -strict-formats -short-paths -keep-locs -g -o test.exe /home/test/.opam/4.13.1+musl+static+flambda/lib/base/base_internalhash_types/base_internalhash_types.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/base/base_internalhash_types /home/test/.opam/4.13.1+musl+static+flambda/lib/base/caml/caml.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/sexplib0/sexplib0.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/base/shadow_stdlib/shadow_stdlib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/base/base.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/base /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_sexp_conv/runtime-lib/ppx_sexp_conv_lib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_here/runtime-lib/ppx_here_lib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_inline_test/config/inline_test_config.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/jane-street-headers/jane_street_headers.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_compare/runtime-lib/ppx_compare_lib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_enumerate/runtime-lib/ppx_enumerate_lib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_hash/runtime-lib/ppx_hash_lib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/time_now/time_now.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/time_now /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_inline_test/runtime-lib/ppx_inline_test_lib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_bench/runtime-lib/ppx_bench_lib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_assert/runtime-lib/ppx_assert_lib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/splittable_random/splittable_random.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/fieldslib/fieldslib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/base_quickcheck/base_quickcheck.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/base/md5/md5_lib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml/unix.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml /home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml/bigarray.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml /home/test/.opam/4.13.1+musl+static+flambda/lib/variantslib/variantslib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/bin_prot/shape/bin_shape_lib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/bin_prot/bin_prot.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/bin_prot /home/test/.opam/4.13.1+musl+static+flambda/lib/stdio/stdio.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_module_timer/runtime/ppx_module_timer_runtime.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/typerep/typerep_lib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_expect/common/expect_test_common.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_expect/config_types/expect_test_config_types.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_expect/collector/expect_test_collector.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_expect/collector /home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_expect/config/expect_test_config.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/base_bigstring/base_bigstring.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/base_bigstring /home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/base_for_tests/base_for_tests.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/parsexp/parsexp.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/sexplib/sexplib.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/core_kernel.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel /home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml/threads/threads.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml /home/test/.opam/4.13.1+musl+static+flambda/lib/core/error_checking_mutex/error_checking_mutex.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/core/error_checking_mutex /home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/caml_unix/caml_unix.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/flags/flags.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/version_util/version_util.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/version_util /home/test/.opam/4.13.1+musl+static+flambda/lib/sexplib/unix/sexplib_unix.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/spawn/spawn.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/spawn /home/test/.opam/4.13.1+musl+static+flambda/lib/timezone/timezone.cmxa /home/test/.opam/4.13.1+musl+static+flambda/lib/core/core.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/core /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/stdint.cmxa -I /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint .test.eobjs/native/dune__exe__Test.cmx -verbose -linkall)
+ as -o '/tmp/build324dc5.dune/camlstartupd557ab.o' '/tmp/build324dc5.dune/camlstartupc5f397.s'
+ gcc -O2 -fno-strict-aliasing -fwrapv -pthread -Wall -Wdeclaration-after-statement -fno-common -fexcess-precision=standard -fno-tree-vrp -ffunction-sections -Os -Wl,-E -o 'test.exe' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/base/base_internalhash_types' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/base' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/time_now' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/bin_prot' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_expect/collector' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/base_bigstring' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/core/error_checking_mutex' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/version_util' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/spawn' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/core' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/stdint' '-L/home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml' '/tmp/build324dc5.dune/camlstartupd557ab.o' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml/std_exit.o' '.test.eobjs/native/dune__exe__Test.o' '/home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/stdint.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/core/core.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/timezone/timezone.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/spawn/spawn.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/sexplib/unix/sexplib_unix.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/version_util/version_util.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/flags/flags.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/caml_unix/caml_unix.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/core/error_checking_mutex/error_checking_mutex.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml/threads/threads.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/core_kernel.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/sexplib/sexplib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/parsexp/parsexp.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/core_kernel/base_for_tests/base_for_tests.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/base_bigstring/base_bigstring.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_expect/config/expect_test_config.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_expect/collector/expect_test_collector.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_expect/config_types/expect_test_config_types.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_expect/common/expect_test_common.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/typerep/typerep_lib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_module_timer/runtime/ppx_module_timer_runtime.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/stdio/stdio.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/bin_prot/bin_prot.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/bin_prot/shape/bin_shape_lib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/variantslib/variantslib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml/bigarray.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml/unix.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/base/md5/md5_lib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/base_quickcheck/base_quickcheck.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/fieldslib/fieldslib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/splittable_random/splittable_random.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_assert/runtime-lib/ppx_assert_lib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_bench/runtime-lib/ppx_bench_lib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_inline_test/runtime-lib/ppx_inline_test_lib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/time_now/time_now.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_hash/runtime-lib/ppx_hash_lib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_enumerate/runtime-lib/ppx_enumerate_lib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_compare/runtime-lib/ppx_compare_lib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/jane-street-headers/jane_street_headers.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_inline_test/config/inline_test_config.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_here/runtime-lib/ppx_here_lib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ppx_sexp_conv/runtime-lib/ppx_sexp_conv_lib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/base/base.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/base/shadow_stdlib/shadow_stdlib.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/sexplib0/sexplib0.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/base/caml/caml.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/base/base_internalhash_types/base_internalhash_types.a' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml/stdlib.a' '-lstdint_stubs' '-lcore_stubs' '-lspawn_stubs' '-lversion_util_stubs' '-lerror_checking_mutex_stubs' '-lthreadsnat' '-lpthread' '-lcore_kernel_stubs' '-lrt' '-lbase_bigstring_stubs' '-lexpect_test_collector_stubs' '-lbin_prot_stubs' '-lunix' '-ltime_now_stubs' '-lbase_stubs' '-lbase_internalhash_types_stubs' '/home/test/.opam/4.13.1+musl+static+flambda/lib/ocaml/libasmrun.a' -lm
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(float_conv.o): in function `float_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/float_conv.c:90: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(float_conv.o): in function `float_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/float_conv.c:158: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int128_conv.o): in function `int128_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int128_conv.c:262: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int128_stubs.o): in function `int128_cmp':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int128_stubs.c:69: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int128_stubs.c:70: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int128_stubs.o): in function `int128_hash':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int128_stubs.c:84: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int128_stubs.o): in function `int128_serialize':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int128_stubs.c:103: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int128_stubs.o): in function `int128_div':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int128_stubs.c:195: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int128_stubs.o):/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int128_stubs.c:199: more undefined references to `get_int128' follow
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int16_conv.o): in function `int16_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int16_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int24_conv.o): in function `int24_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int24_conv.c:104: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int24_conv.o): in function `int24_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int24_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int32_conv.o): in function `int32_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int32_conv.c:104: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int32_conv.o): in function `int32_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int32_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int40_conv.o): in function `int40_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int40_conv.c:104: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int40_conv.o): in function `int40_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int40_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int48_conv.o): in function `int48_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int48_conv.c:104: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int48_conv.o): in function `int48_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int48_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int56_conv.o): in function `int56_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int56_conv.c:104: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int56_conv.o): in function `int56_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int56_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int64_conv.o): in function `int64_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int64_conv.c:104: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int64_conv.o): in function `int64_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int64_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int8_conv.o): in function `int8_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int8_conv.c:106: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int8_conv.o): in function `int8_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int8_conv.c:174: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int_conv.o): in function `int_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int_conv.c:90: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(int_conv.o): in function `int_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/int_conv.c:158: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(nativeint_conv.o): in function `nativeint_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/nativeint_conv.c:90: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(nativeint_conv.o): in function `nativeint_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/nativeint_conv.c:158: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint128_conv.o): in function `uint128_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint128_conv.c:166: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint128_stubs.o): in function `uint128_cmp':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint128_stubs.c:111: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint128_stubs.c:112: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint128_stubs.o): in function `uint128_hash':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint128_stubs.c:126: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint128_stubs.o): in function `uint128_serialize':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint128_stubs.c:145: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint128_stubs.o): in function `suint128_add':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint128_stubs.c:219: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint128_stubs.o):/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint128_stubs.c:219: more undefined references to `get_uint128' follow
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint16_conv.o): in function `uint16_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint16_conv.c:111: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint16_conv.o): in function `uint16_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint16_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint24_conv.o): in function `uint24_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint24_conv.c:111: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint24_conv.o): in function `uint24_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint24_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint32_conv.o): in function `uint32_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint32_conv.c:111: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint32_conv.o): in function `uint32_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint32_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint40_conv.o): in function `uint40_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint40_conv.c:111: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint40_conv.o): in function `uint40_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint40_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint48_conv.o): in function `uint48_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint48_conv.c:111: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint48_conv.o): in function `uint48_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint48_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint56_conv.o): in function `uint56_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint56_conv.c:111: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint56_conv.o): in function `uint56_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint56_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint64_conv.o): in function `uint64_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint64_conv.c:111: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint64_conv.o): in function `uint64_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint64_conv.c:172: undefined reference to `get_uint128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint8_conv.o): in function `uint8_of_int128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint8_conv.c:111: undefined reference to `get_int128'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /home/test/.opam/4.13.1+musl+static+flambda/lib/stdint/libstdint_stubs.a(uint8_conv.o): in function `uint8_of_uint128':
/home/test/.opam/4.13.1+musl+static+flambda/.opam-switch/build/stdint.0.7.0/_build/default/lib/uint8_conv.c:172: undefined reference to `get_uint128'
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking (exit code 1)
Error: error building at STEP "RUN eval "$(opam env)" && dune build": error while running runtime: exit status 1
__int128 is generally only available in 64 bit platforms; we need a solution for 32 bit machines
I currently have the following data type:
open Stdint
type fixed_int =
| U8 of Uint8.t
| U16 of Uint16.t
| U32 of Uint32.t
| U64 of Uint64.t
[@@deriving eq, show]
@@deriving
panics because there is no equal
and show
methods for those integer types. I expect the above code to just compile.
I can't find how to run the tests since the build system is jbuilder.
Could this be documented in the README maybe?
Note: I suspect the comparison function is wrong for large int128 and would like to fix it
# Int32.of_substring "0 " ~pos:0;;
Exception: Invalid_argument "int32.of_substring".
Raised at file "stdlib.ml", line 34, characters 25-45
Called from file "lib/str_conv.ml", line 60, characters 17-24
Called from file "lib/str_conv.ml", line 103, characters 6-41
Called from file "toplevel/toploop.ml", line 180, characters 17-56
I'm on it, also improving tests
On a 64bit OCaml 4.02.3, latest stdint from opam:
(* Testing in the toplevel *)
# Stdint.Uint32.to_int @@ Stdint.Uint32.of_int 0xFFFFFFFF;;
- : int = -1
but I would have expected 4294967295
.
The conversion to Int64.t
does work properly:
# Stdint.Uint32.to_int64 @@ Stdint.Uint32.of_int 0xFFFFFFFF;;
- : int64 = 4294967295L
utop # Uint128.of_int 1152921504606846976 |> Uint128.to_int;;
- : int = 0
Reading the "Numeric conversion functions" of the lib, it's not clear to me whether the functions there will raise if one tries to convert, e.g., an int32 into an int24, or if it will truncate/mask the value.
It could make sense to improve the doc to make this really clear.
When I opam remove stdint on master, I got:
[WARNING] Directory yadayada/lib/stdint is not empty, not removing
And indeed this directory still have those files:
total 196
-rw-r--r-- 1 rixed 8691 Feb 22 04:58 bytes_conv.cmx
-rw-r--r-- 1 rixed 808 Feb 22 04:58 infix.cmx
-rw-r--r-- 1 rixed 30790 Feb 22 04:58 int_wrapper.cmx
-rw-r--r-- 1 rixed 78324 Feb 22 04:58 stdint.annot
-rw-r--r-- 1 rixed 20329 Feb 22 04:58 str_conv.cmx
Note: there is no more a remove
command in stdint.opam, is that on purpose?
test.ml:
open Stdint
let () =
let i = Int128.of_string Sys.argv.(1) in
let f = Int128.to_float i in
Printf.printf "%g\n" f
Makefile:
all: test.opt
test.opt: test.ml
ocamlfind ocamlopt -linkpkg -package stdint $< -o $@
clean:
$(RM) *.cmx *.cmi *.o
output of make
with stdint as of 55d6773, on MacOS:
ocamlfind ocamlopt -linkpkg -package stdint test.ml -o test.opt
Undefined symbols for architecture x86_64:
"_float_of_int128", referenced from:
_camlTest__entry in test.o
_camlStdint__anon$2dfn$5blib$2fstdint$2eml$3a719$2c4$2d$2d70$5d_7722 in stdint.a(stdint.o)
_camlStdint__Pmakeblock_39245 in stdint.a(stdint.o)
"_float_of_int16", referenced from:
_camlStdint__anon$2dfn$5blib$2fstdint$2eml$3a209$2c2$2d$2d67$5d_5035 in stdint.a(stdint.o)
_camlStdint__Pmakeblock_39245 in stdint.a(stdint.o)
"_float_of_int24", referenced from:
_camlStdint__anon$2dfn$5blib$2fstdint$2eml$3a272$2c2$2d$2d67$5d_5356 in stdint.a(stdint.o)
_camlStdint__Pmakeblock_39245 in stdint.a(stdint.o)
"_float_of_int40", referenced from:
_camlStdint__anon$2dfn$5blib$2fstdint$2eml$3a464$2c4$2d$2d69$5d_6142 in stdint.a(stdint.o)
_camlStdint__Pmakeblock_39245 in stdint.a(stdint.o)
"_float_of_int48", referenced from:
_camlStdint__anon$2dfn$5blib$2fstdint$2eml$3a548$2c4$2d$2d69$5d_6536 in stdint.a(stdint.o)
_camlStdint__Pmakeblock_39245 in stdint.a(stdint.o)
"_float_of_int56", referenced from:
_camlStdint__anon$2dfn$5blib$2fstdint$2eml$3a632$2c4$2d$2d69$5d_6930 in stdint.a(stdint.o)
_camlStdint__Pmakeblock_39245 in stdint.a(stdint.o)
...
"_nativeint_of_uint8", referenced from:
_camlStdint__anon$2dfn$5blib$2fstdint$2eml$3a797$2c2$2d$2d71$5d_8053 in stdint.a(stdint.o)
_camlStdint__Pmakeblock_39245 in stdint.a(stdint.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "caml_startup", line 1:
Error: Error during linking
make: *** [Makefile:4: test.opt] Error 2
On Linux:
ocamlfind ocamlopt -linkpkg -package stdint test.ml -o test.opt
test.o: In function `camlTest__entry':
:(.text+0x45): undefined reference to `float_of_int128'
/home/rixed/.opam/ramen/lib/stdint/stdint.a(stdint.o): In function `camlStdint__anon$2dfn$5blib$2fstdint$2eml$3a145$2c2$2d$2d70$5d_4724':
/home/rixed/.opam/ramen/build/stdint.0.5.0fix1/_build/default/lib/stdint.ml:145: undefined reference to `nativeint_of_int8'
/home/rixed/.opam/ramen/lib/stdint/stdint.a(stdint.o): In function `camlStdint__anon$2dfn$5blib$2fstdint$2eml$3a146$2c2$2d$2d66$5d_4714':
/home/rixed/.opam/ramen/build/stdint.0.5.0fix1/_build/default/lib/stdint.ml:146: undefined reference to `float_of_int8'
...
/home/rixed/.opam/ramen/build/stdint.0.5.0fix1/_build/default/lib/stdint.ml:1424: undefined reference to `float_of_uint128'
/home/rixed/.opam/ramen/lib/stdint/stdint.a(stdint.o): In function `camlStdint__Pmakeblock_39245':
:(.data+0xefd8): undefined reference to `float_of_int8'
:(.data+0xefe0): undefined reference to `nativeint_of_int8'
:(.data+0xf118): undefined reference to `float_of_int16'
:(.data+0xf120): undefined reference to `nativeint_of_int16'
:(.data+0xf248): undefined reference to `float_of_int24'
...
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking
Makefile:4: recipe for target 'test.opt' failed
make: *** [test.opt] Error 2
Same program compiles all right with 0.5.0
I am not sure if it's me not using the Infix syntax correctly but I keep getting a Error: This expression has type Stdint.uint64 but an expression was expected of type int
.
Here is a minimal reproducer of the error:
let e = Uint64.of_int 123268723;;
Uint64.(e mod e);;
If I instead use Uint64.(e * e)
are any other infix operator, I get the expected result. Is there any other way I can reliably use mod
between 2 Uint64
or Uint128
ints?
Note that this above example works just fine when using the integers
library:
#require "integers";;
open Unsigned;;
UInt64.Infix.(UInt64.of_int 124334312 mod UInt64.of_int 123231212);;
I'm trying to build version 0.7.0 for Fedora. I'm seeing multiple test failures building on an x86_64 Fedora Rawhide machine, with OCaml 4.11.1 and gcc 10.2.1.
In tests/stdint_test.ml
, pos_int
can return a value outside of the allowed range. For example, with Int8
, in_range
picks a value between -128 and 127. Let's say it picks -128. Then pos_int
takes the absolute value, which is 128, and returns that. This causes some test failures because the OCaml integer version works with the value 128, but the Int8
version works with 128 converted to an Int8
, which is -127. Shouldn't pos_int
pick from the range 0 to maxi
instead?
Other test failures are caused by the definition of lognot
in lib/stdint.ml
. In modules Int40
, Int48
, Int56
, and Int128
, lognot
is defined as logxor max_int
. But that leaves the sign bit unchanged. It should do the XOR operation with -1 instead. Here's the output from a little code I wrote. For each type T, the number on the left of the comma is the result of Stdint.T.to_string (Stdint.T.lognot (Stdint.T.of_int 0))
, and the number on the right of the comma is the result of Stdint.T.to_string (Stdint.T.of_int (lnot 0))
. They should be the same.
Int8: -1, -1
Int16: -1, -1
Int24: -1, -1
Int32: -1, -1
Int40: 549755813887, -1
Int48: 140737488355327, -1
Int56: 36028797018963967, -1
Int64: -1, -1
Int128: 170141183460469231731687303715884105727, -1
Uint8: 255, 255
Uint16: 65535, 65535
Uint24: 16777215, 16777215
Uint32: 4294967295, 4294967295
Uint40: 1099511627775, 1099511627775
Uint48: 281474976710655, 281474976710655
Uint56: 72057594037927935, 72057594037927935
Uint64: 18446744073709551615, 18446744073709551615
Uint128: 340282366920938463463374607431768211455, 340282366920938463463374607431768211455
I'm getting other test failures that I haven't diagnosed yet:
== Testing Int64 ==
test `An integer should perform left-shifts correctly` failed on ≥ 1 cases:
(70368744177664, 16) (after 45 shrink steps)
== Testing Int128 ==
test `An integer should perform left-shifts correctly` failed on ≥ 1 cases:
(70368744177664, 16) (after 37 shrink steps)
test `Logical shifts must not sign-extend` failed on ≥ 1 cases:
0 (after 9 shrink steps)
== Testing Uint64 ==
test `An integer should perform left-shifts correctly` failed on ≥ 1 cases:
(70368744177664, 16) (after 38 shrink steps)
== Testing Uint128 ==
test `An integer should perform left-shifts correctly` failed on ≥ 1 cases:
(70368744177664, 16) (after 37 shrink steps)
Dear Stdint Team,
when I build/install stdint with opam (on cygwin), the file dllstdint_stubs.so is not copied to ~/.opam/system/lib/stublibs, which is the standard opam folder for such files. As a result the .so file is not found when starting executables, unless I copy the file there or add ~/.opam/system/lib/stdint to the load path.
Best regards,
Michael
int24_of_* on 64 bits arch because the shift is then wrong, and uint24_of_* because the extranuous shift.
stdint v0.3 installs header files to both of {libdir}
and {prefix}/include/ocaml_stdint
, and some packages dependent to stdint assume that the headers are installed into {libdir}
, e.g.,
However recently released v0.4.0 and v0.4.1 only copy the headers to the latter directory, not {libdir}
. zmq (and similar packages) cannot be built since the headers are not found:
#=== ERROR while installing zmq.4.0-8 =========================================#
# opam-version 1.2.2
# os linux
# command ocaml setup.ml -build
# path /home/travis/.opam/4.04.2/build/zmq.4.0-8
# compiler 4.04.2
# exit-code 1
# env-file /home/travis/.opam/4.04.2/build/zmq.4.0-8/zmq-4391-a02972.env
# stdout-file /home/travis/.opam/4.04.2/build/zmq.4.0-8/zmq-4391-a02972.out
# stderr-file /home/travis/.opam/4.04.2/build/zmq.4.0-8/zmq-4391-a02972.err
### stdout ###
# [...]
# Warning: the tag "oasis_executable_threadedloopback_native" is not used in any flag or dependency declaration, so it will have no effect; it may be a typo. Otherwise you can use `mark_tag_used` in your myocamlbuild.ml to disable this warning.
# File "_tags", line 126, characters 23-63:
# Warning: the tag "oasis_executable_threadedloopback_native" is not used in any flag or dependency declaration, so it will have no effect; it may be a typo. Otherwise you can use `mark_tag_used` in your myocamlbuild.ml to disable this warning.
# /home/travis/.opam/4.04.2/bin/ocamlfind ocamlc -g -ccopt -I/usr/local/include -ccopt -I. -ccopt -I -ccopt /home/travis/.opam/4.04.2/lib/stdint -ccopt -Wall -ccopt -Wextra -ccopt -O2 -c src/caml_zmq_stubs.c
# + /home/travis/.opam/4.04.2/bin/ocamlfind ocamlc -g -ccopt -I/usr/local/include -ccopt -I. -ccopt -I -ccopt /home/travis/.opam/4.04.2/lib/stdint -ccopt -Wall -ccopt -Wextra -ccopt -O2 -c src/caml_zmq_stubs.c
# src/caml_zmq_stubs.c:37:20: fatal error: uint64.h: No such file or directory
# #include <uint64.h>
# ^
# compilation terminated.
# Command exited with code 2.
### stderr ###
# E: Failure("Command ''/home/travis/.opam/4.04.2/bin/ocamlbuild' src/libZMQ_stubs.a src/dllZMQ_stubs.so src/ZMQ.cma src/ZMQ.cmxa src/ZMQ.a src/ZMQ.cmxs examples/hwserver.native examples/hwclient.native examples/wuserver.native examples/wuclient.native examples/wuproxy.native examples/taskvent.native examples/taskwork.native examples/tasksink.native -tag debug' terminated with error code 10")
Could you copy the headers to {libdir}
for backward compatibility?
Line 696 in e3cc931
Test case:
Int128.(compare (shift_right_logical (of_int (-1)) 1) zero);;
(* actual: -1 *)
(* expected: 1 *)
Actual behavior
Here is a toplevel session:
μ> #require "stdint";;
μ> "-1" |> Stdint.Uint128.of_string |> Stdint.Uint128.to_string;;
- : string = "340282366920938463463374607431768211455"
Basically, this is the maximum 128-bit unsigned integer. It behaves the same for the rest of bit widths.
Expected behavior
Raises an exception according to the description here:
Lines 292 to 297 in 48f97cd
ocamlfind ocamlopt -linkpkg -package stdint foo.ml -o foo.exe
/usr/bin/ld: src/libbar.a(bar.o): in function `baz':
bar.c:123: undefined reference to `get_uint128'
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking
Ok those are not in Int32 not Int64 stdlib modules, but still that would be nice, wouldn't it?
It would be nice if stdint
had a fall-back on pure OCaml code for targets that don't support C bindings, e.g. Js_of_ocaml.
I just open-sourced my pure OCaml integer implementation, which might be helpful for that:
Using the latest 0.6.0:
# #require "stdint";;
# open Stdint;;
# let v = Uint24.of_int 15134052;;
val v : Stdint.Uint24.t = 15134052
# let v' = Uint24.to_uint32 v;;
val v' : Stdint.uint32 = <abstr>
# Uint32.to_int v';;
- : int = 30268105
# Uint32.(to_int (shift_right v' 1));;
- : int = 15134052
(Sorry, I accidentally hit enter)
I'd like to propose some API for things like getting the most/least significant bit index, along with getting the number of set bits in an int.
My main purpose here is to explore how well OCaml works for bitboards, which represent a chessboard as a 64-bit int, with each bit representing the presence/absence of a piece.
This requires a large amount of bit twiddling, for example to serialise given bitboards into moves.
Extracting the MSB/LSB can be done in OCaml purely through your library, but it would benefit heavily from the hardware acceleration of C compiler intrinsics that OCaml doesn't provide.
__uint128 is generally only available in 64 bit platforms; we need a solution for 32 bit machines
Exemple:
# Uint32.(of_int (-5) |> to_int24) |> Int24.to_int;;
- : int = 0
Whereas replacing Int24 above by any other int narrower than 32 bits properly yield -5, as expected.
I'm currently working on a fix, and on reviving the tests.
All [u,]intXX.h
files should use extern "C" { ... }
to allow linking with a C++ binding. I ran into this issue and worked it around by doing extern "C" { #include <uint64.h> }
But it would be nicer to put this directly in aforementioned files.
The following assertion fails:
open Stdint
assert (Int8.of_string "127" = Int8.max_int);
Of course, I expect it not to fail.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.