Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2001-11-11 (10:59)
From: Post Office!~/sentmail <fjr6b@c...>
Subject: [Caml-list] Integer to floating point conversion errors
I am getting negative results when I convert large integers to floating
point.  This happens on both i386 and my G4 laptop with OCaml 3.02.  The
code in question is this:

class prng = fun m i mo ->
        (fun (sd:int) ->
                object (self)
                        val mutable seed = sd
                        val mult = m
                        val incr = i
                        val modu = mo
                        method getseed = seed
                        method raw = (seed <- (seed*mult+incr)mod modu);
                                        float seed /. float modu
                        method gen low high = let range = high -. low in
                                        (self#raw *. range) +. low
let myprng = new prng 274177 13 1073741824;;
let seeded = myprng 44;;

Then use seeded#raw a few times: the results are quite often negative,
which they should not be so far as I can see.

Can anyone advise me how to fix this?

Fred Ross
High Energy Physics Lab
University of Virginia
Bug reports:  FAQ:
To unsubscribe, mail  Archives: