 # Even( and Odd( functions?

I find I occasionally need to determin if a value is odd or even when coding and use the mod operator to determine this state. I think a simple couple of functions would come in handy for this purpose to simplify things.

even(value)

Returns true (-1) if the value is even or false (0) if value is odd.

``````registercustomfunction "EVEN(",1,{?(•1 mod 2=0,-1,0)}
``````

odd(value)

Returns true (-1) if the value is odd or false (0) if value is even

``registercustomfunction "ODD(",1,{?(•1 mod 2≠0,-1,0)}``

I think this needs to be modified to work with negative numbers as well as positive.

`-3 mod 2` for example, returns -1, so for the odd function, you might want to use

`registercustomfunction "ODD(",1,{?(•1 mod 2≠0,-1,0)}`

Good catch Dave. I seldom work with negative numbers other than tax time. I corrected the Odd( function above. Thanks

You had me going there for quite a while – I was staring at your version vs. Dave’s and could not figure out what the difference was! Because there wasn’t any difference, you corrected it. I’ll think about putting these into Panorama, however, i think the names iseven( and isodd( might be better, thoughts?

A rose by any other name… your call. (x mod 2)-1 is -1 if x is even and 0 if x is odd. -(x mod 2) is -1 if x is odd and 0 if x is even.

There needs to be a test that x is an integer.

iseven—> ?(2*int(∆/2)=∆,-1,0) is what I’ve always used, where ∆ is the value being tested.
This returns -1 for all even integers, and 0 for all non integers and odd numbers. Zero tests as even, which is correct for my situation but this might anger some mathematicians.

chris