Re: "make positive" function
Re: "make positive" function
- Subject: Re: "make positive" function
- From: John Stiles <email@hidden>
- Date: Mon, 11 Sep 2006 11:37:08 -0700
#include <math.h>
void myFn()
{
//...
double positiveValue = floor( abs(value) + 0.5f );
}
Modulus isn't what you want. Modulus in C doesn't even make things
positive (which bugs me, but there is a workaround).
I don't see that sqrt(x*x) will work; it will become positive but not
integral. And it's waaaaay more work :)
On Sep 11, 2006, at 11:28 AM, Mike Abdullah wrote:
I'm not a C expert, so apologies for this one:
Basically, I want to take a double and get its closest positive
integer. I haven't been able to find anything that does what I
want (I have a feeling it might be a modulus?).
Anyway, it seems to me I have 3 options:
1. There is an existing, simple function in C - if so can someone
tell me what it is ? :)
2. Do the incredibly clunky, square variable, find square root
3. Write my own function.
Mike.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40blizzard.com
This email sent to 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