Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Int overflow in literals
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oleg Trott <oleg_trott@c...>
Subject: Re: [Caml-list] Int overflow in literals
On Thursday 30 October 2003 03:05 pm, Issac Trotts wrote:
> On Thu, Oct 30, 2003 at 02:53:32PM +0100, Marcin 'Qrczak' Kowalczyk wrote:
> > I understand that int overflow is not checked on arithmetic for
> > efficiency reasons, but IMHO it would be better if it was checked
> > at least in literals. When someone writes 10000000000, he certainly
> > does not mean -737418240.
>
> If you want to be sure that the number is correctly stored, you can use
> Int64:
>
>     Int64.of_string "10000000000"
>
> Issac

Or, better yet, use Big_int:

        Objective Caml version 3.06

# Int64.of_string "10000000000000000000";;
- : int64 = <int64 -8446744073709551616>
# #load "nums.cma";;
# Big_int.big_int_of_string "10000000000000000000";;

-- 
Oleg Trott <oleg_trott@columbia.edu>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners