mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
Merge branch 'master' into optional-semicolons
This commit is contained in:
+11
-12
@@ -1,5 +1,3 @@
|
||||
package math_big
|
||||
|
||||
/*
|
||||
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
|
||||
Made available under Odin's BSD-3 license.
|
||||
@@ -8,6 +6,7 @@ package math_big
|
||||
For the theoretical underpinnings, see Knuth's The Art of Computer Programming, Volume 2, section 4.3.
|
||||
The code started out as an idiomatic source port of libTomMath, which is in the public domain, with thanks.
|
||||
*/
|
||||
package math_big
|
||||
|
||||
import "core:intrinsics"
|
||||
import rnd "core:math/rand"
|
||||
@@ -363,15 +362,15 @@ int_random_digit :: proc(r: ^rnd.Rand = nil) -> (res: DIGIT) {
|
||||
return 0 // We shouldn't get here.
|
||||
}
|
||||
|
||||
int_rand :: proc(dest: ^Int, bits: int, r: ^rnd.Rand = nil, allocator := context.allocator) -> (err: Error) {
|
||||
int_random :: proc(dest: ^Int, bits: int, r: ^rnd.Rand = nil, allocator := context.allocator) -> (err: Error) {
|
||||
/*
|
||||
Check that `a` is usable.
|
||||
*/
|
||||
assert_if_nil(dest)
|
||||
return #force_inline internal_int_rand(dest, bits, r, allocator)
|
||||
return #force_inline internal_int_random(dest, bits, r, allocator)
|
||||
|
||||
}
|
||||
rand :: proc { int_rand, }
|
||||
random :: proc { int_random, }
|
||||
|
||||
/*
|
||||
Internal helpers.
|
||||
@@ -496,7 +495,7 @@ int_to_bytes_little :: proc(a: ^Int, buf: []u8, signed := false, allocator := co
|
||||
if signed {
|
||||
buf[l - 1] = 1 if a.sign == .Negative else 0
|
||||
}
|
||||
for offset := 0; offset < size_in_bits; offset += 8 {
|
||||
#no_bounds_check for offset := 0; offset < size_in_bits; offset += 8 {
|
||||
bits, _ := internal_int_bitfield_extract(a, offset, 8)
|
||||
buf[i] = u8(bits & 255); i += 1
|
||||
}
|
||||
@@ -520,7 +519,7 @@ int_to_bytes_big :: proc(a: ^Int, buf: []u8, signed := false, allocator := conte
|
||||
if signed {
|
||||
buf[0] = 1 if a.sign == .Negative else 0
|
||||
}
|
||||
for offset := 0; offset < size_in_bits; offset += 8 {
|
||||
#no_bounds_check for offset := 0; offset < size_in_bits; offset += 8 {
|
||||
bits, _ := internal_int_bitfield_extract(a, offset, 8)
|
||||
buf[i] = u8(bits & 255); i -= 1
|
||||
}
|
||||
@@ -547,7 +546,7 @@ int_to_bytes_little_python :: proc(a: ^Int, buf: []u8, signed := false, allocato
|
||||
|
||||
size_in_bits := internal_count_bits(t)
|
||||
i := 0
|
||||
for offset := 0; offset < size_in_bits; offset += 8 {
|
||||
#no_bounds_check for offset := 0; offset < size_in_bits; offset += 8 {
|
||||
bits, _ := internal_int_bitfield_extract(t, offset, 8)
|
||||
buf[i] = 255 - u8(bits & 255); i += 1
|
||||
}
|
||||
@@ -555,7 +554,7 @@ int_to_bytes_little_python :: proc(a: ^Int, buf: []u8, signed := false, allocato
|
||||
} else {
|
||||
size_in_bits := internal_count_bits(a)
|
||||
i := 0
|
||||
for offset := 0; offset < size_in_bits; offset += 8 {
|
||||
#no_bounds_check for offset := 0; offset < size_in_bits; offset += 8 {
|
||||
bits, _ := internal_int_bitfield_extract(a, offset, 8)
|
||||
buf[i] = u8(bits & 255); i += 1
|
||||
}
|
||||
@@ -584,7 +583,7 @@ int_to_bytes_big_python :: proc(a: ^Int, buf: []u8, signed := false, allocator :
|
||||
|
||||
size_in_bits := internal_count_bits(t)
|
||||
i := l - 1
|
||||
for offset := 0; offset < size_in_bits; offset += 8 {
|
||||
#no_bounds_check for offset := 0; offset < size_in_bits; offset += 8 {
|
||||
bits, _ := internal_int_bitfield_extract(t, offset, 8)
|
||||
buf[i] = 255 - u8(bits & 255); i -= 1
|
||||
}
|
||||
@@ -621,7 +620,7 @@ int_from_bytes_big :: proc(a: ^Int, buf: []u8, signed := false, allocator := con
|
||||
buf = buf[1:]
|
||||
}
|
||||
|
||||
for v in buf {
|
||||
#no_bounds_check for v in buf {
|
||||
internal_shl(a, a, 8) or_return
|
||||
a.digit[0] |= DIGIT(v)
|
||||
}
|
||||
@@ -658,7 +657,7 @@ int_from_bytes_big_python :: proc(a: ^Int, buf: []u8, signed := false, allocator
|
||||
buf = buf[1:]
|
||||
}
|
||||
|
||||
for v in buf {
|
||||
#no_bounds_check for v in buf {
|
||||
internal_shl(a, a, 8) or_return
|
||||
if signed && sign == .Negative {
|
||||
a.digit[0] |= DIGIT(255 - v)
|
||||
|
||||
Reference in New Issue
Block a user