[Haskell-cafe] Matters of precision
droundy at darcs.net
Fri Aug 10 12:29:37 EDT 2007
On Thu, Aug 09, 2007 at 06:47:04PM +0100, Andrew Coppin wrote:
> First of all, currently I'm just using Double to represent coordinates.
> Can anybody tell me what the smallest value you can represent with one
> is? (Not including denormals.)
The smallest number is around 1e-300, but the smallest fractional
difference (which is probably what's biting you) is around 1e-15.
> Next up, at some point I'm going to need more precision than a Double
> can give me. (But, obviously, I still want the thing to go as fast as
> humanly possible.) In particular, I do NOT want to go into "infinite"
> precision. (E.g., exact arithmetic with arbitrary fractions.) I want to
> be able to make the precision arbitrarily high, but still finite and
> fixed. (The idea being that the further you zoom in, the more the
> computer turns up the precision.) Is there anything useful for this in
> the standard libraries? Or will I have to write something?
I suspect you can acheive this by changing your algorithm and data
structures, rather than your floating point type. If you store relative
positions rather than absolute positions, then as your fractal gets smaller
and smaller, your precision should continue to be good. Danger only arises
when you try to compare (or subtract) two doubles whose difference is much
smaller than their magnitude. By definition, fractal geometries don't
require you to do this.
Department of Physics
Oregon State University
More information about the Haskell-Cafe