Author Topic: [v1.7.2.16] Inconsistent behavior with too small/large values  (Read 4157 times)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
[v1.7.2.16] Inconsistent behavior with too small/large values
« on: August 25, 2018, 01:55:56 PM »
The documentation for "Set an Integer Value" notes
Quote from: VoiceAttackHelp.pdf page 72
If you have a value in text or in a token, you can attempt to convert the value to an integer by selecting, 'Convert Text/Token' and type the text and/or tokens into the box provided.
If the value cannot be converted, the variable value will be, 'Not Set'.
(bold emphasis mine)

However, if the "Convert Text/Token" field is used, a value smaller or larger than the maximum for an Int32(less than -2147483648 or more than 2147483647) will be converted to the minimum or maximum value, respectively(E.G. -2147483649 is converted to -2147483648).

On the other hand, if the value is set too low or high by a math function it will instead result in the variable getting set to "Not Set"(which is not mentioned in the documentation relating to math, only to tokens, neither are the minimum and maximum values, which are only listed for small integer).

E.G.
Code: [Select]
Set integer [t] value to -2147483648
Set integer [t] to [t] plus -1
Write [Blue] '{INT:t}' to log
Will write "Not Set" to the log.


Small Integer will wrap around instead, both when converting or using math.

E.G.
Code: [Select]
Set small int (condition) [t] value to the converted value of -32769
Write [Blue] '{SMALL:t}' to log
Set small int (condition) [t] value as incremented by 1
Write [Blue] '{SMALL:t}' to log
Writes "32767"(wraparound from negative to positive) and "-32768"(wraparound from positive to negative) to the log.


None of these conditions provide feedback to the user; I feel this would be useful for diagnostics.


Lastly, decimal will not convert invalid values, writing "Decimal token could not be converted : " to the log, and math will result in "Not Set" when overflowing.

The "A value" field for decimal is inconsistent with the other two numeric values, as instead of limiting the value to minimum if too small, or maximum if too large, it always retains the previously entered value for that action.

E.G. if the previous value was "1337", and "-79228162514264337593543950336" is entered, clicking "OK" will result in the value remaining "1337".



As an aside, I believe
Quote from: VoiceAttackHelp.pdf page 87
(see, 'Set a Small Integer Variable' command action above)
is intended to refer to the "Set a Small Integer (Condition) Value" section, as there is no "Set a Small Integer Variable" section.


Also, while the documentation for "Set a Small Integer (Condition) Value" notes
Quote from: VoiceAttackHelp.pdf page 55
The value can be no more than 32,767 and no less than -32,767.
the minimum value for an Int16 is actually -32768.

The "A value" numericupdown for this action correctly limits it to -32768.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2827
Re: [v1.7.2.16] Inconsistent behavior with too small/large values
« Reply #1 on: September 02, 2018, 04:55:16 PM »
Quote
However, if the "Convert Text/Token" field is used, a value smaller or larger than the maximum for an Int32(less than -2147483648 or more than 2147483647) will be converted to the minimum or maximum value, respectively(E.G. -2147483649 is converted to -2147483648).

This has been fixed. 


Quote
On the other hand, if the value is set too low or high by a math function it will instead result in the variable getting set to "Not Set"(which is not mentioned in the documentation relating to math, only to tokens, neither are the minimum and maximum values, which are only listed for small integer).

Warning message added.  Doc updated.


Quote
Small Integer will wrap around instead, both when converting or using math.

and

Quote
None of these conditions provide feedback to the user; I feel this would be useful for diagnostics.

Fixed and documented. 

Quote
Lastly, decimal will not convert invalid values, writing "Decimal token could not be converted : " to the log, and math will result in "Not Set" when overflowing.

Added messages due to calculation overflow.  Doc updated.


Quote
The "A value" field for decimal is inconsistent with the other two numeric values, as instead of limiting the value to minimum if too small, or maximum if too large, it always retains the previously entered value for that action.

Not sure what's up with the control.  The min/max values are set just like everywhere else.  I'd have to dig more into it to find out what would be up with it.  I don't have an ETA for that, tho o_O.

Quote
the minimum value for an Int16 is actually -32768

Doc updated.




Good catches on all of these!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: [v1.7.2.16] Inconsistent behavior with too small/large values
« Reply #2 on: September 05, 2018, 06:37:12 PM »
Testing v1.7.2.20:

Attempting to set an out-of-range converted value to a small integer writes something like
Quote
Small integer value out of range : -32769
to the log, but when the value is out of range because of a math function,
Quote
Condition value out of range.
is written to the log instead, using "Condition" rather than "Small integer", and omitting the value that caused the issue.

Converting an out-of-bounds value from a token also differs for decimals and (small)integers:
Quote
Decimal token could not be converted : -79228162514264337593543950336
vs
Quote
Integer value out of range : -2147483650
Where the decimal variant states explicitly that a token conversion can't happen because of an invalid value(any invalid value, I.E. there is no special case for out-of-bounds), whereas the (small)integer variant gives the same message as a math function going out-of-bounds would.


Would it be possible to "mix and match", as it were?
E.G.
Quote
x token could not be converted(value out of range) : -79228162514264337593543950336
If a conversion yields a valid number, but cannot fit into the chosen variable type

Quote
x token could not be converted : text, not a number
If the conversion does not yield a valid number(this would be unchanged from the current behavior)

Quote
x value out of range : -2147483650
If a math function goes out of bounds, always noting the value.