Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function whose argument is an unsigned 32 bit integer

Tags:

ocaml

in ocaml I am trying to write a function which takes as an argument a 32 bit unsigned integer. However I am having problems determining the correct identifier to use in the type declaration of the function. By googling I could only find int32. Thanks

like image 551
artella Avatar asked Aug 29 '12 15:08

artella


2 Answers

Adding to gasche's answer there is a library that provides a module with uint32 type and corresponding operations (including division) - ocaml-uint.

like image 166
ygrek Avatar answered Nov 02 '22 23:11

ygrek


Int32 models signed 32-bit arithmetic. If you're only planning to pass such values around (for example to communicate them to a C API), or use operations that don't depend on signedness, such as add, mul, sub, you can use Int32 just fine. Division and modulo are implemented differently on signed and unsigned numbers, so you shouldn't use those of the Int32 module.

(There was a previous caml-list discussion on this topic.)

like image 45
gasche Avatar answered Nov 03 '22 00:11

gasche