Re: Accurate decimal numbers?
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.
>
SighI 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