feat: add bitwise AND and OR operators for numbers with 32-bit unsigned semantics

Implement num_bitwiseAnd and num_bitwiseOr native methods that cast operands to uint32_t before applying bitwise operations, matching the existing bitwiseNot pattern. Register both operators on the number class and add test files covering basic cases, max u32 boundary, overflow behavior, and non-numeric operand error handling.
This commit is contained in:
Bob Nystrom
2014-02-24 15:27:43 +00:00
parent 63644010cc
commit b36705d3f3
5 changed files with 48 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
IO.print(0 & 0) // expect: 0
IO.print(2863311530 & 1431655765) // expect: 0
IO.print(4042322160 & 1010580540) // expect: 808464432
// Max u32 value.
IO.print(4294967295 & 4294967295) // expect: 4294967295
// Past max u32 value.
IO.print(4294967296 & 4294967296) // expect: 0
// TODO: Negative numbers.
// TODO: Floating-point numbers.
@@ -0,0 +1 @@
1 & false // expect runtime error: Right operand must be a number.
+12
View File
@@ -0,0 +1,12 @@
IO.print(0 | 0) // expect: 0
IO.print(2863311530 | 1431655765) // expect: 4294967295
IO.print(3435973836 | 1717986918) // expect: 4008636142
// Max u32 value.
IO.print(4294967295 | 4294967295) // expect: 4294967295
// Past max u32 value.
IO.print(4294967296 | 4294967296) // expect: 0
// TODO: Negative numbers.
// TODO: Floating-point numbers.
@@ -0,0 +1 @@
1 | false // expect runtime error: Right operand must be a number.