• 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: Accurate decimal numbers?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accurate decimal numbers?


  • Subject: Re: Accurate decimal numbers?
  • From: John Stiles <email@hidden>
  • Date: Fri, 31 Dec 2004 17:08:38 -0800

On Dec 31, 2004, at 4:42 PM, Brendan Younger wrote:

Avoiding int<->float conversions is always best. I'd suggest if(0.0 == fabs(x - rint(x)), but I don't claim to be the expert on this.

If you're going to compare against zero, why use absolute value?
0 == -0.
I'd probably use "floor(x) == x"; since it makes a function call, it's not the fastest technique possible, but the intent is crystal clear and in 99.9% of cases, that's more important.
(After dropping the fabs and algebraic simplification, your version is just "rint(x) == x", basically the same thing.)
 _______________________________________________
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: Accurate decimal numbers?
      • From: mark <email@hidden>
References: 
 >Accurate decimal numbers? (From: Mark Dawson <email@hidden>)
 >Re: Accurate decimal numbers? (From: Brendan Younger <email@hidden>)

  • Prev by Date: Re: How to add a URL-tile to the Dock from an Installer?
  • Next by Date: Re: Accurate decimal numbers?
  • Previous by thread: Re: Accurate decimal numbers?
  • Next by thread: Re: Accurate decimal numbers?
  • Index(es):
    • Date
    • Thread