caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <bhurt@spnz.org>
To: Zeno Lee <zeno.lee@earthlink.net>,
	Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] weird floating poing behavior on windows
Date: Fri, 2 Apr 2004 15:58:59 -0600 (CST)	[thread overview]
Message-ID: <Pine.LNX.4.44.0404021548270.25700-100000@localhost.localdomain> (raw)
In-Reply-To: <008101c418ea$3ff43780$6401a8c0@xp>

On Fri, 2 Apr 2004, Zeno Lee wrote:

> Can anyone tell me what's going on here?  Is this a known issue on windows? 

This is a known issue with floating point numbers.  Take a class or get a 
book on numerical analysis is my recommendation.

Here's the basic problem: let's assume our machine works in base 10 
instead of base 2, and that floating point numbers only hold 4 decimal 
digits.  So how does the machine represent 1.0/3.0?  It can't, not 
exactly.  It's instead represented as 0.3333.  Four digits of accuracy, 
remember?  So we take this number, and multiply it by 3.0, we get not the 
expected answer of 1.0, but instead 0.3333*3, or 0.9999.  Opps.  

Now, in finite precision binary fp, we can't exactly represent 1/5th, just
like we can't exactly represent 1/3 in finite precision decimal.  The
system gets "close", but can't do it exactly, so every once in a while you
get an answer a little larger or smaller than expected.  Even worse, these
small errors can accumulate, snowballing into huge errors.  A lot of very
intelligent people spend years making algorithms in which these errors
tend to cancel each other out instead of accumulating- so that if this 
calculation comes out a little high, the next calculation will likely come 
out a little low.  You can get a PhD and spend your life doing this, and a 
lot of people have.  My recommendation is to simply get a book, and do 
things the way they tell you to.

-- 
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 
Brian

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2004-04-02 20:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-02 13:41 [Caml-list] failwith, raise and type inference Paul Guyot
2004-04-02 13:49 ` Frederic van der Plancke
2004-04-02 13:56   ` Paul Guyot
2004-04-02 13:51 ` Nicolas Cannasse
2004-04-02 13:59 ` Correnson Loïc
2004-04-02 14:09 ` Luc Maranget
2004-04-02 19:39   ` [Caml-list] weird floating poing behavior on windows Zeno Lee
2004-04-02 20:03     ` Greg Bacon
2004-04-02 20:07     ` David Brown
2004-04-02 20:31       ` Zeno Lee
2004-04-02 20:50         ` Pierre Weis
2004-04-02 22:01         ` Brian Hurt
2004-04-02 21:58     ` Brian Hurt [this message]
2004-04-02 20:28   ` [Caml-list] failwith, raise and type inference Pierre Weis
2004-04-05 22:52     ` Ker Lutyn
2004-04-06  1:07       ` Jacques Garrigue
2004-04-06  5:23         ` Issac Trotts
2004-04-06 15:15           ` skaller
2004-04-06  1:15       ` Christophe TROESTLER
2004-04-06  7:05         ` skaller
2004-04-06 11:29           ` Eric C. Cooper
2004-04-09  7:18           ` Christophe TROESTLER
2004-04-09  7:32             ` Xavier Leroy
2004-04-09  8:03               ` skaller

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.LNX.4.44.0404021548270.25700-100000@localhost.localdomain \
    --to=bhurt@spnz.org \
    --cc=caml-list@inria.fr \
    --cc=zeno.lee@earthlink.net \
    /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).