caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Int64 overflow checks
@ 2007-04-30 17:24 Raj B
  2007-05-01  2:41 ` [Caml-list] " skaller
  2007-05-01  2:45 ` Jon Harrop
  0 siblings, 2 replies; 3+ messages in thread
From: Raj B @ 2007-04-30 17:24 UTC (permalink / raw)
  To: caml-list

Hi

I am writing an implementation of the Python programming language in  
OCaml and ran into an interesting issue.

Python allows the programmer to implicitly perform arbitrary-sized  
integer operations by switching internally between its 'int' and  
'long' types. (which seems to translate to OCaml's int64 and BigInt).

I found an OCaml library on a mailing list which checks for overflow  
in 'normal' 32-bit integer operations. How can I check for overflows  
in int64 operations so I can switch to big-int if that happens?


Thanks!
Raj



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Int64 overflow checks
  2007-04-30 17:24 Int64 overflow checks Raj B
@ 2007-05-01  2:41 ` skaller
  2007-05-01  2:45 ` Jon Harrop
  1 sibling, 0 replies; 3+ messages in thread
From: skaller @ 2007-05-01  2:41 UTC (permalink / raw)
  To: Raj B; +Cc: caml-list

On Mon, 2007-04-30 at 12:24 -0500, Raj B wrote:
> Hi
> 
> I am writing an implementation of the Python programming language in  
> OCaml and ran into an interesting issue.
> 
> Python allows the programmer to implicitly perform arbitrary-sized  
> integer operations by switching internally between its 'int' and  
> 'long' types. (which seems to translate to OCaml's int64 and BigInt).
> 
> I found an OCaml library on a mailing list which checks for overflow  
> in 'normal' 32-bit integer operations. How can I check for overflows  
> in int64 operations so I can switch to big-int if that happens?

you use basic maths. For example on addition, you expect 

	a + b > a
	a + b > b

and one of these will be false if you got overflow
(something like that).


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Int64 overflow checks
  2007-04-30 17:24 Int64 overflow checks Raj B
  2007-05-01  2:41 ` [Caml-list] " skaller
@ 2007-05-01  2:45 ` Jon Harrop
  1 sibling, 0 replies; 3+ messages in thread
From: Jon Harrop @ 2007-05-01  2:45 UTC (permalink / raw)
  To: caml-list

On Monday 30 April 2007 18:24, Raj B wrote:
> Hi
>
> I am writing an implementation of the Python programming language in
> OCaml and ran into an interesting issue.
>
> Python allows the programmer to implicitly perform arbitrary-sized
> integer operations by switching internally between its 'int' and
> 'long' types. (which seems to translate to OCaml's int64 and BigInt).
>
> I found an OCaml library on a mailing list which checks for overflow
> in 'normal' 32-bit integer operations. How can I check for overflows
> in int64 operations so I can switch to big-int if that happens?

Sounds like a premature optimization. Just use Big_int for everything to start 
with...

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journal/?e


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-05-01  2:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-30 17:24 Int64 overflow checks Raj B
2007-05-01  2:41 ` [Caml-list] " skaller
2007-05-01  2:45 ` Jon Harrop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).