When setting the values for signals in constant combinators using the new 0x prefix it works as I'd expect (as in all 32 bits are set to the entered value). The same does not occur when setting the constant value in arithmetic / decider combinators.
If I try to set the constant to a value which includes the sign bit, e.g. 0x80000000 (= -2147483648) or 0xffffffff (= -1) it seems to clamp the value to the largest possible 32 bit integer 2147483647 (= 0x7fffffff) instead.
This is inconsistent behavior, compared to setting the signal values in the constant combinator.
Thus I assume this to be a bug.
BP with a small setup, which showcases the issue:
[2.0.20] Base 16 number with highest bit set saturates if used as constant in arithmetic and decider combinator
Re: [2.0.20] Base 16 number with highest bit set saturates if used as constant in arithmetic and decider combinator
This is an interesting case because having a positive number entry roll over to a negative integer can be either very useful or very unexpected depending on the circumstance. I agree it should be made consistent between combinators.
My mods: Multiple Unit Train Control, Smart Artillery Wagons
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
-
- Fast Inserter
- Posts: 220
- Joined: Fri Aug 12, 2016 10:22 pm
- Contact:
Re: [2.0.20] Base 16 number with highest bit set saturates if used as constant in arithmetic and decider combinator
That there's a difference between base10 and base16 behavior is the real problem. In other words, if they clamped it to positives on all three combinators--while now consistent--would be incorrect as it forces a user to use base10 for negative numbers.
Re: [2.0.20] Base 16 number with highest bit set saturates if used as constant in arithmetic and decider combinator
I do not believe that there being a difference in behavior for the different bases is an issue. As robot256 said, either behavior can be useful depending on the context you use it in. Think of the following 2 examples:That there's a difference between base10 and base16 behavior is the real problem.
If I want to use only the natural number aspect of the signals (e.g. addition, multiplication, division, mod, etc...) I will most likely enter the numbers in base 10. In this case it makes more sense in my mind that numbers do not wrap around but instead clamp to the largest / smallest possible (depending on the sign), as seeing a base 10 number mod 2^32 always looks quite weird. Clamping would at least preserve the sign of the originally entered value. This usecase is also what I assume the most common one when users work with combinators.
On the other hand, whenever I want to do exact bit manipulation (e.g. using bitwise and, or, xor in the arithmetic combinators) I'm astutely aware of the the underlying int32 format which is used by the signals. In this instance I'd rather be surprised if the hex number -- which should specify all bits of the format exactly -- is changed to a completely different value instead. Thus in this case the "wrap around" is the more sensible option in my opinion, as this does not change the underlying bits (hence the quotes on "wrap around" -- the entered information is not changed)
Re: [2.0.20] Base 16 number with highest bit set saturates if used as constant in arithmetic and decider combinator
It would be fine to infer "unsigned truncated" interpretation if hex or bitwise syntax is used anywhere, as long as we had operators to force it back (e.g. "bit()" and "num()"). And of course make it consistent across formula fields.
If we're stuck with the expression parser, might as well make the most of it.
If we're stuck with the expression parser, might as well make the most of it.
My mods: Multiple Unit Train Control, Smart Artillery Wagons
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Re: [2.0.20] Base 16 number with highest bit set saturates if used as constant in arithmetic and decider combinator
FYI, you can just use sign in base16 as you would in base10: -0xffffdoktorstick wrote: Thu Nov 21, 2024 4:32 pm That there's a difference between base10 and base16 behavior is the real problem. In other words, if they clamped it to positives on all three combinators--while now consistent--would be incorrect as it forces a user to use base10 for negative numbers.
Re: [2.0.20] Base 16 number with highest bit set saturates if used as constant in arithmetic and decider combinator
You can use the unary negation, but I argue that this is not too helpful in this case, as changing the sign changes more than a single bit, e.g. -0x8000_0000 = 0x7fff_ffff which personally I again find to be a hassle to work with (in the context of bitwise operations, I just want to be able to directly set the bits).posila wrote: Mon Dec 09, 2024 11:22 pmFYI, you can just use sign in base16 as you would in base10: -0xffffdoktorstick wrote: Thu Nov 21, 2024 4:32 pm That there's a difference between base10 and base16 behavior is the real problem. In other words, if they clamped it to positives on all three combinators--while now consistent--would be incorrect as it forces a user to use base10 for negative numbers.
What I currently do as a workaround instead, if I want to set bits individually, is just writing out the full 0x... and if the highest (31st) bit is set, then I subtract 2^32 i.e.:
- For values 0x0000_0000 - 0x7fff_ffff just input them just like that (omitting underscore)
- For values 0x8000_0000 - 0xffff_ffff enter 0x8000_0000-2^32 to 0xffff_ffff-2^32