andrenth / ocaml-stdint

Various signed and unsigned integers for OCaml
Other
84 stars 15 forks source link

Fix conversion from any ints to uint24 and int24 #41

Closed rixed closed 4 years ago

rixed commented 4 years ago

int24 was wrong on 64bits arch only, whereas uint24 was wrong for all archs.

NOTICE: this fix assumes that the previous fix re. uint24 is merged already. Otherwise, conversion to uint24 are still bogus (although less so).

Before:

  # Uint24.(of_uint32 (Uint32.of_int 42) |> to_int);;
  - : int = 10752
  # Int24.(of_int32 (Int32.of_int 42) |> to_int);;
  - : int = 10752

After:

  # Uint24.(of_uint32 (Uint32.of_int 42) |> to_int);;
  - : int = 42
  # Uint24.(of_uint32 (Uint32.of_int 42) |> to_int);;
  - : int = 42

Closes #40

(cherry picked from commit 142ce47908c4bbfcbeef748cfa58778510c05338)