Re: Float comparison



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"
.



Relevant Pages

  • Re: Float comparison
    ... For example, when using IEEE 754 arithmetic, you perform ... apply a simple rounding algorithm that produces a real number that has ... a representation, and that is the representation of the result. ... reciprocal of a googolplex to a googolplex and have the representation different ...
    (comp.lang.c)
  • Re: Float comparison
    ... For example, when using IEEE 754 arithmetic, you perform ... apply a simple rounding algorithm that produces a real number that has ... a representation, and that is the representation of the result. ... reciprocal of a googolplex to a googolplex and have the representation different ...
    (comp.lang.c)
  • Re: Float comparison
    ... For example, when using IEEE 754 arithmetic, you perform ... apply a simple rounding algorithm that produces a real number that has ... a representation, and that is the representation of the result. ... reciprocal of a googolplex to a googolplex and have the representation different ...
    (comp.lang.c)
  • Re: Float comparison
    ... For example, when using IEEE 754 arithmetic, you perform ... apply a simple rounding algorithm that produces a real number that has ... a representation, and that is the representation of the result. ... reciprocal of a googolplex to a googolplex and have the representation different ...
    (comp.lang.c)
  • Re: Quantales, Dioids and Formal Language (was: Power Monoid)
    ... The structure that is a dioid is P, itself; not the generic monoid ... by the very natural of context-free and general ... The relation to the algebraic representation is that the mapping may ... the q's are regular expressions formed of context-free ...
    (sci.math.research)