From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA02477; Thu, 10 Oct 2002 17:01:28 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA02747 for ; Thu, 10 Oct 2002 17:01:27 +0200 (MET DST) Received: from yoda.planetinternet.be (anvers-smtp.planetinternet.be [195.95.30.152]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9AF1QD00647 for ; Thu, 10 Oct 2002 17:01:26 +0200 (MET DST) Received: from janxp (u212-239-205-3.adsl.pi.be [212.239.205.3]) by yoda.planetinternet.be (Postfix) with ESMTP id A6F1E37629 for ; Thu, 10 Oct 2002 17:01:25 +0200 (CEST) Message-ID: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> From: "Scott J," To: Subject: [Caml-list] Runtime overflow and what to do Date: Thu, 10 Oct 2002 17:01:26 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00B9_01C2707E.AB3199E0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk This is a multi-part message in MIME format. ------=_NextPart_000_00B9_01C2707E.AB3199E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, suppose I use the following code for fact let rec fact n = if n <= 1 then 1 else n * fact (n - 1) ;; Because an integer number is represented by a fixed number of bytes I will get a runtime overflow if n is chosen too large. Is there in Ocamel a workaround to cope with this problem . Something like " Onoverflow goto .. " in imperative languages. Thx Scott ------=_NextPart_000_00B9_01C2707E.AB3199E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
 
 
suppose I use the following code for=20 fact
 
let rec fact n =3D if n <=3D 1 then = 1 else n * fact=20 (n - 1) ;;
 
Because an integer number is = represented by a fixed=20 number of bytes I will get a runtime overflow if n is chosen too=20 large.
 
Is there in Ocamel a workaround to cope = with this=20 problem . Something like " Onoverflow goto .. " in imperative=20 languages.
 
Thx
 
Scott
 
 
------=_NextPart_000_00B9_01C2707E.AB3199E0-- ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA03308; Thu, 10 Oct 2002 17:07:37 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA02983 for ; Thu, 10 Oct 2002 17:07:37 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9AF7a524617; Thu, 10 Oct 2002 17:07:36 +0200 (MET DST) Received: from santenay.inria.fr (santenay.inria.fr [128.93.8.59]) by pauillac.inria.fr (8.7.6/8.7.3) with SMTP id RAA02875; Thu, 10 Oct 2002 17:07:35 +0200 (MET DST) Date: Thu, 10 Oct 2002 17:07:35 +0200 From: Maxence Guesdon To: "Scott J," Cc: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-Id: <20021010170735.1d7dbb3a.maxence.guesdon@inria.fr> In-Reply-To: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> Organization: INRIA X-Mailer: Sylpheed version 0.8.3claws (GTK+ 1.2.10; ) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 10 Oct 2002 17:01:26 +0200 "Scott J," wrote: > let rec fact n = if n <= 1 then 1 else n * fact (n - 1) ;; You can catch the Stack_overflow exception : try fact 500000 with Stack_overflow -> -1 Is that what you want ? -- Maxence Guesdon ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA03377; Thu, 10 Oct 2002 17:11:23 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA02722 for ; Thu, 10 Oct 2002 17:11:22 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9AFBL524862; Thu, 10 Oct 2002 17:11:21 +0200 (MET DST) Received: from santenay.inria.fr (santenay.inria.fr [128.93.8.59]) by pauillac.inria.fr (8.7.6/8.7.3) with SMTP id RAA03340; Thu, 10 Oct 2002 17:11:21 +0200 (MET DST) Date: Thu, 10 Oct 2002 17:11:20 +0200 From: Maxence Guesdon To: "Scott J," Cc: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-Id: <20021010171120.175e2dca.maxence.guesdon@inria.fr> In-Reply-To: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> Organization: INRIA X-Mailer: Sylpheed version 0.8.3claws (GTK+ 1.2.10; ) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > suppose I use the following code for fact > > let rec fact n = if n <= 1 then 1 else n * fact (n - 1) ;; > > Because an integer number is represented by a fixed number of bytes I will > get a runtime overflow if n is chosen too large. > > Is there in Ocamel a workaround to cope with this problem . Something like " > Onoverflow goto .. " in imperative languages. Sorry, i replied too fast and did not answer your question, since you don't want to catch stack_overflow but be warned about an overflow during the computation of mult. I don't know how to do that. -- Maxence Guesdon ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA03982; Thu, 10 Oct 2002 17:21:14 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA03796 for ; Thu, 10 Oct 2002 17:21:14 +0200 (MET DST) Received: from beaune.inria.fr (beaune.inria.fr [128.93.8.3]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9AFLDD01207 for ; Thu, 10 Oct 2002 17:21:13 +0200 (MET DST) Received: by beaune.inria.fr (8.8.8/1.1.22.3/14Sep99-0328PM) id RAA0000032708; Thu, 10 Oct 2002 17:21:13 +0200 (MET DST) From: Luc Maranget Message-Id: <200210101521.RAA0000032708@beaune.inria.fr> Subject: Re: [Caml-list] Runtime overflow and what to do To: jscott@planetinternet.be (Scott J, ) Date: Thu, 10 Oct 2002 17:21:13 +0200 (MET DST) Cc: caml-list@inria.fr In-Reply-To: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> from "Scott J," at oct 10, 2002 05:01:26 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Hi, > > > suppose I use the following code for fact > > let rec fact n = if n <= 1 then 1 else n * fact (n - 1) ;; > > Because an integer number is represented by a fixed number of bytes I will > get a runtime overflow if n is chosen too large. > > Is there in Ocamel a workaround to cope with this problem . Something like " > Onoverflow goto .. " in imperative languages. > > Thx > > Scott > > There is no such feature as a Onoverflow goto, because Ocaml (and not OCamel...) default integers are not << real >> integers, but machine integers on some size (typically 31 or 63) bits. This means that maxint + 1 is minint and basically this is the behavior of C. I guess the reason why is avoiding putting non-obvious tests everywhere. Most of the time you do not need those tests. * If you want ``real'' integers, you can use some arbitrary precision library (Num, etc.), overflow detection would not help here anyway. * If you want to be warned on overflow, you have to devise the tests by yourself, and then you can use an exception as your Onoverflow goto An easy one : expection Overflow let protected_incr x = let y = x+1 in if y > x then y else raise Overflow try .... incr (..) with | Overflow -> ... do whatever you can ... Hope it helps. --Luc ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA08603; Thu, 10 Oct 2002 20:03:46 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA08583 for ; Thu, 10 Oct 2002 20:03:45 +0200 (MET DST) Received: from mel-rto6.wanadoo.fr (smtp-out-6.wanadoo.fr [193.252.19.25]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9AI3iD04688; Thu, 10 Oct 2002 20:03:44 +0200 (MET DST) Received: from mel-rta10.wanadoo.fr (193.252.19.193) by mel-rto6.wanadoo.fr (6.5.007) id 3DA24D4D0020A638; Thu, 10 Oct 2002 20:03:44 +0200 Received: from iliana (80.13.248.160) by mel-rta10.wanadoo.fr (6.5.007) id 3DA24C0A0021748C; Thu, 10 Oct 2002 20:03:44 +0200 Received: from luther by iliana with local (Exim 3.36 #1 (Debian)) id 17zhoJ-0000VH-00; Thu, 10 Oct 2002 20:13:23 +0200 Date: Thu, 10 Oct 2002 20:13:23 +0200 To: Luc Maranget Cc: "Scott J, " , caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021010181323.GA1922@iliana> References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> <200210101521.RAA0000032708@beaune.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200210101521.RAA0000032708@beaune.inria.fr> User-Agent: Mutt/1.4i From: Sven LUTHER Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, Oct 10, 2002 at 05:21:13PM +0200, Luc Maranget wrote: > > Hi, > > > > > > suppose I use the following code for fact > > > > let rec fact n = if n <= 1 then 1 else n * fact (n - 1) ;; > > > > Because an integer number is represented by a fixed number of bytes I will > > get a runtime overflow if n is chosen too large. > > > > Is there in Ocamel a workaround to cope with this problem . Something like " > > Onoverflow goto .. " in imperative languages. > > > > Thx > > > > Scott > > > > > > There is no such feature as a Onoverflow goto, because > Ocaml (and not OCamel...) default integers are not << real >> integers, > but machine integers on some size (typically 31 or 63) bits. But it is the lower bit that is ignored, no, si i guess incrementing an ocaml integer by 1, correspond to incrementing the machine integer by two, and would set the overflow flag in the processor status register all the same, would it not ? The flag is then ignored, but it is set all the same, at least until it is overriden by some other calculation. Friendly, Sven Luther ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA10421; Thu, 10 Oct 2002 21:01:18 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA10347 for ; Thu, 10 Oct 2002 21:01:18 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9AIvH504010; Thu, 10 Oct 2002 20:57:17 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA10527; Thu, 10 Oct 2002 20:57:16 +0200 (MET DST) Date: Thu, 10 Oct 2002 20:57:16 +0200 From: Xavier Leroy To: Sven LUTHER Cc: Luc Maranget , "Scott J, " , caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021010205716.A8990@pauillac.inria.fr> References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> <200210101521.RAA0000032708@beaune.inria.fr> <20021010181323.GA1922@iliana> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20021010181323.GA1922@iliana>; from luther@dpt-info.u-strasbg.fr on Thu, Oct 10, 2002 at 08:13:23PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > But it is the lower bit that is ignored, no, si i guess incrementing an > ocaml integer by 1, correspond to incrementing the machine integer by > two, and would set the overflow flag in the processor status register > all the same, would it not ? Yes, except that not all processors have overflow flags. The Alpha and the MIPS don't, for instance. Integer arithmetic modulo a power of 2 is unpleasant for certain applications (and very useful for others, e.g. hash functions and cryptography), but this is really all what today's processors offer. - Xavier Leroy ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA14233; Fri, 11 Oct 2002 00:17:17 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA14422 for ; Fri, 11 Oct 2002 00:17:16 +0200 (MET DST) Received: from yoda.planetinternet.be (anvers-smtp.planetinternet.be [195.95.30.152]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9AMHF509826; Fri, 11 Oct 2002 00:17:15 +0200 (MET DST) Received: from janxp (u212-239-205-3.adsl.pi.be [212.239.205.3]) by yoda.planetinternet.be (Postfix) with ESMTP id 56186374C7; Fri, 11 Oct 2002 00:17:14 +0200 (CEST) Message-ID: <021501c270aa$ca400660$0100a8c0@janxp> From: "Scott J," To: "Xavier Leroy" Cc: References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> <200210101521.RAA0000032708@beaune.inria.fr> <20021010181323.GA1922@iliana> <20021010205716.A8990@pauillac.inria.fr> Subject: Re: [Caml-list] Runtime overflow and what to do Date: Fri, 11 Oct 2002 00:17:15 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0211_01C270BB.8D9B0FA0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk This is a multi-part message in MIME format. ------=_NextPart_000_0211_01C270BB.8D9B0FA0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, So it is not easy, perhaps even impossible if the processor doesn't set a flag . e.g. fact n begins first with a lis of negative numbers (after overflow) then comes again a list with positive numbers and then it remains = 0 Scott ----- Original Message ----- From: Xavier Leroy To: Sven LUTHER Cc: Luc Maranget ; Scott J, ; caml-list@inria.fr Sent: Thursday, October 10, 2002 8:57 PM Subject: Re: [Caml-list] Runtime overflow and what to do > But it is the lower bit that is ignored, no, si i guess incrementing an > ocaml integer by 1, correspond to incrementing the machine integer by > two, and would set the overflow flag in the processor status register > all the same, would it not ? Yes, except that not all processors have overflow flags. The Alpha and the MIPS don't, for instance. Integer arithmetic modulo a power of 2 is unpleasant for certain applications (and very useful for others, e.g. hash functions and cryptography), but this is really all what today's processors offer. - Xavier Leroy ------=_NextPart_000_0211_01C270BB.8D9B0FA0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
 
So it is not easy, perhaps even = impossible if the=20 processor doesn't set a flag .
 
e.g. fact n begins first with a lis of = negative=20 numbers (after overflow) then comes again a list with positive numbers = and then=20 it remains =3D 0
 
Scott
----- Original Message -----
From:=20 Xavier=20 Leroy
Cc: Luc Maranget ; Scott J,=20 ; caml-list@inria.fr
Sent: Thursday, October 10, = 2002 8:57=20 PM
Subject: Re: [Caml-list] = Runtime overflow=20 and what to do

> But it is the lower bit that is ignored, no, si i = guess=20 incrementing an
> ocaml integer by 1, correspond to incrementing = the=20 machine integer by
> two, and would set the overflow flag in the = processor status register
> all the same, would it not ? =

Yes,=20 except that not all processors have overflow flags.  The = Alpha
and the=20 MIPS don't, for instance.  Integer arithmetic modulo a = power
of 2 is=20 unpleasant for certain applications (and very useful for
others, = e.g. hash=20 functions and cryptography), but this is really all
what today's = processors=20 offer.

- Xavier Leroy ------=_NextPart_000_0211_01C270BB.8D9B0FA0-- ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id IAA22257; Fri, 11 Oct 2002 08:42:31 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA21840 for ; Fri, 11 Oct 2002 08:42:31 +0200 (MET DST) Received: from grisu.bik-gmbh.de (In-Planung---------X.BIK-GmbH.de [212.12.55.66] (may be forged)) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9B6gU523357 for ; Fri, 11 Oct 2002 08:42:30 +0200 (MET DST) Received: from hars.de (prony.bik-gmbh.de [194.233.237.133]) by grisu.bik-gmbh.de (8.12.3/8.12.3) with ESMTP id g9B6gRU8070554; Fri, 11 Oct 2002 08:42:27 +0200 (CEST) (envelope-from florian@hars.de) Message-ID: <3DA672CD.2020301@hars.de> Date: Fri, 11 Oct 2002 08:42:21 +0200 From: Florian Hars User-Agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.1) Gecko/20020826 X-Accept-Language: de-de, en-us, en MIME-Version: 1.0 To: "Scott J," CC: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Scott J, wrote: > Because an integer number is represented by a fixed number of bytes I > will get a runtime overflow if n is chosen too large. You have to check explicitly: # exception Overflow;; exception Overflow # let fact n = let rec fact_r acc n = if n = 1 then acc else if max_int / acc > (n-1) then fact_r (acc * n) (n - 1) else raise Overflow in fact_r 1 n;; val fact : int -> int = # fact 12;; - : int = 479001600 # fact 13;; Exception: Overflow. Yours, Florian ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA23661; Fri, 11 Oct 2002 09:50:38 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA23742 for ; Fri, 11 Oct 2002 09:50:37 +0200 (MET DST) Received: from mel-rto6.wanadoo.fr (smtp-out-6.wanadoo.fr [193.252.19.25]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9B7oaD19936; Fri, 11 Oct 2002 09:50:36 +0200 (MET DST) Received: from mel-rta7.wanadoo.fr (193.252.19.61) by mel-rto6.wanadoo.fr (6.5.007) id 3DA24D4D0024FF09; Fri, 11 Oct 2002 09:50:36 +0200 Received: from iliana (217.128.59.170) by mel-rta7.wanadoo.fr (6.5.007) id 3DA24BE60023A76D; Fri, 11 Oct 2002 09:50:36 +0200 Received: from luther by iliana with local (Exim 3.36 #1 (Debian)) id 17zuiW-0000WX-00; Fri, 11 Oct 2002 10:00:16 +0200 Date: Fri, 11 Oct 2002 10:00:16 +0200 To: "Scott J," Cc: Xavier Leroy , caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021011080016.GA1974@iliana> References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> <200210101521.RAA0000032708@beaune.inria.fr> <20021010181323.GA1922@iliana> <20021010205716.A8990@pauillac.inria.fr> <021501c270aa$ca400660$0100a8c0@janxp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <021501c270aa$ca400660$0100a8c0@janxp> User-Agent: Mutt/1.4i From: Sven LUTHER Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, Oct 11, 2002 at 12:17:15AM +0200, Scott J, wrote: > Hi, > > So it is not easy, perhaps even impossible if the processor doesn't set a > flag . > > e.g. fact n begins first with a lis of negative numbers (after overflow) > then comes again a list with positive numbers and then it remains = 0 No, it is easy, but you have to check at each iteration, as was proposed here previously. Friendly, Sven Luther ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA23864; Fri, 11 Oct 2002 09:52:46 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA23835 for ; Fri, 11 Oct 2002 09:52:45 +0200 (MET DST) Received: from mel-rto4.wanadoo.fr (smtp-out-4.wanadoo.fr [193.252.19.23]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9B7qiD19975; Fri, 11 Oct 2002 09:52:44 +0200 (MET DST) Received: from mel-rta7.wanadoo.fr (193.252.19.61) by mel-rto4.wanadoo.fr (6.5.007) id 3DA24D320024F735; Fri, 11 Oct 2002 09:52:44 +0200 Received: from iliana (217.128.59.170) by mel-rta7.wanadoo.fr (6.5.007) id 3DA24BE60023AEC8; Fri, 11 Oct 2002 09:52:44 +0200 Received: from luther by iliana with local (Exim 3.36 #1 (Debian)) id 17zukb-0000Ww-00; Fri, 11 Oct 2002 10:02:25 +0200 Date: Fri, 11 Oct 2002 10:02:25 +0200 To: Xavier Leroy Cc: Sven LUTHER , Luc Maranget , "Scott J, " , caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021011080225.GB1974@iliana> References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> <200210101521.RAA0000032708@beaune.inria.fr> <20021010181323.GA1922@iliana> <20021010205716.A8990@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20021010205716.A8990@pauillac.inria.fr> User-Agent: Mutt/1.4i From: Sven LUTHER Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, Oct 10, 2002 at 08:57:16PM +0200, Xavier Leroy wrote: > > But it is the lower bit that is ignored, no, si i guess incrementing an > > ocaml integer by 1, correspond to incrementing the machine integer by > > two, and would set the overflow flag in the processor status register > > all the same, would it not ? > > Yes, except that not all processors have overflow flags. The Alpha > and the MIPS don't, for instance. Integer arithmetic modulo a power Didn't know that. (Mostly i know about powerpc and M68K assembly only). Mmm, Is that why these processors are faster on number crunshing ? Or better said, a consequence of designing these processors fro being fast at number crunshing ? > of 2 is unpleasant for certain applications (and very useful for > others, e.g. hash functions and cryptography), but this is really all > what today's processors offer. Did you ever got hand on a MAJC processor, which supposedly has an extra bit for GC purpose, or something such ? Friendly, Sven Luther ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA28474; Fri, 11 Oct 2002 12:05:53 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA27640 for ; Fri, 11 Oct 2002 12:05:52 +0200 (MET DST) Received: from athlon.baretta.com (host94-68.pool80116.interbusiness.it [80.116.68.94]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9BA5p506276 for ; Fri, 11 Oct 2002 12:05:51 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 7FF70273AE; Fri, 11 Oct 2002 12:16:13 +0200 (CEST) Message-ID: <3DA6A4ED.5050700@baretta.com> Date: Fri, 11 Oct 2002 12:16:13 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: it, en MIME-Version: 1.0 To: "Scott J," , Ocaml Subject: Re: [Caml-list] Runtime overflow and what to do References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> <200210101521.RAA0000032708@beaune.inria.fr> <20021010181323.GA1922@iliana> <20021010205716.A8990@pauillac.inria.fr> <021501c270aa$ca400660$0100a8c0@janxp> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Scott J, wrote: > Hi, > > So it is not easy, perhaps even impossible if the processor doesn't set > a flag . > > e.g. fact n begins first with a lis of negative numbers (after overflow) > then comes again a list with positive numbers and then it remains = 0 > > Scott If your problem is only the factorial function, then you can calculate statically (i.e. at source-code writing time) the value of the maximum integer whose factorial will fit in O'Caml's representation of integers, and test against that, once and for all, before entering the recursive calculation. exception overflow let max_fact_arg = ... let fact = let rec rec_fact n = if n <= 0 then 1 else n * rec_fact (n-1) in function | x when x <= max_fact_arg -> rec_fact n | _ -> raise Overflow This strategy allows to incur in hardly any runtime costs for the check, and it also allows you prove more easily that your program will not raise runtime Overflow exceptions (the precondition for not entering the exception raising branch does not have to be propagated out of a recursive function call). Alex ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA02635; Sat, 12 Oct 2002 18:13:38 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA02515 for ; Sat, 12 Oct 2002 18:13:36 +0200 (MET DST) Received: from pacific-carrier-annex.mit.edu (PACIFIC-CARRIER-ANNEX.MIT.EDU [18.7.21.83]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9CGDZD21088 for ; Sat, 12 Oct 2002 18:13:36 +0200 (MET DST) Received: from grand-central-station.mit.edu (GRAND-CENTRAL-STATION.MIT.EDU [18.7.21.82]) by pacific-carrier-annex.mit.edu (8.9.2/8.9.2) with ESMTP id MAA22211; Sat, 12 Oct 2002 12:13:34 -0400 (EDT) Received: from melbourne-city-street.mit.edu (MELBOURNE-CITY-STREET.MIT.EDU [18.7.21.86]) by grand-central-station.mit.edu (8.9.2/8.9.2) with ESMTP id MAA07015; Sat, 12 Oct 2002 12:13:33 -0400 (EDT) Received: from psi-phi.mit.edu (PSI-PHI.MIT.EDU [18.187.1.35]) by melbourne-city-street.mit.edu (8.9.2/8.9.2) with ESMTP id MAA16516; Sat, 12 Oct 2002 12:13:32 -0400 (EDT) Received: (from jfc@localhost) by psi-phi.mit.edu (8.9.3) id MAA27433; Sat, 12 Oct 2002 12:13:32 -0400 Message-Id: <200210121613.MAA27433@psi-phi.mit.edu> To: Alessandro Baretta cc: Ocaml Subject: Re: [Caml-list] Runtime overflow and what to do In-Reply-To: Your message of "Fri, 11 Oct 2002 12:16:13 +0200." <3DA6A4ED.5050700@baretta.com> Date: Sat, 12 Oct 2002 12:13:32 -0400 From: John Carr Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > If your problem is only the factorial function, then you can > calculate statically (i.e. at source-code writing time) the > value of the maximum integer whose factorial will fit in > O'Caml's representation of integers, and test against that, > once and for all, before entering the recursive calculation. OCaml supports 32 and 64 bit integers. Is it possible to detect at compile time the size of the maximum integer? In the case of factorial, you could almost as easily optimize the function to a table lookup. ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA03707; Sat, 12 Oct 2002 18:48:49 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA03650 for ; Sat, 12 Oct 2002 18:48:48 +0200 (MET DST) Received: from mel-rto4.wanadoo.fr (smtp-out-4.wanadoo.fr [193.252.19.23]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9CGmlD21479 for ; Sat, 12 Oct 2002 18:48:47 +0200 (MET DST) Received: from mel-rta9.wanadoo.fr (193.252.19.69) by mel-rto4.wanadoo.fr (6.5.007) id 3DA24D320031D8B8; Sat, 12 Oct 2002 18:48:46 +0200 Received: from iliana (80.11.160.38) by mel-rta9.wanadoo.fr (6.5.007) id 3DA24B2900327511; Sat, 12 Oct 2002 18:48:46 +0200 Received: from luther by iliana with local (Exim 3.36 #1 (Debian)) id 180Pax-0001Em-00; Sat, 12 Oct 2002 18:58:31 +0200 Date: Sat, 12 Oct 2002 18:58:31 +0200 To: John Carr Cc: Alessandro Baretta , Ocaml Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021012165831.GA4700@iliana> References: <3DA6A4ED.5050700@baretta.com> <200210121613.MAA27433@psi-phi.mit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200210121613.MAA27433@psi-phi.mit.edu> User-Agent: Mutt/1.4i From: Sven LUTHER Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, Oct 12, 2002 at 12:13:32PM -0400, John Carr wrote: > > > If your problem is only the factorial function, then you can > > calculate statically (i.e. at source-code writing time) the > > value of the maximum integer whose factorial will fit in > > O'Caml's representation of integers, and test against that, > > once and for all, before entering the recursive calculation. > > OCaml supports 32 and 64 bit integers. Is it possible to detect at > compile time the size of the maximum integer? val max_int : int The greatest representable integer. Says the doc. BTW, i compile the sparc debian package on a sparc64 box which advertizes as a sparc box. Will i get access to the 64 bit integers in this case or not ? Friendly, Sven Luther ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA04408; Sat, 12 Oct 2002 19:11:52 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA03822 for ; Sat, 12 Oct 2002 19:11:51 +0200 (MET DST) Received: from laurelin.dementia.org ([208.167.88.73]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9CHBn503033 for ; Sat, 12 Oct 2002 19:11:50 +0200 (MET DST) Received: by laurelin.dementia.org (Postfix, from userid 1001) id 4A71D70D8; Sat, 12 Oct 2002 13:12:24 -0400 (EDT) To: Sven LUTHER Cc: John Carr , Alessandro Baretta , Ocaml Subject: Re: [Caml-list] Runtime overflow and what to do References: <3DA6A4ED.5050700@baretta.com> <200210121613.MAA27433@psi-phi.mit.edu> <20021012165831.GA4700@iliana> From: John Prevost Date: 12 Oct 2002 13:12:23 -0400 (71.693 UMT) In-Reply-To: <20021012165831.GA4700@iliana> Message-ID: <861y6vtwco.fsf@laurelin.dementia.org> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >>>>> "sl" == Sven LUTHER writes: sl> On Sat, Oct 12, 2002 at 12:13:32PM -0400, John Carr wrote: >> OCaml supports 32 and 64 bit integers. Is it possible to >> detect at compile time the size of the maximum integer? sl> val max_int : int sl> The greatest representable integer. But that's at runtime. Which, actually, is the best you can do--bytecode compiled things might run on any architecture. Native compiled things you can rely on more. But if you want to compile this knowledge in, you'll have to have some configure script that determines the word size and chooses which version to compile. John. ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA17936; Sun, 13 Oct 2002 11:25:39 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA18132 for ; Sun, 13 Oct 2002 11:25:38 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9D9Pc518845; Sun, 13 Oct 2002 11:25:38 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA18212; Sun, 13 Oct 2002 11:25:37 +0200 (MET DST) Date: Sun, 13 Oct 2002 11:25:37 +0200 From: Xavier Leroy To: "Scott J," Cc: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021013112537.J13771@pauillac.inria.fr> References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> <200210101521.RAA0000032708@beaune.inria.fr> <20021010181323.GA1922@iliana> <20021010205716.A8990@pauillac.inria.fr> <021501c270aa$ca400660$0100a8c0@janxp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <021501c270aa$ca400660$0100a8c0@janxp>; from jscott@planetinternet.be on Fri, Oct 11, 2002 at 12:17:15AM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > So it is not easy, perhaps even impossible if the processor doesn't set a > flag . It is possible, but slow and not pretty! For example, here is Caml code that performs integer addition and detects overflows: exception Integer_overflow let no_overflow_add a b = if (a lxor b) lor (a lxor (lnot (a+b))) < 0 (* no kidding! *) then a + b else raise Integer_overflow Multiplication is left as an exercise for the readers :-) My advice would be to use bignums; they are a bit slower, but at least you get the exact result in all cases. - Xavier Leroy ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA18163; Sun, 13 Oct 2002 11:28:19 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA18044 for ; Sun, 13 Oct 2002 11:28:18 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9D9SG518981; Sun, 13 Oct 2002 11:28:16 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA17900; Sun, 13 Oct 2002 11:28:15 +0200 (MET DST) Date: Sun, 13 Oct 2002 11:28:15 +0200 From: Xavier Leroy To: John Carr Cc: Alessandro Baretta , Ocaml Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021013112815.K13771@pauillac.inria.fr> References: <3DA6A4ED.5050700@baretta.com> <200210121613.MAA27433@psi-phi.mit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <200210121613.MAA27433@psi-phi.mit.edu>; from jfc@MIT.EDU on Sat, Oct 12, 2002 at 12:13:32PM -0400 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > OCaml supports 32 and 64 bit integers. Is it possible to detect at > compile time the size of the maximum integer? What about: echo "print_int Sys.word_size" > /tmp/caml$$ WORDSIZE=`ocaml /tmp/caml$$` rm -f /tmp/caml$$ WORDSIZE will be set to 32 or 64, depending on the platform. - Xavier Leroy ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA18500; Sun, 13 Oct 2002 11:31:34 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA18651 for ; Sun, 13 Oct 2002 11:31:33 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9D9VV519125; Sun, 13 Oct 2002 11:31:31 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA18517; Sun, 13 Oct 2002 11:31:30 +0200 (MET DST) Date: Sun, 13 Oct 2002 11:31:30 +0200 From: Xavier Leroy To: Sven LUTHER Cc: John Carr , Alessandro Baretta , Ocaml Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021013113130.L13771@pauillac.inria.fr> References: <3DA6A4ED.5050700@baretta.com> <200210121613.MAA27433@psi-phi.mit.edu> <20021012165831.GA4700@iliana> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20021012165831.GA4700@iliana>; from luther@dpt-info.u-strasbg.fr on Sat, Oct 12, 2002 at 06:58:31PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > BTW, i compile the sparc debian package on a sparc64 box which > advertizes as a sparc box. Will i get access to the 64 bit integers in > this case or not ? The short answer is: it depends on the C compiler. Caml integers correspond to the C "long int" type, with one bit reserved for GC purposes. So, if the C compiler maps "long int" to 64-bit integers, you get 63-bit Caml ints; if it chooses 32-bit integers for "long int", you get 31-bit Caml ints. Often, this can be controlled via flags to the C compiler. The above is for the bytecode interpreter. For the native-code compiler, the current Sparc code emitter mandates 32-bit integers. - Xavier Leroy ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA18681; Sun, 13 Oct 2002 11:42:30 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA18729 for ; Sun, 13 Oct 2002 11:42:29 +0200 (MET DST) Received: from mel-rto6.wanadoo.fr (smtp-out-6.wanadoo.fr [193.252.19.25]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9D9gTD02284; Sun, 13 Oct 2002 11:42:29 +0200 (MET DST) Received: from mel-rta10.wanadoo.fr (193.252.19.193) by mel-rto6.wanadoo.fr (6.5.007) id 3DA24D4D0034D607; Sun, 13 Oct 2002 11:42:29 +0200 Received: from iliana (80.14.240.235) by mel-rta10.wanadoo.fr (6.5.007) id 3DA24C0A00362873; Sun, 13 Oct 2002 11:42:29 +0200 Received: from luther by iliana with local (Exim 3.36 #1 (Debian)) id 180fQ0-0000WQ-00; Sun, 13 Oct 2002 11:52:16 +0200 Date: Sun, 13 Oct 2002 11:52:16 +0200 To: Xavier Leroy Cc: Sven LUTHER , John Carr , Alessandro Baretta , Ocaml Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021013095216.GA1949@iliana> References: <3DA6A4ED.5050700@baretta.com> <200210121613.MAA27433@psi-phi.mit.edu> <20021012165831.GA4700@iliana> <20021013113130.L13771@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20021013113130.L13771@pauillac.inria.fr> User-Agent: Mutt/1.4i From: Sven LUTHER Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, Oct 13, 2002 at 11:31:30AM +0200, Xavier Leroy wrote: > > BTW, i compile the sparc debian package on a sparc64 box which > > advertizes as a sparc box. Will i get access to the 64 bit integers in > > this case or not ? > > The short answer is: it depends on the C compiler. Caml integers > correspond to the C "long int" type, with one bit reserved for GC > purposes. So, if the C compiler maps "long int" to 64-bit integers, > you get 63-bit Caml ints; if it chooses 32-bit integers for "long int", > you get 31-bit Caml ints. Often, this can be controlled via flags to > the C compiler. Ok, ... Which would be the relevant flags ? i get (from the build log) : ... Checking the sizes of integers and pointers... OK, this is a regular 32 bit architecture. 64-bit "long long" integer type found (printf with "%ll"). This is a big-endian architecture. Doubles must be doubleword-aligned. 64-bit integers must be doubleword-aligned. ... Configuration for the bytecode compiler: C compiler used........... gcc options for compiling..... -fno-defer-pop -Wall -Wno-unused -D_FILE_OFFSET_BITS=64 -D_REENTRANT options for linking....... -Wl,-E -lm -ldl -lcurses -lpthread shared libraries are supported options for compiling..... -fPIC -fno-defer-pop -Wall -Wno-unused -D_FILE_OFFSET_BITS=64 -D_REENTRANT command for building...... gcc -shared -o lib.so -Wl,-rpath,/a/path objs So i suppose this is not using 64 bit mode. More importantly, i suppose code compiled in this fashion for 64 bit sparcs will not build on 32 bit sparc boxes, if these kind of boxes are still available anyway. > The above is for the bytecode interpreter. For the native-code > compiler, the current Sparc code emitter mandates 32-bit integers. Would it be much work to build a 64-bit integers target ? Friendly, Sven Luther ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA19571; Sun, 13 Oct 2002 11:57:32 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA19504 for ; Sun, 13 Oct 2002 11:57:31 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9D9vP519885; Sun, 13 Oct 2002 11:57:26 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA19057; Sun, 13 Oct 2002 11:57:25 +0200 (MET DST) Date: Sun, 13 Oct 2002 11:57:25 +0200 From: Xavier Leroy To: Sven LUTHER Cc: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021013115725.P13771@pauillac.inria.fr> References: <3DA6A4ED.5050700@baretta.com> <200210121613.MAA27433@psi-phi.mit.edu> <20021012165831.GA4700@iliana> <20021013113130.L13771@pauillac.inria.fr> <20021013095216.GA1949@iliana> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20021013095216.GA1949@iliana>; from luther@dpt-info.u-strasbg.fr on Sun, Oct 13, 2002 at 11:52:16AM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Which would be the relevant flags ? No idea. If you're interested, you figure them out :-) > More importantly, i suppose code compiled in this fashion for 64 bit > sparcs will not build on 32 bit sparc boxes, if these kind of boxes are > still available anyway. Yes (to both). I still don't have access to a 64-bit SPARC machine. > > The above is for the bytecode interpreter. For the native-code > > compiler, the current Sparc code emitter mandates 32-bit integers. > > Would it be much work to build a 64-bit integers target ? A few days for someone who knows the SPARC64 assembly language well. - Xavier Leroy ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA19989; Sun, 13 Oct 2002 12:04:58 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA19641 for ; Sun, 13 Oct 2002 12:04:57 +0200 (MET DST) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9DA4v520219 for ; Sun, 13 Oct 2002 12:04:57 +0200 (MET DST) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id MAA16519 for caml-list@inria.fr; Sun, 13 Oct 2002 12:04:56 +0200 Date: Sun, 13 Oct 2002 12:04:56 +0200 From: Daniel de Rauglaudre To: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021013120456.D7639@verdot.inria.fr> References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> <200210101521.RAA0000032708@beaune.inria.fr> <20021010181323.GA1922@iliana> <20021010205716.A8990@pauillac.inria.fr> <021501c270aa$ca400660$0100a8c0@janxp> <20021013112537.J13771@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20021013112537.J13771@pauillac.inria.fr>; from xavier.leroy@inria.fr on Sun, Oct 13, 2002 at 11:25:37AM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Sun, Oct 13, 2002 at 11:25:37AM +0200, Xavier Leroy wrote: > Multiplication is left as an exercise for the readers :-) Much more complicated... I tried that a long time ago when I was writting a PostScript interpreter, but I found no solution. -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA19653; Sun, 13 Oct 2002 12:05:23 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA19422 for ; Sun, 13 Oct 2002 12:05:22 +0200 (MET DST) Received: from mel-rto3.wanadoo.fr (smtp-out-3.wanadoo.fr [193.252.19.233]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9DA5M520235; Sun, 13 Oct 2002 12:05:22 +0200 (MET DST) Received: from mel-rta7.wanadoo.fr (193.252.19.61) by mel-rto3.wanadoo.fr (6.5.007) id 3DA24D180034EAE0; Sun, 13 Oct 2002 12:05:21 +0200 Received: from iliana (80.14.240.235) by mel-rta7.wanadoo.fr (6.5.007) id 3DA24BE60032D12C; Sun, 13 Oct 2002 12:05:21 +0200 Received: from luther by iliana with local (Exim 3.36 #1 (Debian)) id 180fm9-0000Zi-00; Sun, 13 Oct 2002 12:15:09 +0200 Date: Sun, 13 Oct 2002 12:15:09 +0200 To: Xavier Leroy Cc: Sven LUTHER , caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021013101509.GA2181@iliana> References: <3DA6A4ED.5050700@baretta.com> <200210121613.MAA27433@psi-phi.mit.edu> <20021012165831.GA4700@iliana> <20021013113130.L13771@pauillac.inria.fr> <20021013095216.GA1949@iliana> <20021013115725.P13771@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20021013115725.P13771@pauillac.inria.fr> User-Agent: Mutt/1.4i From: Sven LUTHER Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, Oct 13, 2002 at 11:57:25AM +0200, Xavier Leroy wrote: > > Which would be the relevant flags ? > > No idea. If you're interested, you figure them out :-) Ok, ... Still i have difficulties understanding how this work, in my idea bytecode was build once run everywhere, how does this go with your statement that it can be made to use 64bit integers by a compiler switch ? Mmm, maybe you are speaking about ocamlrun only ? > > More importantly, i suppose code compiled in this fashion for 64 bit > > sparcs will not build on 32 bit sparc boxes, if these kind of boxes are > > still available anyway. > > Yes (to both). I still don't have access to a 64-bit SPARC machine. Do you want access ? I can try to arrange that if you want. To an hppa machine also. > > > The above is for the bytecode interpreter. For the native-code > > > compiler, the current Sparc code emitter mandates 32-bit integers. > > > > Would it be much work to build a 64-bit integers target ? > > A few days for someone who knows the SPARC64 assembly language well. Ok, ... Friendly, Sven Luther ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA20632; Sun, 13 Oct 2002 12:19:09 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA20618 for ; Sun, 13 Oct 2002 12:19:08 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9DAJ7520825; Sun, 13 Oct 2002 12:19:07 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA20723; Sun, 13 Oct 2002 12:19:07 +0200 (MET DST) From: Pierre Weis Message-Id: <200210131019.MAA20723@pauillac.inria.fr> Subject: Re: [Caml-list] Runtime overflow and what to do In-Reply-To: <20021013112537.J13771@pauillac.inria.fr> from Xavier Leroy at "Oct 13, 102 11:25:37 am" To: xavier.leroy@inria.fr (Xavier Leroy) Date: Sun, 13 Oct 2002 12:19:07 +0200 (MET DST) Cc: jscott@planetinternet.be, caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > So it is not easy, perhaps even impossible if the processor doesn't set a > > flag . > > It is possible, but slow and not pretty! I must precise that even if the code to implement arithmetics with overflow checks can be considered as ``not pretty'', its usage is absolutely easy and transparent in Caml: just write a specialized module for arithmetics with overflow checks (say ``Cautious_arith'') that redefines ( + ), ( - ), ( * ), ( / ), min, etc, along the lines sketched by Xavier for addition (by the way, writing such a module is a very pleasant home exercise); once you have written the Cautious_arith module, write your application code as usual. Now, if you want overflow checks just add open Cautious_arith at the beginning of your module and recompile. If you changed your mind, and want to recover the normal speed of integer arithmetic operations, just remove the open directive and recompile! This is an elegant and clean application of very basic operators redefinition that not so many programming languages offer. Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA21297; Sun, 13 Oct 2002 12:30:00 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA21087 for ; Sun, 13 Oct 2002 12:29:59 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9DATx521209; Sun, 13 Oct 2002 12:29:59 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA17141; Sun, 13 Oct 2002 12:29:58 +0200 (MET DST) From: Pierre Weis Message-Id: <200210131029.MAA17141@pauillac.inria.fr> Subject: Re: [Caml-list] Runtime overflow and what to do In-Reply-To: <20021013120456.D7639@verdot.inria.fr> from Daniel de Rauglaudre at "Oct 13, 102 12:04:56 pm" To: daniel.de_rauglaudre@inria.fr (Daniel de Rauglaudre) Date: Sun, 13 Oct 2002 12:29:58 +0200 (MET DST) Cc: caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Hi, > > On Sun, Oct 13, 2002 at 11:25:37AM +0200, Xavier Leroy wrote: > > > Multiplication is left as an exercise for the readers :-) > > Much more complicated... I tried that a long time ago when I was > writting a PostScript interpreter, but I found no solution. (* [lenght_of_int] is the maximum number of bits in an integer. *) let length_of_int = Sys.word_size - 2;; let ( * ) n m = if num_bits_int n + num_bits_int m < length_of_int then n * m else raise (Overflow ("*", string_of_int n, string_of_int m)) (* [num_bits_int n] returns the number of significant bits of an integer. *) Just to let people play with the writting of the module :), num_bits_int is left as an exercise to the interested readers (3 lines of Caml code using trivial bit shuffling). Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA21731; Sun, 13 Oct 2002 12:47:53 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA21696 for ; Sun, 13 Oct 2002 12:47:53 +0200 (MET DST) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9DAlq521641 for ; Sun, 13 Oct 2002 12:47:52 +0200 (MET DST) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id MAA17273 for caml-list@inria.fr; Sun, 13 Oct 2002 12:47:52 +0200 Date: Sun, 13 Oct 2002 12:47:52 +0200 From: Daniel de Rauglaudre To: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021013124752.H7639@verdot.inria.fr> References: <20021013120456.D7639@verdot.inria.fr> <200210131029.MAA17141@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200210131029.MAA17141@pauillac.inria.fr>; from pierre.weis@inria.fr on Sun, Oct 13, 2002 at 12:29:58PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Sun, Oct 13, 2002 at 12:29:58PM +0200, Pierre Weis wrote: > let ( * ) n m = > if num_bits_int n + num_bits_int m < length_of_int > then n * m else raise (Overflow ("*", string_of_int n, string_of_int m)) Does it work with negative numbers? And with multiplication between a positive and a negative number? > Just to let people play with the writting of the module :), > num_bits_int is left as an exercise to the interested readers (3 lines > of Caml code using trivial bit shuffling). I am interested in knowing it, because I already searched that. Without a loop or a predefined array of powers of two, I don't know how to do that. -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA24122; Sun, 13 Oct 2002 14:38:47 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA23712 for ; Sun, 13 Oct 2002 14:38:46 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9DCcj523625; Sun, 13 Oct 2002 14:38:45 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA23940; Sun, 13 Oct 2002 14:38:45 +0200 (MET DST) From: Pierre Weis Message-Id: <200210131238.OAA23940@pauillac.inria.fr> Subject: Re: [Caml-list] Runtime overflow and what to do In-Reply-To: <20021013124752.H7639@verdot.inria.fr> from Daniel de Rauglaudre at "Oct 13, 102 12:47:52 pm" To: daniel.de_rauglaudre@inria.fr (Daniel de Rauglaudre) Date: Sun, 13 Oct 2002 14:38:45 +0200 (MET DST) Cc: caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi again, > On Sun, Oct 13, 2002 at 12:29:58PM +0200, Pierre Weis wrote: > > > let ( * ) n m = > > if num_bits_int n + num_bits_int m < length_of_int > > then n * m else raise (Overflow ("*", string_of_int n, string_of_int m)) > > Does it work with negative numbers? And with multiplication between a > positive and a negative number? Yes it does. > > Just to let people play with the writting of the module :), > > num_bits_int is left as an exercise to the interested readers (3 lines > > of Caml code using trivial bit shuffling). > > I am interested in knowing it, because I already searched that. > Without a loop or a predefined array of powers of two, I don't > know how to do that. Nor did I. I think there exists processors that do have an instruction to implement this function but this is not the general case: you need to write a loop or use a predefined array of powers of two or write a dichotomic algorithm or whatever... For instance: let num_bits_int n = let rec num_bits n = if n = 0 then 0 else succ (num_bits (n lsr 1)) in num_bits (abs n);; (No dichotomy, here. Experiments with a dichotomic algorithm is also interesting, but deciding which is faster is difficult since benchmarking is almost impossible: the results are too much dependant of the value of integers manipulated in the program.) Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA25450; Sun, 13 Oct 2002 15:25:25 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA25596 for ; Sun, 13 Oct 2002 15:25:24 +0200 (MET DST) Received: from fort-point-station.mit.edu (FORT-POINT-STATION.MIT.EDU [18.7.7.76]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9DDPN524748 for ; Sun, 13 Oct 2002 15:25:23 +0200 (MET DST) Received: from grand-central-station.mit.edu (GRAND-CENTRAL-STATION.MIT.EDU [18.7.21.82]) by fort-point-station.mit.edu (8.9.2/8.9.2) with ESMTP id JAA13944; Sun, 13 Oct 2002 09:25:22 -0400 (EDT) Received: from melbourne-city-street.mit.edu (MELBOURNE-CITY-STREET.MIT.EDU [18.7.21.86]) by grand-central-station.mit.edu (8.9.2/8.9.2) with ESMTP id JAA08965; Sun, 13 Oct 2002 09:25:21 -0400 (EDT) Received: from nerd-xing.mit.edu (NERD-XING.MIT.EDU [18.7.16.74]) by melbourne-city-street.mit.edu (8.9.2/8.9.2) with ESMTP id JAA00645; Sun, 13 Oct 2002 09:25:21 -0400 (EDT) Received: (from jfc@localhost) by nerd-xing.mit.edu (8.9.3) id JAA07471; Sun, 13 Oct 2002 09:25:21 -0400 (EDT) Message-Id: <200210131325.JAA07471@nerd-xing.mit.edu> To: Sven LUTHER cc: Ocaml Subject: Re: [Caml-list] Runtime overflow and what to do In-Reply-To: Your message of "Sun, 13 Oct 2002 11:52:16 +0200." <20021013095216.GA1949@iliana> Date: Sun, 13 Oct 2002 09:25:21 -0400 From: John Carr Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >Would it be much work to build a 64-bit integers target ? Try http://www.mit.edu/~jfc/ocaml-sparc64.tar.gz This tar file contains diffs and new code generation files for 64 bit SPARC. You will need to apply the .diff files with patch and move the other files into the appropriate directories (replacing the existing files without the "64" suffix), and probably do some editing of config/Makefile. I have not tested this on Linux. Contact me if you need help. If there is a lot of interest I can try to package this in a more immediately useful form. I stopped work on the 64 bit code generator before finishing the packaging. A note of caution: 64 bits is not necessarily better than 32. Unlike C, OCaml does not allow you to declare a 32 bit object in 64 bit mode, so memory use will approximately double. Performance executing out of cache will improve slightly, or significantly when using floating point, but the increased cache miss rate may make the program slower overall. ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA28699; Sun, 13 Oct 2002 18:15:00 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA28783 for ; Sun, 13 Oct 2002 18:14:59 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9DGEw528242; Sun, 13 Oct 2002 18:14:58 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA29139; Sun, 13 Oct 2002 18:14:58 +0200 (MET DST) Date: Sun, 13 Oct 2002 18:14:58 +0200 From: Xavier Leroy To: Pierre Weis Cc: Daniel de Rauglaudre , caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021013181458.A28677@pauillac.inria.fr> References: <20021013120456.D7639@verdot.inria.fr> <200210131029.MAA17141@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <200210131029.MAA17141@pauillac.inria.fr>; from pierre.weis@inria.fr on Sun, Oct 13, 2002 at 12:29:58PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > [Overflow checking in integer multiplication] > (* [lenght_of_int] is the maximum number of bits in an integer. *) > let length_of_int = Sys.word_size - 2;; > > let ( * ) n m = > if num_bits_int n + num_bits_int m < length_of_int > then n * m else raise (Overflow ("*", string_of_int n, string_of_int m)) > > (* [num_bits_int n] returns the number of significant bits of an > integer. *) Hmmph... this definition raises Overflow when computing min_int * 1, or (min_int / 2) * 2, while these products are actually representable within a machine integer... Apologies for nit-picking; I couldn't resist! - Xavier Leroy ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA29840; Sun, 13 Oct 2002 19:07:04 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA29779 for ; Sun, 13 Oct 2002 19:07:03 +0200 (MET DST) Received: from postfix2-1.free.fr (postfix2-1.free.fr [213.228.0.9]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9DH72529261 for ; Sun, 13 Oct 2002 19:07:03 +0200 (MET DST) Received: from montchapet (dijon-1-a7-62-147-71-215.dial.proxad.net [62.147.71.215]) by postfix2-1.free.fr (Postfix) with ESMTP id BFDCE14B for ; Sun, 13 Oct 2002 19:07:01 +0200 (CEST) Content-Type: text/plain; charset="iso-8859-1" From: Michel Quercia Reply-To: michel.quercia@prepas.org To: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Date: Sun, 13 Oct 2002 19:06:36 +0200 User-Agent: KMail/1.4.1 References: <20021013120456.D7639@verdot.inria.fr> <200210131029.MAA17141@pauillac.inria.fr> <20021013181458.A28677@pauillac.inria.fr> In-Reply-To: <20021013181458.A28677@pauillac.inria.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200210131906.36527.michel.quercia@prepas.org> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Le Dimanche 13 Octobre 2002 18:14, Xavier Leroy a écrit : > > [Overflow checking in integer multiplication] > > let ( * ) n m = > > if num_bits_int n + num_bits_int m < length_of_int > > then n * m else raise (Overflow ("*", string_of_int n, string_of_int m)) > Hmmph... this definition raises Overflow when computing > min_int * 1, or (min_int / 2) * 2, while these products are actually > representable within a machine integer... What about this one ? let mul a b = if a = 0 then 0 else let x = a*b in let q = x/a and r = x mod a in if (q = b) & (r = 0) then x else raise Overflow -- Michel Quercia 23 rue de Montchapet, 21000 Dijon http://michel.quercia.free.fr (maths) http://pauillac.inria.fr/~quercia (informatique) mailto:michel.quercia@prepas.org ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA05215; Mon, 14 Oct 2002 02:56:10 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA04997 for ; Mon, 14 Oct 2002 02:56:09 +0200 (MET DST) Received: from relay.pair.com (relay1.pair.com [209.68.1.20]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id g9E0u8D15542 for ; Mon, 14 Oct 2002 02:56:08 +0200 (MET DST) Received: (qmail 79330 invoked from network); 14 Oct 2002 00:56:06 -0000 Received: from node-d8e9cca2-sfo-onnet.worldcom.com (HELO checkerlap.d6.com) (216.233.204.162) by relay1.pair.com with SMTP; 14 Oct 2002 00:56:06 -0000 X-pair-Authenticated: 216.233.204.162 Message-Id: <4.3.2.7.2.20021013175437.032eb130@mail.d6.com> X-Sender: checker@mail.d6.com X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Sun, 13 Oct 2002 17:56:21 -0700 To: Xavier Leroy , John Carr From: Chris Hecker Subject: Re: [Caml-list] Runtime overflow and what to do Cc: Alessandro Baretta , Ocaml In-Reply-To: <20021013112815.K13771@pauillac.inria.fr> References: <200210121613.MAA27433@psi-phi.mit.edu> <3DA6A4ED.5050700@baretta.com> <200210121613.MAA27433@psi-phi.mit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > echo "print_int Sys.word_size" > /tmp/caml$$ > WORDSIZE=`ocaml /tmp/caml$$` > rm -f /tmp/caml$$ We clearly need a "-eval" switch to ocaml, like perl's -e/n/p. :) Chris ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA18517; Mon, 14 Oct 2002 11:46:51 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA18437 for ; Mon, 14 Oct 2002 11:46:50 +0200 (MET DST) Received: from favie.faith.gr.jp (favie.faith.gr.jp [61.127.175.250]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9E9km501305 for ; Mon, 14 Oct 2002 11:46:49 +0200 (MET DST) Received: from localhost (dhcp7.faith.gr.jp [192.168.1.17]) by favie.faith.gr.jp (8.9.3/8.9.3) with ESMTP id SAA27993; Mon, 14 Oct 2002 18:46:41 +0900 To: checker@d6.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do In-Reply-To: <4.3.2.7.2.20021013175437.032eb130@mail.d6.com> References: <200210121613.MAA27433@psi-phi.mit.edu> <20021013112815.K13771@pauillac.inria.fr> <4.3.2.7.2.20021013175437.032eb130@mail.d6.com> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20021014184615Q.garrigue@kurims.kyoto-u.ac.jp> Date: Mon, 14 Oct 2002 18:46:15 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Chris Hecker > > echo "print_int Sys.word_size" > /tmp/caml$$ > > WORDSIZE=`ocaml /tmp/caml$$` > > rm -f /tmp/caml$$ > > We clearly need a "-eval" switch to ocaml, like perl's -e/n/p. :) The above can be reduced to one line, without temporary file. In fact, I feel more like we would need a "-silent" option, to get rid of prompts and types (this is already the default with scripts). echo "print_int Sys.word_size;;" | \ ocaml | grep "^# ." | sed -e "s/# //" -e "s/- :.*//" A shorter but more specific approach is echo "Sys.word_size;;" | ocaml | grep "# -" | sed -e "s/.*= //" Jacques Garrigue ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA20977; Mon, 14 Oct 2002 13:02:54 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA19184 for ; Mon, 14 Oct 2002 13:02:53 +0200 (MET DST) Received: from yoda.planetinternet.be (anvers-smtp.planetinternet.be [195.95.30.152]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9EB2q504650 for ; Mon, 14 Oct 2002 13:02:52 +0200 (MET DST) Received: from janxp (u212-239-170-184.adsl.pi.be [212.239.170.184]) by yoda.planetinternet.be (Postfix) with ESMTP id 0010B3711C; Mon, 14 Oct 2002 13:02:45 +0200 (CEST) Message-ID: <008d01c27371$3de287f0$0100a8c0@janxp> From: "Scott J," To: "Jacques Garrigue" Cc: References: <200210121613.MAA27433@psi-phi.mit.edu><20021013112815.K13771@pauillac.inria.fr><4.3.2.7.2.20021013175437.032eb130@mail.d6.com> <20021014184615Q.garrigue@kurims.kyoto-u.ac.jp> Subject: Re: [Caml-list] Runtime overflow and what to do Date: Mon, 14 Oct 2002 13:02:46 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0089_01C27381.FDB66640" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk This is a multi-part message in MIME format. ------=_NextPart_000_0089_01C27381.FDB66640 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, I am following the discussion. But do not understand this. Is this a solution to eliminate overhead in integer arithmetic. Personnally I thought to try to capture the overflow status flag for the pentium processor on my Windows XP. Thx Scott ----- Original Message ----- From: Jacques Garrigue To: checker@d6.com Cc: caml-list@inria.fr Sent: Monday, October 14, 2002 11:46 AM Subject: Re: [Caml-list] Runtime overflow and what to do From: Chris Hecker > > echo "print_int Sys.word_size" > /tmp/caml$$ > > WORDSIZE=`ocaml /tmp/caml$$` > > rm -f /tmp/caml$$ > > We clearly need a "-eval" switch to ocaml, like perl's -e/n/p. :) The above can be reduced to one line, without temporary file. In fact, I feel more like we would need a "-silent" option, to get rid of prompts and types (this is already the default with scripts). echo "print_int Sys.word_size;;" | \ ocaml | grep "^# ." | sed -e "s/# //" -e "s/- :.*//" A shorter but more specific approach is echo "Sys.word_size;;" | ocaml | grep "# -" | sed -e "s/.*= //" Jacques Garrigue ------------------- 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 ------=_NextPart_000_0089_01C27381.FDB66640 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
 
I am following the discussion. But do = not=20 understand this. Is this a solution to eliminate overhead in integer=20 arithmetic.
 
Personnally I thought to try to capture = the=20 overflow status flag for the pentium processor on my Windows = XP.
 
Thx
 
Scott
----- Original Message -----
From:=20 Jacques Garrigue =
Sent: Monday, October 14, 2002 = 11:46=20 AM
Subject: Re: [Caml-list] = Runtime overflow=20 and what to do

From: Chris Hecker <checker@d6.com>
>=20 >        echo "print_int = Sys.word_size"=20 > /tmp/caml$$
> = >        =20 WORDSIZE=3D`ocaml /tmp/caml$$`
>=20 >         rm -f = /tmp/caml$$
>=20
> We clearly need a "-eval" switch to ocaml, like perl's = -e/n/p. =20 :)

The above can be reduced to one line, without temporary = file.
In=20 fact, I feel more like we would need a "-silent" option, to get = rid
of=20 prompts and types (this is already the default with = scripts).

echo=20 "print_int Sys.word_size;;" | \
ocaml | grep "^# ." | sed -e "s/# = //" -e=20 "s/- :.*//"

A shorter but more specific approach is

echo = "Sys.word_size;;" | ocaml | grep "# -" | sed -e "s/.*=3D = //"

Jacques=20 Garrigue
-------------------
To unsubscribe, mail caml-list-request@inria.fr= =20 Archives: http://caml.inria.fr
Bug=20 reports: http://caml.inria.fr/bin/caml= -bugs=20 FAQ: http://caml.inria.fr/FAQ/
Begin= ner's=20 list: http://groups.yaho= o.com/group/ocaml_beginners ------=_NextPart_000_0089_01C27381.FDB66640-- ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA27225; Mon, 14 Oct 2002 16:08:10 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA27004 for ; Mon, 14 Oct 2002 16:08:09 +0200 (MET DST) Received: from lobus.fungible.com (adsl-64-161-114-6.dsl.snfc21.pacbell.net [64.161.114.6]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9EE87514254 for ; Mon, 14 Oct 2002 16:08:08 +0200 (MET DST) Received: by lobus.fungible.com (Postfix, from userid 1000) id 2F0E980DE; Mon, 14 Oct 2002 07:08:06 -0700 (PDT) Date: Mon, 14 Oct 2002 07:05:57 -0700 From-Tims-Fingers: true To: garrigue@kurims.kyoto-u.ac.jp Cc: checker@d6.com, caml-list@inria.fr In-reply-to: <20021014184615Q.garrigue@kurims.kyoto-u.ac.jp> (message from Jacques Garrigue on Mon, 14 Oct 2002 18:46:15 +0900) Subject: Re: [Caml-list] Runtime overflow and what to do References: <200210121613.MAA27433@psi-phi.mit.edu> <20021013112815.K13771@pauillac.inria.fr> <4.3.2.7.2.20021013175437.032eb130@mail.d6.com> <20021014184615Q.garrigue@kurims.kyoto-u.ac.jp> Message-Id: <20021014140806.2F0E980DE@lobus.fungible.com> From: tim@fungible.com (Tim Freeman) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Jacques Garrigue >The above can be reduced to one line, without temporary file. >In fact, I feel more like we would need a "-silent" option, to get rid >of prompts and types (this is already the default with scripts). > >echo "print_int Sys.word_size;;" | \ >ocaml | grep "^# ." | sed -e "s/# //" -e "s/- :.*//" The following is simpler and works on Unix systems that have /dev/fd: echo "print_int Sys.word_size;;" | ocaml /dev/fd/0 I agree that a "-silent" option would be prettier than this, and it would work on systems that don't have /dev/fd. -- Tim Freeman tim@fungible.com GPG public key fingerprint ECDF 46F8 3B80 BB9E 575D 7180 76DF FE00 34B1 5C78 ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA31048; Mon, 14 Oct 2002 17:59:44 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA30754 for ; Mon, 14 Oct 2002 17:59:43 +0200 (MET DST) Received: from smtp2.libero.it (smtp2.libero.it [193.70.192.52]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9EFxhD04827 for ; Mon, 14 Oct 2002 17:59:43 +0200 (MET DST) Received: from dalamar.takhisis.org (62.98.147.134) by smtp2.libero.it (6.5.028) id 3DA310EC00294CCE for caml-list@inria.fr; Mon, 14 Oct 2002 17:59:41 +0200 Received: from lordsoth.takhisis.org (lordsoth.takhisis.org [192.168.1.119]) by dalamar.takhisis.org (8.12.6/8.12.6/Debian-6) with ESMTP id g9EFWNxQ001781 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=FAIL) for ; Mon, 14 Oct 2002 17:32:23 +0200 Received: from lordsoth.takhisis.org (lordsoth.takhisis.org [192.168.1.119]) by lordsoth.takhisis.org (8.12.6/8.12.6/Debian-6) with ESMTP id g9EFWM0X009632 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Mon, 14 Oct 2002 17:32:23 +0200 Received: (from zack@localhost) by lordsoth.takhisis.org (8.12.6/8.12.6/Debian-6) id g9EFWMHg009630 for caml-list@inria.fr; Mon, 14 Oct 2002 17:32:22 +0200 Date: Mon, 14 Oct 2002 17:32:22 +0200 From: Stefano Zacchiroli To: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021014153222.GC9043@cs.unibo.it> Mail-Followup-To: caml-list@inria.fr References: <200210121613.MAA27433@psi-phi.mit.edu> <20021013112815.K13771@pauillac.inria.fr> <4.3.2.7.2.20021013175437.032eb130@mail.d6.com> <20021014184615Q.garrigue@kurims.kyoto-u.ac.jp> <20021014140806.2F0E980DE@lobus.fungible.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20021014140806.2F0E980DE@lobus.fungible.com> User-Agent: Mutt/1.4i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, Oct 14, 2002 at 07:05:57AM -0700, Tim Freeman wrote: > echo "print_int Sys.word_size;;" | ocaml /dev/fd/0 Cool! Could you explain the trick? If I understood correctly /dev/fd/x is a pointer to /proc/self/fd/x, so the ocaml process try to read the script from /proc/self/fd/0 that is its standard input i.e. the output of the echo command. But why the standard ocaml toplevel message wont be printed? TIA, Cheers. -- Stefano Zacchiroli - undergraduate student of CS @ Univ. Bologna, Italy zack@cs.unibo.it | ICQ# 33538863 | http://www.cs.unibo.it/~zacchiro "I know you believe you understood what you think I said, but I am not sure you realize that what you heard is not what I meant!" -- G.Romney ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA31694; Mon, 14 Oct 2002 18:12:10 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA31304 for ; Mon, 14 Oct 2002 18:12:10 +0200 (MET DST) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9EGC9D05177 for ; Mon, 14 Oct 2002 18:12:09 +0200 (MET DST) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id g9EGC9B92878 ; Mon, 14 Oct 2002 18:12:09 +0200 (CEST) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.12.3/jb-1.1) id g9EGC7qQ029031 ; Mon, 14 Oct 2002 18:12:07 +0200 (MET DST) Date: Mon, 14 Oct 2002 18:12:07 +0200 (MET DST) From: Alain Frisch To: Stefano Zacchiroli cc: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do In-Reply-To: <20021014153222.GC9043@cs.unibo.it> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-milter (http://amavis.org/) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 14 Oct 2002, Stefano Zacchiroli wrote: > > echo "print_int Sys.word_size;;" | ocaml /dev/fd/0 > > But why the standard ocaml toplevel message wont be printed? Because the ocaml toplevel is quiet when it evaluates a script whose name is given on its command line. -- Alain ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA32584; Mon, 14 Oct 2002 18:48:46 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA00042 for ; Mon, 14 Oct 2002 18:48:45 +0200 (MET DST) Received: from relay.pair.com (relay1.pair.com [209.68.1.20]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id g9EGmgD05899 for ; Mon, 14 Oct 2002 18:48:44 +0200 (MET DST) Received: (qmail 59779 invoked from network); 14 Oct 2002 16:48:40 -0000 Received: from adsl-host-sf-228.apexworld.net (HELO checkerlap.d6.com) (66.114.212.228) by relay1.pair.com with SMTP; 14 Oct 2002 16:48:40 -0000 X-pair-Authenticated: 66.114.212.228 Message-Id: <4.3.2.7.2.20021014094010.03418790@mail.d6.com> X-Sender: checker@mail.d6.com X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Mon, 14 Oct 2002 09:49:00 -0700 To: Jacques Garrigue From: Chris Hecker Subject: [Caml-list] new ocaml switches (was Re: Runtime overflow and what to do) Cc: caml-list@inria.fr In-Reply-To: <20021014184615Q.garrigue@kurims.kyoto-u.ac.jp> References: <4.3.2.7.2.20021013175437.032eb130@mail.d6.com> <200210121613.MAA27433@psi-phi.mit.edu> <20021013112815.K13771@pauillac.inria.fr> <4.3.2.7.2.20021013175437.032eb130@mail.d6.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >The above can be reduced to one line, without temporary file. >In fact, I feel more like we would need a "-silent" option, to get rid >of prompts and types (this is already the default with scripts). Yes, I agree with -silent too! The only problem with using the pipe for everything is that Win2k's echo passes the quotes along to ocaml, so you need: echo Sys.word_size | ocaml Sadly, this means you'll need different commands on unix versus nt. -eval would avoid that problem to a large extent, except in that case quoting inside a string is different between the two systems, so you're stil kind of hosed. We probably need all of these switches! Would -silent not print anything that wasn't "printed" from the script, or would it only print the types? Maybe we need -Q for printing nothing (script must print to stdout), -qq for printing only values, and -q for printing types and values. Or something. And -e[val] for evaluating a string (should support multiple of them on a single command like perl does, which is handy). Not sure if there are equivalents for perl -n & -p that we'd want...ocaml is a bit heavy for quick scripting like this, so -eval might be enough. Chris ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA08900; Tue, 15 Oct 2002 21:15:12 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA08723 for ; Tue, 15 Oct 2002 21:15:12 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9FJFB524825; Tue, 15 Oct 2002 21:15:11 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA09316; Tue, 15 Oct 2002 21:15:10 +0200 (MET DST) From: Pierre Weis Message-Id: <200210151915.VAA09316@pauillac.inria.fr> Subject: Re: [Caml-list] Runtime overflow and what to do In-Reply-To: <20021013181458.A28677@pauillac.inria.fr> from Xavier Leroy at "Oct 13, 102 06:14:58 pm" To: xavier.leroy@inria.fr (Xavier Leroy) Date: Tue, 15 Oct 2002 21:15:10 +0200 (MET DST) Cc: pierre.weis@inria.fr, daniel.de_rauglaudre@inria.fr, caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > [Overflow checking in integer multiplication] > > > (* [lenght_of_int] is the maximum number of bits in an integer. *) > > let length_of_int = Sys.word_size - 2;; > > > > let ( * ) n m = > > if num_bits_int n + num_bits_int m < length_of_int > > then n * m else raise (Overflow ("*", string_of_int n, string_of_int m)) > > > > (* [num_bits_int n] returns the number of significant bits of an > > integer. *) > > Hmmph... this definition raises Overflow when computing > min_int * 1, or (min_int / 2) * 2, while these products are actually > representable within a machine integer... > > Apologies for nit-picking; I couldn't resist! > > - Xavier Leroy Well spotted, thank you very much! As a reward, note that your overflow test on addition raises overflow when computing (max_int + 1) - 1, while this sum is actually representable within a machine integer... Sure, computer arithmetics is tricky! Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA09400; Tue, 15 Oct 2002 21:25:56 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA09083 for ; Tue, 15 Oct 2002 21:25:55 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9FJPs525119; Tue, 15 Oct 2002 21:25:54 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA09742; Tue, 15 Oct 2002 21:25:54 +0200 (MET DST) Date: Tue, 15 Oct 2002 21:25:53 +0200 From: Xavier Leroy To: Pierre Weis Cc: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Message-ID: <20021015212553.A9185@pauillac.inria.fr> References: <20021013181458.A28677@pauillac.inria.fr> <200210151915.VAA09316@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <200210151915.VAA09316@pauillac.inria.fr>; from pierre.weis@inria.fr on Tue, Oct 15, 2002 at 09:15:10PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > As a reward, note that your overflow test on addition raises overflow > when computing (max_int + 1) - 1, while this sum is actually > representable within a machine integer... More nit picking: max_int + 1 isn't representable, and (machine) addition evaluates it to min_int, which is clearly a case of overflow. - Xavier Leroy ------------------- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA22936; Wed, 16 Oct 2002 10:24:28 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA22315 for ; Wed, 16 Oct 2002 10:24:27 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9G8OQ517387; Wed, 16 Oct 2002 10:24:26 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA22894; Wed, 16 Oct 2002 10:24:26 +0200 (MET DST) From: Pierre Weis Message-Id: <200210160824.KAA22894@pauillac.inria.fr> Subject: Re: [Caml-list] Runtime overflow and what to do In-Reply-To: <20021015212553.A9185@pauillac.inria.fr> from Xavier Leroy at "Oct 15, 102 09:25:53 pm" To: xavier.leroy@inria.fr (Xavier Leroy) Date: Wed, 16 Oct 2002 10:24:26 +0200 (MET DST) Cc: pierre.weis@inria.fr, caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > More nit picking: max_int + 1 isn't representable, and (machine) > addition evaluates it to min_int, which is clearly a case of overflow. Oups! Given that max_int has the intended definition, max_int + 1 is evidently an overflow ... Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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