Jon Harrop a écrit :
I'm just trying to write efficient functions for div and mod by three. I'd
like to handle 32- and 64-bit machines with the same code so I tried:
let gcd3 = match Sys.word_size with
| 32 - 715827883
| 64 - 3074457345618258603
| _ - failwith Unknown word
I'm just trying to write efficient functions for div and mod by three. I'd
like to handle 32- and 64-bit machines with the same code so I tried:
let gcd3 = match Sys.word_size with
| 32 - 715827883
| 64 - 3074457345618258603
| _ - failwith Unknown word size
That works perfectly
Jon Harrop wrote:
Is there a better workaround?
A (maybe overkill) solution is to use optcomp [1]. What you have to do
is to add word_size variable:
Pa_optcomp.define word_size (Int Sys.word_size)
Then you can write:
let gcd3 =
#if word_size = 32
715827883
#elif word_size = 64