math.big: wrap all asserts in module code (not in tests) in `$if debug {}` (#14012)
parent
afb07e0e16
commit
716cb17aea
|
@ -16,9 +16,14 @@ on:
|
||||||
paths:
|
paths:
|
||||||
- '!**'
|
- '!**'
|
||||||
- 'cmd/tools/vtest*'
|
- 'cmd/tools/vtest*'
|
||||||
|
- 'cmd/tools/builders/**.v'
|
||||||
- 'vlib/builtin/**.v'
|
- 'vlib/builtin/**.v'
|
||||||
- 'vlib/strconv/**.v'
|
- 'vlib/strconv/**.v'
|
||||||
- 'vlib/strings/**.v'
|
- 'vlib/strings/**.v'
|
||||||
|
- 'vlib/math/**.v'
|
||||||
|
- 'vlib/math/big/**.v'
|
||||||
|
- 'vlib/arrays/**.v'
|
||||||
|
- 'vlib/datatypes/**.v'
|
||||||
- 'vlib/os/**.v'
|
- 'vlib/os/**.v'
|
||||||
- 'vlib/sync/**.v'
|
- 'vlib/sync/**.v'
|
||||||
- 'vlib/v/tests/**.v'
|
- 'vlib/v/tests/**.v'
|
||||||
|
@ -27,18 +32,25 @@ on:
|
||||||
- 'vlib/v/parser/**.v'
|
- 'vlib/v/parser/**.v'
|
||||||
- 'vlib/v/checker/**.v'
|
- 'vlib/v/checker/**.v'
|
||||||
- 'vlib/v/gen/c/**.v'
|
- 'vlib/v/gen/c/**.v'
|
||||||
|
- 'vlib/v/builder/**.v'
|
||||||
- 'vlib/v/cflag/**.v'
|
- 'vlib/v/cflag/**.v'
|
||||||
- 'vlib/v/live/**.v'
|
- 'vlib/v/live/**.v'
|
||||||
- 'vlib/v/util/**.v'
|
- 'vlib/v/util/**.v'
|
||||||
|
- 'vlib/v/markused/**.v'
|
||||||
- 'vlib/v/preludes/**.v'
|
- 'vlib/v/preludes/**.v'
|
||||||
- 'vlib/v/embed_file/**.v'
|
- 'vlib/v/embed_file/**.v'
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
- '!**'
|
- '!**'
|
||||||
- 'cmd/tools/vtest*'
|
- 'cmd/tools/vtest*'
|
||||||
|
- 'cmd/tools/builders/**.v'
|
||||||
- 'vlib/builtin/**.v'
|
- 'vlib/builtin/**.v'
|
||||||
- 'vlib/strconv/**.v'
|
- 'vlib/strconv/**.v'
|
||||||
- 'vlib/strings/**.v'
|
- 'vlib/strings/**.v'
|
||||||
|
- 'vlib/math/**.v'
|
||||||
|
- 'vlib/math/big/**.v'
|
||||||
|
- 'vlib/arrays/**.v'
|
||||||
|
- 'vlib/datatypes/**.v'
|
||||||
- 'vlib/os/**.v'
|
- 'vlib/os/**.v'
|
||||||
- 'vlib/sync/**.v'
|
- 'vlib/sync/**.v'
|
||||||
- 'vlib/v/tests/**.v'
|
- 'vlib/v/tests/**.v'
|
||||||
|
@ -47,9 +59,11 @@ on:
|
||||||
- 'vlib/v/parser/**.v'
|
- 'vlib/v/parser/**.v'
|
||||||
- 'vlib/v/checker/**.v'
|
- 'vlib/v/checker/**.v'
|
||||||
- 'vlib/v/gen/c/**.v'
|
- 'vlib/v/gen/c/**.v'
|
||||||
|
- 'vlib/v/builder/**.v'
|
||||||
- 'vlib/v/cflag/**.v'
|
- 'vlib/v/cflag/**.v'
|
||||||
- 'vlib/v/live/**.v'
|
- 'vlib/v/live/**.v'
|
||||||
- 'vlib/v/util/**.v'
|
- 'vlib/v/util/**.v'
|
||||||
|
- 'vlib/v/markused/**.v'
|
||||||
- 'vlib/v/preludes/**.v'
|
- 'vlib/v/preludes/**.v'
|
||||||
- 'vlib/v/embed_file/**.v'
|
- 'vlib/v/embed_file/**.v'
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,9 @@ fn binary_divide_array_by_array(operand_a []u32, operand_b []u32, mut quotient [
|
||||||
}
|
}
|
||||||
|
|
||||||
len_diff := operand_a.len - operand_b.len
|
len_diff := operand_a.len - operand_b.len
|
||||||
|
$if debug {
|
||||||
assert len_diff >= 0
|
assert len_diff >= 0
|
||||||
|
}
|
||||||
|
|
||||||
// we must do in place shift and operations.
|
// we must do in place shift and operations.
|
||||||
mut divisor := []u32{cap: operand_b.len}
|
mut divisor := []u32{cap: operand_b.len}
|
||||||
|
@ -35,7 +37,9 @@ fn binary_divide_array_by_array(operand_a []u32, operand_b []u32, mut quotient [
|
||||||
lshift_in_place(mut remainder, lead_zer_remainder - lead_zer_divisor)
|
lshift_in_place(mut remainder, lead_zer_remainder - lead_zer_divisor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$if debug {
|
||||||
assert left_align_p(divisor[divisor.len - 1], remainder[remainder.len - 1])
|
assert left_align_p(divisor[divisor.len - 1], remainder[remainder.len - 1])
|
||||||
|
}
|
||||||
for bit_idx := int(bit_offset); bit_idx >= 0; bit_idx-- {
|
for bit_idx := int(bit_offset); bit_idx >= 0; bit_idx-- {
|
||||||
if greater_equal_from_end(remainder, divisor) {
|
if greater_equal_from_end(remainder, divisor) {
|
||||||
bit_set(mut quotient, bit_idx)
|
bit_set(mut quotient, bit_idx)
|
||||||
|
@ -63,7 +67,9 @@ fn binary_divide_array_by_array(operand_a []u32, operand_b []u32, mut quotient [
|
||||||
fn bit_set(mut a []u32, n int) {
|
fn bit_set(mut a []u32, n int) {
|
||||||
byte_offset := n >> 5
|
byte_offset := n >> 5
|
||||||
mask := u32(1) << u32(n % 32)
|
mask := u32(1) << u32(n % 32)
|
||||||
|
$if debug {
|
||||||
assert a.len >= byte_offset
|
assert a.len >= byte_offset
|
||||||
|
}
|
||||||
a[byte_offset] |= mask
|
a[byte_offset] |= mask
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +77,9 @@ fn bit_set(mut a []u32, n int) {
|
||||||
// returns true if a >= b (completed with zeroes)
|
// returns true if a >= b (completed with zeroes)
|
||||||
[inline]
|
[inline]
|
||||||
fn greater_equal_from_end(a []u32, b []u32) bool {
|
fn greater_equal_from_end(a []u32, b []u32) bool {
|
||||||
|
$if debug {
|
||||||
assert a.len >= b.len
|
assert a.len >= b.len
|
||||||
|
}
|
||||||
offset := a.len - b.len
|
offset := a.len - b.len
|
||||||
for index := a.len - 1; index >= offset; index-- {
|
for index := a.len - 1; index >= offset; index-- {
|
||||||
if a[index] > b[index - offset] {
|
if a[index] > b[index - offset] {
|
||||||
|
@ -99,8 +107,10 @@ fn subtract_align_last_byte_in_place(mut a []u32, b []u32) {
|
||||||
a[index] -= (b[index - offset] + carry)
|
a[index] -= (b[index - offset] + carry)
|
||||||
carry = new_carry
|
carry = new_carry
|
||||||
}
|
}
|
||||||
|
$if debug {
|
||||||
assert carry == 0
|
assert carry == 0
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// logical left shift
|
// logical left shift
|
||||||
// there is no overflow. We know that the last bits are zero
|
// there is no overflow. We know that the last bits are zero
|
||||||
|
|
Loading…
Reference in New Issue