caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Integer to floating point conversion errors
@ 2001-11-09 23:39 Post Office!~/sentmail
  2001-11-11 13:33 ` Berke Durak
  0 siblings, 1 reply; 4+ messages in thread
From: Post Office!~/sentmail @ 2001-11-09 23:39 UTC (permalink / raw)
  To: caml-list

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
                end);;
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: 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


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

end of thread, other threads:[~2001-11-11 16:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-09 23:39 [Caml-list] Integer to floating point conversion errors Post Office!~/sentmail
2001-11-11 13:33 ` Berke Durak
2001-11-11 15:35   ` Post Office!~/sentmail
2001-11-11 16:34     ` Remi VANICAT

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).