From: Elnatan Reisner <elnatan@cs.umd.edu>
To: OCaml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] 2147483648l < 2147483647l
Date: Tue, 19 Jan 2010 14:15:14 -0500 [thread overview]
Message-ID: <348A6F6E-AE4B-42B3-9FDA-5E58FBD62426@cs.umd.edu> (raw)
In-Reply-To: <00ff01ca9935$3539b050$9fad10f0$@romulus.metastack.com>
[-- Attachment #1: Type: text/plain, Size: 1719 bytes --]
On Jan 19, 2010, at 1:28 PM, David Allsopp wrote:
> Goswin von Brederlow wrote:
>
>>> # 2147483648l;;
>>> - : int32 = -2147483648l
>>
>> Isn't that documented properly? I think in the docs I saw at least
>> that
>> ocaml will silently overflow ints.
>
> Arithmetic operations are allowed to overflow silently but at no
> point do
> you end up with an illegal constant which is the bug here.
>
> i.e. Int32.add 2147483647l 1l correctly evaluates to -2147483648l but
> -2147483648l is a valid int32. The evaluation of a constant by the
> compiler
> in your ML source is supposed to follow the same rules as
> Int32.of_string
> (which would raise an exception if given "-2147483648l") hence
> 2147483648l
> which is not a valid int32 should be a "syntax" error.
As a point of clarification, the top level and the to_string functions
do have the same behavior; none of them raise an exception when given
a literal representing max_int+1 or min_int. It doesn't matter whether
this is done with ints, Int32s, or Int64s. (I am using OCaml 3.11.1 on
a 32-bit machine.)
# 1073741824,-1073741824;;
- : int * int = (-1073741824, -1073741824)
# int_of_string "1073741824",int_of_string "-1073741824";;
- : int * int = (-1073741824, -1073741824)
# 2147483648l,-2147483648l;;
- : int32 * int32 = (-2147483648l, -2147483648l)
# Int32.of_string "2147483648",Int32.of_string "-2147483648";;
- : int32 * int32 = (-2147483648l, -2147483648l)
# 9223372036854775808L,-9223372036854775808L;;
- : int64 * int64 = (-9223372036854775808L, -9223372036854775808L)
# Int64.of_string "9223372036854775808",Int64.of_string
"-9223372036854775808";;
- : int64 * int64 = (-9223372036854775808L, -9223372036854775808L)
-Elnatan
[-- Attachment #2: Type: text/html, Size: 2564 bytes --]
prev parent reply other threads:[~2010-01-19 19:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-05 12:59 Matej Kosik
2010-01-05 13:17 ` [Caml-list] " Olivier Andrieu
2010-01-05 13:26 ` David Allsopp
2010-01-19 17:59 ` Goswin von Brederlow
2010-01-19 18:28 ` David Allsopp
2010-01-19 19:15 ` Elnatan Reisner [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=348A6F6E-AE4B-42B3-9FDA-5E58FBD62426@cs.umd.edu \
--to=elnatan@cs.umd.edu \
--cc=caml-list@yquem.inria.fr \
/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