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)}
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?
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.