4 ms·
127. I don’t think bit masking alone will get you there. You want to map anything over 0x80 to 0x7F. I think you can do something like x + (x < -127) * (x
by Someone 4y ago
127.
I don’t think bit masking alone will get you there. You want to map anything over 0x80 to 0x7F.
I think you can do something like
x + (x < -127) * (x + 127) + (x > 127)) * (x - 127)
^^^^^^^^^^^^^^^^^^^^^^
can give you clamping, but haven’t checked it ((x < -127) is minus one for true or zero for false, so the part marked ^^^^ subtracts x + 127 from x when it is too low, and that’s equivalent to subtracting x (yielding zero) and subtracting -127 (yielding -127). The other part is similar, but for values that are too high.
That expression can be put in a DEF FN.