Re: [OT] somebody could explain this? - Mailing list pgsql-hackers

From Otto Hirr
Subject Re: [OT] somebody could explain this?
Date
Msg-id C4A5FA40873548F0A4362F015AEB0084@olabinc.com
Whole thread Raw
In response to Re: [OT] somebody could explain this?  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Responses Re: [OT] somebody could explain this?
List pgsql-hackers
Lets start with an agreed upon expert, Knuth.
The art of computer programming. Vol2,Seminumerical Algorithms.Ed2.
pg682: Precision: The number of digits in a representation.
pg212: Section: Accuracy of floating point numbers.
"A rough (but reasonably useful) way to express the behavior of
floating point arithmetic can be based upon the concept of
"significant figures" or relative error."

The float point rep is built of a exponent and fractional part.
(Note mantissa means "a worthless addition"(pg199)

Most notably, the IEEE rep, either single or double, most certainly
has the ability to store the EXACT value for 0.1.

The issue is how to REPRESENT an exact value in the computer.
Some values may be represented exactly. Some values may not.
The tricky part is then operations on these values. We may have
exact representation of two values, then applying an operation
that results in a theoretical value that can only have an
approximate representation. Accuracy deals with the difference
between the theoretical exact value and our ability to
represent it.

Note that Knuth's observation about add/sub v. mul/div:

"Roughly speaking, the operations of floating point multiplication
and division do not magnify the relative error by very much; but
floating point subtraction of nearly equal quantities (and floating
point addition, u+v, where u is nearly equal to -v) can very greatly
increase the relative error."

Surprised?

Things to consider:
Is the value I want to represent have, shall we say, a limit to
the number of digits required to fully define its value,
eg 0.5, 0.9987

Is the value I want to represent have no limit to the number of
digits, eg pi, etc.

Does my representation provide a value that is within acceptable
limits of error, between the rep and actual value.

!Are the operations that I am performing introducing greater
amounts of relative error!

Break out the old computer book/math book and review...
Lets not assume or re-invent the wheel.

..Otto

> I think the crucial point is that the common IEEE floating point
> formats are unable to store an EXACT representation of common
> decimal fractions (such as .1) -- they can only store an
> APPROXIMATION.
> 
> >>> Peter Eisentraut <peter_e@gmx.net>  >>>
> Csaba Nagy wrote:
> > [snip]
> >
> > > Floating points numbers are accurate but not precise.
> >
> > OK, now this one beats me... what's the difference between 
> "accurate"
> > and "exact" ? I thought both mean something like "correct", but
> > precise refers to some action and accurate applies to a situation or
> > description...
> 
> Accurate means close to the real value, precise means having a lot of 
> detail.
> 
> So 3 is more accurate than 4 as a representation of "Pi", but 
> both are 
> not very precise.
> 
> 5.32290753057207250735 is a very precise representation of "Pi" but 
> totally inaccurate.
> 
> This also means that the statement at the top is wrong.  It should be 
> the other way around.
> 
> -- 
> Peter Eisentraut
> http://developer.postgresql.org/~petere/
> 
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
> 
> 
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 6: explain analyze is your friend
> 



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Reducing the overhead of NUMERIC data
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Reducing the overhead of NUMERIC data