Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] failwith, raise and type inference
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] weird floating poing behavior on windows
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