Re: why are floats flakey?
Re: why are floats flakey?
- Subject: Re: why are floats flakey?
- From: Ondra Cada <email@hidden>
- Date: Tue, 25 May 2004 15:00:48 +0200
Raphael,
On 25.5.2004, at 14:30, Raphael Sebbe wrote:
>
Time = TimeValue / TimeScale
>
That way, any rational number can be used
Not really, for TimeValue and TimeScale are limited too. Since the
computer is a finite thing, whilst numbers (even integers) happen to be
inifinite, you just cannot express "any number" from anything (but a
finite subset, like an interval of integers). There's an infinite
number of rationals in any interval (of a non-trivial length).
That's also the final reason why *any* computer number type is
"flakey": any type, whatever way it is defined, can express only a
finite number of values. All the others--*much* more of them!, an aleph
zero of rationals or integers, an aleph one of reals--, therefore, have
to be either refused (normally done for those exceeding some range) or
rounded (normally done for those inside the range, which cannot be
expressed).
Back to the original question: this is, actually, computing 101:
floats/doubles and alike are fit to be used in sci algorithms, *not*
expressing things like money amounts, which need to be precise. For the
latter, things like NSDecimalNumber, or in plain C an integer with an
explicit scale, are to be used.
---
Ondra Hada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.