caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Post Office!~/sentmail <fjr6b@cms.mail.virginia.edu>
To: caml-list@inria.fr
Subject: [Caml-list] Integer to floating point conversion errors
Date: Fri, 9 Nov 2001 18:39:58 -0500 (EST)	[thread overview]
Message-ID: <Pine.GSO.4.32.0111091836540.16016-100000@config.mail.Virginia.EDU> (raw)

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


             reply	other threads:[~2001-11-11 10:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-09 23:39 Post Office!~/sentmail [this message]
2001-11-11 13:33 ` Berke Durak
2001-11-11 15:35   ` Post Office!~/sentmail
2001-11-11 16:34     ` Remi VANICAT

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.4.32.0111091836540.16016-100000@config.mail.Virginia.EDU \
    --to=fjr6b@cms.mail.virginia.edu \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).