|
Even / Odd Displaying 1-5 of 5 total.
1
TheGerf
|
Is there a function, or a formula to use in Verge that will tell me if a number is odd or even?
TheGerf, not just any gerf.
Posted on 2001-05-23 23:33:09
|
vecna
|
try:
int odd, number;
odd = number % 2;
if (odd) blah
else //even. blahg.
etc.
Posted on 2001-05-24 01:31:44
|
grenideer
|
but you can make one.
Say verge rounds up (that is, 3/2=2). Then you can make a function checking the tested number and one number above it. If the answer to the second problem is the same, then the original number is odd, otherwise even.
Or you can divide by two, then multiply the answer by two. If the answer is the same number as the original, then the number is even, otherwise odd.
I'm just thinking out loud without any plan but these are two viable options taking advantage of the fact that verge uses only real numbers. Come to think of it, I'm not sure if verge rounds up or down though.
Posted on 2001-05-24 01:33:32
|
Ear
|
First of all, ever hear of modulo? The modulo operator returns the the remainder after division.
So, if a is evenly divisable by two, then a % 2 would return 0. If not, it would return 1.
Also, v2 doesn't exactly round because it simply truncates the number. (What really is happening is that v2 simply isn't using the remainder, which is stored in a different register. Modulo divides the same way, but instead of returing the result, it returns the stored remainder.)
Here's what I mean:
5 / 2 = 2
-5 / -2 = 2
-5 / 2 = -2
5 / -2 = -2
- Ear "It's time for the human race to enter the solar system."
Posted on 2001-05-24 14:29:55
|
TheGerf
|
asdf
TheGerf, not just any gerf.
Posted on 2001-05-24 19:02:56
|
Displaying 1-5 of 5 total.
1
|
|