1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

math.big: wrap all asserts in module code (not in tests) in $if debug {} (#14012)

This commit is contained in:
Delyan Angelov 2022-04-12 09:38:53 +03:00 committed by GitHub
parent afb07e0e16
commit 716cb17aea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View File

@ -16,9 +16,14 @@ on:
paths:
- '!**'
- 'cmd/tools/vtest*'
- 'cmd/tools/builders/**.v'
- 'vlib/builtin/**.v'
- 'vlib/strconv/**.v'
- 'vlib/strings/**.v'
- 'vlib/math/**.v'
- 'vlib/math/big/**.v'
- 'vlib/arrays/**.v'
- 'vlib/datatypes/**.v'
- 'vlib/os/**.v'
- 'vlib/sync/**.v'
- 'vlib/v/tests/**.v'
@ -27,18 +32,25 @@ on:
- 'vlib/v/parser/**.v'
- 'vlib/v/checker/**.v'
- 'vlib/v/gen/c/**.v'
- 'vlib/v/builder/**.v'
- 'vlib/v/cflag/**.v'
- 'vlib/v/live/**.v'
- 'vlib/v/util/**.v'
- 'vlib/v/markused/**.v'
- 'vlib/v/preludes/**.v'
- 'vlib/v/embed_file/**.v'
pull_request:
paths:
- '!**'
- 'cmd/tools/vtest*'
- 'cmd/tools/builders/**.v'
- 'vlib/builtin/**.v'
- 'vlib/strconv/**.v'
- 'vlib/strings/**.v'
- 'vlib/math/**.v'
- 'vlib/math/big/**.v'
- 'vlib/arrays/**.v'
- 'vlib/datatypes/**.v'
- 'vlib/os/**.v'
- 'vlib/sync/**.v'
- 'vlib/v/tests/**.v'
@ -47,9 +59,11 @@ on:
- 'vlib/v/parser/**.v'
- 'vlib/v/checker/**.v'
- 'vlib/v/gen/c/**.v'
- 'vlib/v/builder/**.v'
- 'vlib/v/cflag/**.v'
- 'vlib/v/live/**.v'
- 'vlib/v/util/**.v'
- 'vlib/v/markused/**.v'
- 'vlib/v/preludes/**.v'
- 'vlib/v/embed_file/**.v'

View File

@ -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
$if debug {
assert len_diff >= 0
}
// we must do in place shift and operations.
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)
}
$if debug {
assert left_align_p(divisor[divisor.len - 1], remainder[remainder.len - 1])
}
for bit_idx := int(bit_offset); bit_idx >= 0; bit_idx-- {
if greater_equal_from_end(remainder, divisor) {
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) {
byte_offset := n >> 5
mask := u32(1) << u32(n % 32)
$if debug {
assert a.len >= byte_offset
}
a[byte_offset] |= mask
}
@ -71,7 +77,9 @@ fn bit_set(mut a []u32, n int) {
// returns true if a >= b (completed with zeroes)
[inline]
fn greater_equal_from_end(a []u32, b []u32) bool {
$if debug {
assert a.len >= b.len
}
offset := a.len - b.len
for index := a.len - 1; index >= offset; index-- {
if a[index] > b[index - offset] {
@ -99,7 +107,9 @@ fn subtract_align_last_byte_in_place(mut a []u32, b []u32) {
a[index] -= (b[index - offset] + carry)
carry = new_carry
}
$if debug {
assert carry == 0
}
}
// logical left shift