Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Runtime overflow and what to do
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sven LUTHER <luther@d...>
Subject: Re: [Caml-list] Runtime overflow and what to do
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