• 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: mark <email@hidden>
  • Date: Sat, 01 Jan 2005 16:48:24 -0800

You're right--while I already had some checks that should help reduce the
likelyhood of these #s, there's no reason to spend extra time avoiding a
direct check.
> From: John Stiles <email@hidden>
> Why are you dodging around NaN/inf's like they're made of Kryptonite?
> They're easy to check for. I'm just trying to show you that they do
> exist and you have to be ready for them.
>
> bool NumberIsOK( float x )
> {
> return !isnan(x) && (x > -INFINITY) && (x < INFINITY);
> }
>
> ...
> x = NSScanner or atof or whatever;
> if( !NumberIsOK( x ) )
> {
> NSAlert( @"Invalid number entered" ... ); // <-- do something nicer
> return false;
> }
Thanks for the code snippet!

> Once you've got your double or float, if you want to convert it to
> integer, just figure out the minimum units you want--say, 1/1000--and
> round to it. i.e.:
>
> int i = rint( (x * 1000) + 0.5 );
>
Yes, this is what I'm doing alreadyŠ
> You're overanalyzing and making things more complicated than they have
> to be.
>
SighŠI think you're rightŠ

 _______________________________________________
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

References: 
 >Re: Accurate decimal numbers? (From: John Stiles <email@hidden>)

  • Prev by Date: Re: Accurate decimal numbers?
  • Next by Date: Cocoa Bindings and Structures
  • Previous by thread: Re: Accurate decimal numbers?
  • Next by thread: Re: Accurate decimal numbers?
  • Index(es):
    • Date
    • Thread