From: "Jean-Christophe Filliâtre" <Jean-Christophe.Filliatre@lri.fr>
To: Jon Harrop <jon@ffconsultancy.com>
Cc: O'Caml Mailing List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Parsing 64-bit ints in 32-bit OCaml
Date: Mon, 16 Mar 2009 22:58:53 +0100 [thread overview]
Message-ID: <49BECB9D.5010805@lri.fr> (raw)
In-Reply-To: <200903071728.56418.jon@ffconsultancy.com>
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 size"
>
> That works perfectly in 64-bit but breaks OCaml's parser in 32-bit, which dies
> with:
>
> Integer literal exceeds the range of representable integers of type int
>
> As a workaround, I replaced it with:
>
> | 64 -> Int64.to_int 3074457345618258603L
>
> Is there a better workaround?
I also bump into the same problem from time to time, and I usually
replace the large constant by a (launch time) computation, such as
(0xffff lsl 16) lor 0xffff
for 0xffffffff for instance. In your case, it could simply be
(3074457 * 1000000 + 345618) * 1000000 + 258603
But your solution is equally good (the int64 is boxed but is simpler to
read).
--
Jean-Christophe
prev parent reply other threads:[~2009-03-16 21:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-07 17:28 Jon Harrop
2009-03-07 18:12 ` [Caml-list] " Jérémie Dimino
2009-03-16 21:58 ` Jean-Christophe Filliâtre [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49BECB9D.5010805@lri.fr \
--to=jean-christophe.filliatre@lri.fr \
--cc=caml-list@yquem.inria.fr \
--cc=jon@ffconsultancy.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox