Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accurate decimal numbers?



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

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



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.