math: fix `bits_test`

pull/4312/head
Alexey 2020-04-09 13:43:37 +03:00 committed by GitHub
parent 3fbf91a044
commit 384d401af0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 5 deletions

View File

@ -19,7 +19,6 @@ const (
'vlib/flag/flag_test.v', 'vlib/flag/flag_test.v',
'vlib/json/json_test.v', 'vlib/json/json_test.v',
'vlib/math/big/big_test.v', 'vlib/math/big/big_test.v',
'vlib/math/bits/bits_test.v',
'vlib/math/complex/complex_test.v', 'vlib/math/complex/complex_test.v',
'vlib/math/factorial/factorial_test.v', 'vlib/math/factorial/factorial_test.v',
'vlib/math/fractions/fraction_test.v', 'vlib/math/fractions/fraction_test.v',

View File

@ -477,7 +477,7 @@ pub fn div_64(hi u64, lo u64, y1 u64) (u64, u64) {
// for y == 0 (division by zero) but, unlike Div32, it doesn't panic // for y == 0 (division by zero) but, unlike Div32, it doesn't panic
// on a quotient overflow. // on a quotient overflow.
pub fn rem_32(hi u32, lo u32, y u32) u32 { pub fn rem_32(hi u32, lo u32, y u32) u32 {
return u32((u64(hi)<<32 | u64(lo)) % u64(y)) return u32(((u64(hi)<<32) | u64(lo)) % u64(y))
} }
// rem_64 returns the remainder of (hi, lo) divided by y. Rem64 panics // rem_64 returns the remainder of (hi, lo) divided by y. Rem64 panics

View File

@ -236,11 +236,10 @@ fn test_bits(){
// 32 bit // 32 bit
i = 1 i = 1
for x in 0..32 { for x in 0..32 {
v0 := (u32(i) << x) v0 := u32(i) << x
v1 := v0 - 1 v1 := v0 - 1
hi, lo := mul_32(v0, v1) hi, lo := mul_32(v0, v1)
//C.printf("x:%08x [%llu,%llu] %llu\n", v0, hi, lo, u64(v0 * v1)) assert (u64(hi) << 32) | (u64(lo)) == u64(v0) * u64(v1)
assert (u64(hi) << 32) | (u64(lo)) == u64(v0 * v1)
} }
// 64 bit // 64 bit