Describe the bug
A Variant holding a Double, Currency or Decimal of 7.9, shifted left by 1, gives 15.8: the value is multiplied by 2, not shifted. Shifted right by 1, the Double and the Decimal give 3, but the Currency gives 3.95. A Variant holding an Integer or a Long shifted left by a count as large as the type's width gives Empty rather than 0. There is no diagnostic.
To Reproduce
Steps to reproduce the behavior:
-
Open variant-shift.twinproj (from variant-shift.zip) and run it (F5). Its Sub Main holds the whole bug:
Dim d As Variant = CDbl(7.9)
Dim c As Variant = CCur(7.9)
Debug.Print d << 1 ' 15.8
Debug.Print c >> 1 ' 3.95
Dim i As Variant = CInt(1)
Dim l As Variant = CLng(1)
Debug.Print TypeName(i << 20) ' Empty
Debug.Print TypeName(l << 32) ' Empty
-
See the DEBUG CONSOLE show 15.8, 3.95, Empty and Empty. The project prints the same for a Decimal too.
| expression |
result |
a Variant holding CInt(1), << 20 |
Empty |
a Variant holding CLng(1), << 32 |
Empty |
a Variant holding CLng(1), << 31 |
Long -2147483648 |
a Long variable holding 1, << 32 |
0 |
Expected behavior
A shift moves bits, so a fractional value should be truncated first, as the right shift of the Double and the Decimal already does: 7.9 << 1 is 14 and 7.9 >> 1 is 3. A count as large as the width of the type should give 0 and keep the type, as the Long variable's shift does, not Empty.
Desktop (please complete the following information):
- OS: Windows 10 Pro 22H2 (build 19045)
- twinBASIC compiler version: BETA 995
Additional context
Severity: wrong values, with no diagnostic. Also on BETA 983, with the same results, except that the right shift of a Variant holding 7.9 gave 4 there for all three types (BETA 984 made >> arithmetic). A Long variable's shift by 32 gives 0 on both builds.
Describe the bug
A
Variantholding aDouble,CurrencyorDecimalof 7.9, shifted left by 1, gives 15.8: the value is multiplied by 2, not shifted. Shifted right by 1, theDoubleand theDecimalgive 3, but theCurrencygives 3.95. AVariantholding anIntegeror aLongshifted left by a count as large as the type's width givesEmptyrather than 0. There is no diagnostic.To Reproduce
Steps to reproduce the behavior:
Open
variant-shift.twinproj(from variant-shift.zip) and run it (F5). ItsSub Mainholds the whole bug:See the DEBUG CONSOLE show 15.8, 3.95,
EmptyandEmpty. The project prints the same for aDecimaltoo.VariantholdingCInt(1),<< 20EmptyVariantholdingCLng(1),<< 32EmptyVariantholdingCLng(1),<< 31Long-2147483648Longvariable holding 1,<< 32Expected behavior
A shift moves bits, so a fractional value should be truncated first, as the right shift of the
Doubleand theDecimalalready does:7.9 << 1is 14 and7.9 >> 1is 3. A count as large as the width of the type should give 0 and keep the type, as theLongvariable's shift does, notEmpty.Desktop (please complete the following information):
Additional context
Severity: wrong values, with no diagnostic. Also on BETA 983, with the same results, except that the right shift of a
Variantholding 7.9 gave 4 there for all three types (BETA 984 made>>arithmetic). ALongvariable's shift by 32 gives 0 on both builds.