• 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: Float behaviour
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Float behaviour


  • Subject: Re: Float behaviour
  • From: Jim Hamilton <email@hidden>
  • Date: Mon, 22 Aug 2005 13:27:11 -0400


On Aug 22, 2005, at 1:19 PM, Richard Gray wrote:

I'm new to Cocoa and Objective C and have just been running through
the Currency Converter example on developer.apple.com.  That seemed
fairly straightforward and the application runs, but I notice some
strange behaviour in it that I haven't seen mentioned anywhere else.

If I were to convert $1 at an exchange rate of 1.2, I'd expect to get
1.2 units of the new currency yes?  According to my currency converter
however, 1 x 1.2 = 1.200000047683716

Can someone explain this behaviour to me and how to avoid it?  I wrote
another small app that takes an number entered into 1 text field and
writes it to another when I press a button.  It shows the same
behaviour.

I'm sure there's a simple explanation for this, but I'm just not
seeing at the moment.


Of course, this has nothing to do with Cocoa, but with floating-point arithmetic.


<http://docs.sun.com/source/806-3568/ncg_goldberg.html>
"What Every Computer Scientist Should Know About Floating-Point Arithmetic"


Jim H
--
Jim Hamilton

email@hidden
email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Float behaviour
      • From: Richard Gray <email@hidden>
References: 
 >Float behaviour (From: Richard Gray <email@hidden>)

  • Prev by Date: Float behaviour
  • Next by Date: Re: Clearing NSTableView on unbind
  • Previous by thread: Float behaviour
  • Next by thread: Re: Float behaviour
  • Index(es):
    • Date
    • Thread