• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: why are floats flakey?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: why are floats flakey?
      • From: Raphael Sebbe <email@hidden>
References: 
 >why are floats flakey? (From: justin webster <email@hidden>)
 >Re: why are floats flakey? (From: Raphael Sebbe <email@hidden>)

  • Prev by Date: Re: why are floats flakey?
  • Next by Date: installing a product with xcode
  • Previous by thread: Re: why are floats flakey?
  • Next by thread: Re: why are floats flakey?
  • Index(es):
    • Date
    • Thread