Commodore 64 basic doesn’t have min or max functions.
DEF (https://www.c64-wiki.com/wiki/DEF) would be the way to do this, but I don’t see how to write a performant version in a single expression (you can’t use IF as an expression. You could cast to float, compute some specially chosen sigmoid function, and round to int, but that’s slow)
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.
25 comments
[ 1.6 ms ] story [ 68.2 ms ] threadAstronaut with gun: Always has been
https://github.com/xoreaxeaxeax/movfuscator
"Intelligent C64s restore themselves to their former position of prominence. The singularity is near."
Seeing the c64 basic code produced (0) is only 6000 lines, a comparison to how a human would (re-)write the SIN() function is now feasible.
(0) https://github.com/nickbild/tflite_c64/blob/main/neural_net....
Edit: clarification
5550 if acc < -128 then acc = -128
5560 if acc > 127 then acc = 127
Anyone?
DEF (https://www.c64-wiki.com/wiki/DEF) would be the way to do this, but I don’t see how to write a performant version in a single expression (you can’t use IF as an expression. You could cast to float, compute some specially chosen sigmoid function, and round to int, but that’s slow)
A USR function (https://www.c64-wiki.com/wiki/USR) would work, but that’s cheating.
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
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.
(Apropos floating point, are you SURE it runs the same, Nick? those aren't exactly IEEE 754 floats you've got there!)