Re: Float comparison
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Sat, 25 Apr 2009 11:26:28 -0700
James Kuyper <jameskuyper@xxxxxxxxxxx> writes:
christian.bau wrote:
...
With the model that representation = real number, the analysis is
quite simple. For example, when using IEEE 754 arithmetic, you perform
the arithmetic with real numbers giving the exact real result, then
apply a simple rounding algorithm that produces a real number that has
a representation, and that is the representation of the result.
There is, in general, no way to "perform the arithmetic ... giving the
exact real result", and as a result there's no rounding step,
either. In general, what you have to do is implement an algorithm that
inherently produces only an a approximation to the exact result, and
what you have to do to conform to IEEE 754 is design the algorithm to
ensure that the approximation is sufficiently good.
Actually, it is possible to "perform the arithmetic ... giving the
exact real result", though it can be resource-intensive. All
mathematical expressions expressible in C yield rational numbers. To
get exact real results corresponding to those expressions, you can use
a representation consisting of two arbitrary-precision integers. This
doesn't work for expressions involving functions that yield irrational
results (sqrt, sin, et al), but it can work for everything involving
literals and built-in operators.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: Float comparison
- From: Flash Gordon
- Re: Float comparison
- References:
- Float comparison
- From: Alessio Ribeca
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Richard Heathfield
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: nick_keighley_nospam
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Ben Bacarisse
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: christian.bau
- Re: Float comparison
- From: James Kuyper
- Float comparison
- Prev by Date: Re: ASSIGNMENT
- Next by Date: Re: byte data manipulation
- Previous by thread: Re: Float comparison
- Next by thread: Re: Float comparison
- Index(es):
Relevant Pages
|