| ... | ... | @@ -9,26 +9,45 @@ const mem = std.mem; |
| 9 | 9 | test "@addWithOverflow" { |
| 10 | 10 | var result: u8 = undefined; |
| 11 | 11 | try expect(@addWithOverflow(u8, 250, 100, &result)); |
| 12 | try expect(result == 94); |
| 12 | 13 | try expect(!@addWithOverflow(u8, 100, 150, &result)); |
| 13 | 14 | try expect(result == 250); |
| 14 | 15 | } |
| 15 | 16 | |
| 16 | | // TODO test mulWithOverflow |
| 17 | | // TODO test subWithOverflow |
| 17 | test "@mulWithOverflow" { |
| 18 | var result: u8 = undefined; |
| 19 | try expect(@mulWithOverflow(u8, 86, 3, &result)); |
| 20 | try expect(result == 2); |
| 21 | try expect(!@mulWithOverflow(u8, 85, 3, &result)); |
| 22 | try expect(result == 255); |
| 23 | } |
| 24 | |
| 25 | test "@subWithOverflow" { |
| 26 | var result: u8 = undefined; |
| 27 | try expect(@subWithOverflow(u8, 1, 2, &result)); |
| 28 | try expect(result == 255); |
| 29 | try expect(!@subWithOverflow(u8, 1, 1, &result)); |
| 30 | try expect(result == 0); |
| 31 | } |
| 18 | 32 | |
| 19 | 33 | test "@shlWithOverflow" { |
| 20 | 34 | var result: u16 = undefined; |
| 21 | 35 | try expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result)); |
| 36 | try expect(result == 0b0111111111111000); |
| 22 | 37 | try expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result)); |
| 23 | 38 | try expect(result == 0b1011111111111100); |
| 24 | 39 | } |
| 25 | 40 | |
| 26 | | test "@*WithOverflow with u0 values" { |
| 41 | test "overflow arithmetic with u0 values" { |
| 27 | 42 | var result: u0 = undefined; |
| 28 | 43 | try expect(!@addWithOverflow(u0, 0, 0, &result)); |
| 44 | try expect(result == 0); |
| 29 | 45 | try expect(!@subWithOverflow(u0, 0, 0, &result)); |
| 46 | try expect(result == 0); |
| 30 | 47 | try expect(!@mulWithOverflow(u0, 0, 0, &result)); |
| 48 | try expect(result == 0); |
| 31 | 49 | try expect(!@shlWithOverflow(u0, 0, 0, &result)); |
| 50 | try expect(result == 0); |
| 32 | 51 | } |
| 33 | 52 | |
| 34 | 53 | test "@clz vectors" { |