SPIN2 min/max operations on unsigned values missing in language?
rogloh
Posts: 5,787
I just noticed in SPIN2 that it doesn't appear to have an operator to find the min or max of a pair of values using unsigned integers, only signed is defined:
Was there a reason why the unsigned version wasn't also in the language? COG space? I sort of wonder if the language could be extended to also use the +#> and +#< forms for determining MIN and MAX of two unsigned values, like the unsigned divide and comparisons use, or does that break the SPIN2 interpreter size?
In PASM, it would just need to use FLE and FGE instructions instead of FLES and FGES.
I guess we can still do the following for now but this workaround may need to break apart a potentially more complex assignment or test (which may otherwise be capable of more conveniently using a min or max of two unsigned values directly as a term) by using an intermediate and more verbose if statement instead like this:
Was there a reason why the unsigned version wasn't also in the language? COG space? I sort of wonder if the language could be extended to also use the +#> and +#< forms for determining MIN and MAX of two unsigned values, like the unsigned divide and comparisons use, or does that break the SPIN2 interpreter size?
In PASM, it would just need to use FLE and FGE instructions instead of FLES and FGES.
I guess we can still do the following for now but this workaround may need to break apart a potentially more complex assignment or test (which may otherwise be capable of more conveniently using a min or max of two unsigned values directly as a term) by using an intermediate and more verbose if statement instead like this:
' For limiting a to MIN(a,b) if a+>b a := b ' For setting a to MAX(a,b) if a+<b a := b ' For assigning MIN(a,b) to c if a +< b c := a else c := b ' For assigning MAX(a,b) to c if a +> b c := a else c := b
Comments
Yes, except in cases of unsigned operators.
Instead....
c := a +> b ? a : b
-Phil
True, but it can create a cascade of complexity when something falls outside of normal handling.
-Phil
Phil, if I were to elaborate, the cascade would begin.
Yeah I posted something else about ternary operators last night and also then made the same connection. This will let us put any unsigned min/max calculations into other complex expressions which is preferable over breaking them up, so I'm happy with that solution. Nice!
Wait, who invited unsigned operators to this party?
That was a mistake...