IcarusLives wrote: ↑29 Mar 2018 19:32
My problem now lies with HOW do I write such a function? (The actual maths)? In the %getDistance% macro I posted above, it does contain somewhat of an "if" because it checks for the larger integer, but I don't know how it does that..
IcarusLives wrote: ↑30 Mar 2018 09:50
my problem is now solved!!
I have posted the complete creation of that exemplary function, so i'm unsure about what is the problematic part exactly, and why it now is solved.
Actually i assume that it may be have been unclear why "(-((x)>>31))" is the same as "(x < 0) ? 1 : 0", so i want to add that:
The "set/A" command internally uses a 32 bit signed integer datatype (signed integer means that the representation of the stored number is in
two's complement). In Java and other languages this datatype is referred to as "int".
A characteristic of this reprasentation is that every bit with index >= 32 of an int is "1" if this int is negative, else "0" (but it isn't stored explicitely, because you only have 32 bits available).
When performing an "arithmetic right shift" (>>) all bits of an int value are moved to the right a given number of bit positions including the not explicitely stored bits.
Therefore if you shift a given number (n) 31 times ("x>>31"), then the result is either "11111111111111111111111111111111" (which is the representation of "-1") for negative numbers, else "00000000000000000000000000000000" (which is "0").
Negating the above result (and adding parentheses around the "x" and the result to protect against odd sideeffects) gives you the "LssZero(x)" function.
The functions aGerman has posted, are also fiddling with the bit representation of the given int numbers to compute their result.
penpen