Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Integer to floating point conversion errors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] Integer to floating point conversion errors
Post Office!~/sentmail <fjr6b@cms.mail.virginia.edu> writes:

> On Sun, 11 Nov 2001, Berke Durak wrote:
> 
> Pardon me, I wasn't clear.  Since incr and mult are assumed to be
> positive, seed should always be positive.  Therefore a mod of C by a
> positive number should always be positive.  The problems arise like the
> following:
> 
> # seeded#raw;;
> - : float = -0.011235290207
> # seeded#getseed;;
> - : int = 12063801
> # float ( seeded#getseed );;
> - : float = 12063801
> # float ( seeded#getseed ) /. float( 1073741824 );;
> - : float = -0.011235290207
> # float (1073741824);;
> - : float = -1073741824

# max_int;;
- : int = 1073741823

so your int is bigger than max_int, and caml silently transform it in 
-1073741824 (there should be a warning)
float ( seeded#getseed ) /. 1073741824.0
should work.

-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr