Commits

dtrg committed 2e9d16d

Added missing logical operators, shift operators on ints.

  • Participants
  • Parent commits 4bfe325

Comments (0)

Files changed (3)

include/Stdlib.ch

 	function / (o: int): int;
 	function % (o: int): int;
 	
+	function ~ (): int;
+	function & (o: int): int;
+	function | (o: int): int;
+	function ^ (o: int): int;
+
+	function << (o: int): int;
+	function >> (o: int): int;
+	function >>> (o: int): int;
+		
 	function == (o: int): boolean;
 	function != (o: int): boolean;
 	function < (o: int): boolean;
  
 	function % (o: int): (r: int)
  		{ r=extern(int); extern "${r} = self % ${o};"; }
- 
+
+	function << (o: int): (r: int)
+		{ r=extern(int); extern "${r} = self << ${o};"; }
+		
+	function >> (o: int): (r: int)
+		{ r=extern(int); extern "${r} = self >> ${o};"; }
+		
+	function >>> (o: int): (r: int)
+		{ r=extern(int); extern "${r} = (unsigned)self >> (unsigned)${o};"; }
+		 
+	function ~ (): (r: int)
+		{ r=extern(int); extern "${r} = ^self;"; }
+		
+	function & (o: int): (r: int)
+		{ r=extern(int); extern "${r} = self & ${o};"; }
+		
+	function | (o: int): (r: int)
+		{ r=extern(int); extern "${r} = self | ${o};"; }
+		
+	function ^ (o: int): (r: int)
+		{ r=extern(int); extern "${r} = self ^ ${o};"; }
+		 
 	function == (o: int): (r: boolean)
  		{ r=extern(boolean); extern "${r} = self == ${o};"; }
  

test/integer-test.cow

 	testresulti("*", i1, i2, (i1 * i2));
 	testresulti("/", i1, i2, (i1 / i2));
 	testresulti("%", i1, i2, (i1 % i2));
+	testresulti("&", i1, i2, (i1 & i2));
+	testresulti("|", i1, i2, (i1 | i2));
+	testresulti("^", i1, i2, (i1 ^ i2));
+	testresulti("<<", i1, i2, (i1 << i2));
+	testresulti(">>", i1, i2, (i1 >> i2));
+	testresulti(">>>", i1, i2, (i1 >>> i2));
 }
 
 function testm(i1: int, i2: int)
 	test(i2, i1);
 }
 
+testm(1234, 3);
+testm(-1234, 3);
 testm(1234, 1234);
 testm(1234, 78);
 testm(-1234, 78);

test/integer-test.cow.log.pristine

+1234 == 3 = false
+1234 != 3 = true
+1234 > 3 = true
+1234 < 3 = false
+1234 >= 3 = true
+1234 <= 3 = false
+1234 + 3 = 1237
+1234 - 3 = 1231
+1234 * 3 = 3702
+1234 / 3 = 411
+1234 % 3 = 1
+1234 & 3 = 2
+1234 | 3 = 1235
+1234 ^ 3 = 1233
+1234 << 3 = 9872
+1234 >> 3 = 154
+1234 >>> 3 = 154
+3 == 1234 = false
+3 != 1234 = true
+3 > 1234 = false
+3 < 1234 = true
+3 >= 1234 = false
+3 <= 1234 = true
+3 + 1234 = 1237
+3 - 1234 = -1231
+3 * 1234 = 3702
+3 / 1234 = 0
+3 % 1234 = 3
+3 & 1234 = 2
+3 | 1234 = 1235
+3 ^ 1234 = 1233
+3 << 1234 = 786432
+3 >> 1234 = 0
+3 >>> 1234 = 0
+-1234 == 3 = false
+-1234 != 3 = true
+-1234 > 3 = false
+-1234 < 3 = true
+-1234 >= 3 = false
+-1234 <= 3 = true
+-1234 + 3 = -1231
+-1234 - 3 = -1237
+-1234 * 3 = -3702
+-1234 / 3 = -411
+-1234 % 3 = -1
+-1234 & 3 = 2
+-1234 | 3 = -1233
+-1234 ^ 3 = -1235
+-1234 << 3 = -9872
+-1234 >> 3 = -155
+-1234 >>> 3 = 536870757
+3 == -1234 = false
+3 != -1234 = true
+3 > -1234 = true
+3 < -1234 = false
+3 >= -1234 = true
+3 <= -1234 = false
+3 + -1234 = -1231
+3 - -1234 = 1237
+3 * -1234 = -3702
+3 / -1234 = 0
+3 % -1234 = 3
+3 & -1234 = 2
+3 | -1234 = -1233
+3 ^ -1234 = -1235
+3 << -1234 = 49152
+3 >> -1234 = 0
+3 >>> -1234 = 0
 1234 == 1234 = true
 1234 != 1234 = false
 1234 > 1234 = false
 1234 * 1234 = 1522756
 1234 / 1234 = 1
 1234 % 1234 = 0
+1234 & 1234 = 1234
+1234 | 1234 = 1234
+1234 ^ 1234 = 0
+1234 << 1234 = 323485696
+1234 >> 1234 = 0
+1234 >>> 1234 = 0
 1234 == 1234 = true
 1234 != 1234 = false
 1234 > 1234 = false
 1234 * 1234 = 1522756
 1234 / 1234 = 1
 1234 % 1234 = 0
+1234 & 1234 = 1234
+1234 | 1234 = 1234
+1234 ^ 1234 = 0
+1234 << 1234 = 323485696
+1234 >> 1234 = 0
+1234 >>> 1234 = 0
 1234 == 78 = false
 1234 != 78 = true
 1234 > 78 = true
 1234 * 78 = 96252
 1234 / 78 = 15
 1234 % 78 = 64
+1234 & 78 = 66
+1234 | 78 = 1246
+1234 ^ 78 = 1180
+1234 << 78 = 20217856
+1234 >> 78 = 0
+1234 >>> 78 = 0
 78 == 1234 = false
 78 != 1234 = true
 78 > 1234 = false
 78 * 1234 = 96252
 78 / 1234 = 0
 78 % 1234 = 78
+78 & 1234 = 66
+78 | 1234 = 1246
+78 ^ 1234 = 1180
+78 << 1234 = 20447232
+78 >> 1234 = 0
+78 >>> 1234 = 0
 -1234 == 78 = false
 -1234 != 78 = true
 -1234 > 78 = false
 -1234 * 78 = -96252
 -1234 / 78 = -15
 -1234 % 78 = -64
+-1234 & 78 = 14
+-1234 | 78 = -1170
+-1234 ^ 78 = -1184
+-1234 << 78 = -20217856
+-1234 >> 78 = -1
+-1234 >>> 78 = 262143
 78 == -1234 = false
 78 != -1234 = true
 78 > -1234 = true
 78 * -1234 = -96252
 78 / -1234 = 0
 78 % -1234 = 78
+78 & -1234 = 14
+78 | -1234 = -1170
+78 ^ -1234 = -1184
+78 << -1234 = 1277952
+78 >> -1234 = 0
+78 >>> -1234 = 0
 -1234 == -78 = false
 -1234 != -78 = true
 -1234 > -78 = false
 -1234 * -78 = 96252
 -1234 / -78 = 15
 -1234 % -78 = -64
+-1234 & -78 = -1246
+-1234 | -78 = -66
+-1234 ^ -78 = 1180
+-1234 << -78 = -323485696
+-1234 >> -78 = -1
+-1234 >>> -78 = 16383
 -78 == -1234 = false
 -78 != -1234 = true
 -78 > -1234 = true
 -78 * -1234 = 96252
 -78 / -1234 = 0
 -78 % -1234 = -78
+-78 & -1234 = -1246
+-78 | -1234 = -66
+-78 ^ -1234 = 1180
+-78 << -1234 = -1277952
+-78 >> -1234 = -1
+-78 >>> -1234 = 262143