mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-30 11:20:08 +00:00
Strip even more semicolons if followed by a } or ) on the same line
This commit is contained in:
@@ -87,7 +87,7 @@ FACTORIAL_BINARY_SPLIT_MAX_RECURSIONS := 100
|
||||
*/
|
||||
MATH_BIG_FORCE_64_BIT :: #config(MATH_BIG_FORCE_64_BIT, false)
|
||||
MATH_BIG_FORCE_32_BIT :: #config(MATH_BIG_FORCE_32_BIT, false)
|
||||
when (MATH_BIG_FORCE_32_BIT && MATH_BIG_FORCE_64_BIT) { #panic("Cannot force 32-bit and 64-bit big backend simultaneously."); }
|
||||
when (MATH_BIG_FORCE_32_BIT && MATH_BIG_FORCE_64_BIT) { #panic("Cannot force 32-bit and 64-bit big backend simultaneously.") }
|
||||
|
||||
_LOW_MEMORY :: #config(BIGINT_SMALL_MEMORY, false)
|
||||
when _LOW_MEMORY {
|
||||
|
||||
+15
-15
@@ -56,7 +56,7 @@ int_copy :: proc(dest, src: ^Int, minimize := false, allocator := context.alloca
|
||||
/*
|
||||
If dest == src, do nothing
|
||||
*/
|
||||
if (dest == src) { return nil; }
|
||||
if (dest == src) { return nil }
|
||||
|
||||
/*
|
||||
Check that `src` is usable and `dest` isn't immutable.
|
||||
@@ -383,7 +383,7 @@ assert_initialized :: proc(a: ^Int, loc := #caller_location) {
|
||||
|
||||
zero_unused :: proc(dest: ^Int, old_used := -1) {
|
||||
assert_if_nil(dest)
|
||||
if ! #force_inline is_initialized(dest) { return; }
|
||||
if ! #force_inline is_initialized(dest) { return }
|
||||
|
||||
#force_inline internal_zero_unused(dest, old_used)
|
||||
}
|
||||
@@ -405,13 +405,13 @@ clear_if_uninitialized_multi :: proc(args: ..^Int, allocator := context.allocato
|
||||
clear_if_uninitialized :: proc {clear_if_uninitialized_single, clear_if_uninitialized_multi, }
|
||||
|
||||
error_if_immutable_single :: proc(arg: ^Int) -> (err: Error) {
|
||||
if arg != nil && .Immutable in arg.flags { return .Assignment_To_Immutable; }
|
||||
if arg != nil && .Immutable in arg.flags { return .Assignment_To_Immutable }
|
||||
return nil
|
||||
}
|
||||
|
||||
error_if_immutable_multi :: proc(args: ..^Int) -> (err: Error) {
|
||||
for i in args {
|
||||
if i != nil && .Immutable in i.flags { return .Assignment_To_Immutable; }
|
||||
if i != nil && .Immutable in i.flags { return .Assignment_To_Immutable }
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -489,7 +489,7 @@ int_to_bytes_little :: proc(a: ^Int, buf: []u8, signed := false, allocator := co
|
||||
|
||||
size_in_bytes := int_to_bytes_size(a, signed, allocator) or_return
|
||||
l := len(buf)
|
||||
if size_in_bytes > l { return .Buffer_Overflow; }
|
||||
if size_in_bytes > l { return .Buffer_Overflow }
|
||||
|
||||
size_in_bits := internal_count_bits(a)
|
||||
i := 0
|
||||
@@ -512,7 +512,7 @@ int_to_bytes_big :: proc(a: ^Int, buf: []u8, signed := false, allocator := conte
|
||||
|
||||
size_in_bytes := int_to_bytes_size(a, signed, allocator) or_return
|
||||
l := len(buf)
|
||||
if size_in_bytes > l { return .Buffer_Overflow; }
|
||||
if size_in_bytes > l { return .Buffer_Overflow }
|
||||
|
||||
size_in_bits := internal_count_bits(a)
|
||||
i := l - 1
|
||||
@@ -534,11 +534,11 @@ int_to_bytes_big :: proc(a: ^Int, buf: []u8, signed := false, allocator := conte
|
||||
int_to_bytes_little_python :: proc(a: ^Int, buf: []u8, signed := false, allocator := context.allocator) -> (err: Error) {
|
||||
assert_if_nil(a)
|
||||
|
||||
if !signed && a.sign == .Negative { return .Invalid_Argument; }
|
||||
if !signed && a.sign == .Negative { return .Invalid_Argument }
|
||||
|
||||
l := len(buf)
|
||||
size_in_bytes := int_to_bytes_size(a, signed, allocator) or_return
|
||||
if size_in_bytes > l { return .Buffer_Overflow; }
|
||||
if size_in_bytes > l { return .Buffer_Overflow }
|
||||
|
||||
if a.sign == .Negative {
|
||||
t := &Int{}
|
||||
@@ -570,12 +570,12 @@ int_to_bytes_little_python :: proc(a: ^Int, buf: []u8, signed := false, allocato
|
||||
int_to_bytes_big_python :: proc(a: ^Int, buf: []u8, signed := false, allocator := context.allocator) -> (err: Error) {
|
||||
assert_if_nil(a)
|
||||
|
||||
if !signed && a.sign == .Negative { return .Invalid_Argument; }
|
||||
if a.sign == .Zero_or_Positive { return int_to_bytes_big(a, buf, signed, allocator); }
|
||||
if !signed && a.sign == .Negative { return .Invalid_Argument }
|
||||
if a.sign == .Zero_or_Positive { return int_to_bytes_big(a, buf, signed, allocator) }
|
||||
|
||||
l := len(buf)
|
||||
size_in_bytes := int_to_bytes_size(a, signed, allocator) or_return
|
||||
if size_in_bytes > l { return .Buffer_Overflow; }
|
||||
if size_in_bytes > l { return .Buffer_Overflow }
|
||||
|
||||
t := &Int{}
|
||||
defer destroy(t)
|
||||
@@ -601,7 +601,7 @@ int_from_bytes_big :: proc(a: ^Int, buf: []u8, signed := false, allocator := con
|
||||
assert_if_nil(a)
|
||||
buf := buf
|
||||
l := len(buf)
|
||||
if l == 0 { return .Invalid_Argument; }
|
||||
if l == 0 { return .Invalid_Argument }
|
||||
|
||||
sign: Sign
|
||||
size_in_bits := l * 8
|
||||
@@ -638,7 +638,7 @@ int_from_bytes_big_python :: proc(a: ^Int, buf: []u8, signed := false, allocator
|
||||
assert_if_nil(a)
|
||||
buf := buf
|
||||
l := len(buf)
|
||||
if l == 0 { return .Invalid_Argument; }
|
||||
if l == 0 { return .Invalid_Argument }
|
||||
|
||||
sign: Sign
|
||||
size_in_bits := l * 8
|
||||
@@ -684,7 +684,7 @@ int_from_bytes_little :: proc(a: ^Int, buf: []u8, signed := false, allocator :=
|
||||
assert_if_nil(a)
|
||||
buf := buf
|
||||
l := len(buf)
|
||||
if l == 0 { return .Invalid_Argument; }
|
||||
if l == 0 { return .Invalid_Argument }
|
||||
|
||||
sign: Sign
|
||||
size_in_bits := l * 8
|
||||
@@ -722,7 +722,7 @@ int_from_bytes_little_python :: proc(a: ^Int, buf: []u8, signed := false, alloca
|
||||
assert_if_nil(a)
|
||||
buf := buf
|
||||
l := len(buf)
|
||||
if l == 0 { return .Invalid_Argument; }
|
||||
if l == 0 { return .Invalid_Argument }
|
||||
|
||||
sign: Sign
|
||||
size_in_bits := l * 8
|
||||
|
||||
+65
-65
@@ -628,7 +628,7 @@ internal_int_mul :: proc(dest, src, multiplier: ^Int, allocator := context.alloc
|
||||
/*
|
||||
Early out for `multiplier` is zero; Set `dest` to zero.
|
||||
*/
|
||||
if multiplier.used == 0 || src.used == 0 { return internal_zero(dest); }
|
||||
if multiplier.used == 0 || src.used == 0 { return internal_zero(dest) }
|
||||
|
||||
neg := src.sign != multiplier.sign
|
||||
|
||||
@@ -715,7 +715,7 @@ internal_sqr :: proc (dest, src: ^Int, allocator := context.allocator) -> (res:
|
||||
*/
|
||||
internal_int_divmod :: proc(quotient, remainder, numerator, denominator: ^Int, allocator := context.allocator) -> (err: Error) {
|
||||
context.allocator = allocator
|
||||
if denominator.used == 0 { return .Division_by_Zero; }
|
||||
if denominator.used == 0 { return .Division_by_Zero }
|
||||
/*
|
||||
If numerator < denominator then quotient = 0, remainder = numerator.
|
||||
*/
|
||||
@@ -757,7 +757,7 @@ internal_int_divmod_digit :: proc(quotient, numerator: ^Int, denominator: DIGIT,
|
||||
/*
|
||||
Cannot divide by zero.
|
||||
*/
|
||||
if denominator == 0 { return 0, .Division_by_Zero; }
|
||||
if denominator == 0 { return 0, .Division_by_Zero }
|
||||
|
||||
/*
|
||||
Quick outs.
|
||||
@@ -854,7 +854,7 @@ internal_div :: proc { internal_int_div, }
|
||||
internal_int_mod :: proc(remainder, numerator, denominator: ^Int, allocator := context.allocator) -> (err: Error) {
|
||||
#force_inline internal_int_divmod(nil, remainder, numerator, denominator, allocator) or_return
|
||||
|
||||
if remainder.used == 0 || denominator.sign == remainder.sign { return nil; }
|
||||
if remainder.used == 0 || denominator.sign == remainder.sign { return nil }
|
||||
|
||||
return #force_inline internal_add(remainder, remainder, numerator, allocator)
|
||||
}
|
||||
@@ -937,7 +937,7 @@ internal_int_factorial :: proc(res: ^Int, n: int, allocator := context.allocator
|
||||
`res_gcd` and `res_lcm` can be nil or ^Int depending on which results are desired.
|
||||
*/
|
||||
internal_int_gcd_lcm :: proc(res_gcd, res_lcm, a, b: ^Int, allocator := context.allocator) -> (err: Error) {
|
||||
if res_gcd == nil && res_lcm == nil { return nil; }
|
||||
if res_gcd == nil && res_lcm == nil { return nil }
|
||||
|
||||
return #force_inline _private_int_gcd_lcm(res_gcd, res_lcm, a, b, allocator)
|
||||
}
|
||||
@@ -951,7 +951,7 @@ internal_int_mod_bits :: proc(remainder, numerator: ^Int, bits: int, allocator :
|
||||
/*
|
||||
Everything is divisible by 1 << 0 == 1, so this returns 0.
|
||||
*/
|
||||
if bits == 0 { return internal_zero(remainder); }
|
||||
if bits == 0 { return internal_zero(remainder) }
|
||||
|
||||
/*
|
||||
If the modulus is larger than the value, return the value.
|
||||
@@ -1034,7 +1034,7 @@ internal_is_negative :: proc { internal_int_is_negative, }
|
||||
Assumes `a` not to be `nil`.
|
||||
*/
|
||||
internal_int_is_even :: #force_inline proc(a: ^Int) -> (even: bool) {
|
||||
if internal_is_zero(a) { return true; }
|
||||
if internal_is_zero(a) { return true }
|
||||
|
||||
/*
|
||||
`a.used` > 0 here, because the above handled `is_zero`.
|
||||
@@ -1062,23 +1062,23 @@ internal_int_is_power_of_two :: #force_inline proc(a: ^Int) -> (power_of_two: bo
|
||||
/*
|
||||
Early out for Int == 0.
|
||||
*/
|
||||
if #force_inline internal_is_zero(a) { return true; }
|
||||
if #force_inline internal_is_zero(a) { return true }
|
||||
|
||||
/*
|
||||
For an `Int` to be a power of two, its bottom limb has to be a power of two.
|
||||
*/
|
||||
if ! #force_inline platform_int_is_power_of_two(int(a.digit[a.used - 1])) { return false; }
|
||||
if ! #force_inline platform_int_is_power_of_two(int(a.digit[a.used - 1])) { return false }
|
||||
|
||||
/*
|
||||
We've established that the bottom limb is a power of two.
|
||||
If it's the only limb, that makes the entire Int a power of two.
|
||||
*/
|
||||
if a.used == 1 { return true; }
|
||||
if a.used == 1 { return true }
|
||||
|
||||
/*
|
||||
For an `Int` to be a power of two, all limbs except the top one have to be zero.
|
||||
*/
|
||||
for i := 1; i < a.used && a.digit[i - 1] != 0; i += 1 { return false; }
|
||||
for i := 1; i < a.used && a.digit[i - 1] != 0; i += 1 { return false }
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -1096,11 +1096,11 @@ internal_int_compare :: #force_inline proc(a, b: ^Int) -> (comparison: int) {
|
||||
/*
|
||||
Compare based on sign.
|
||||
*/
|
||||
if a.sign != b.sign { return -1 if a_is_negative else +1; }
|
||||
if a.sign != b.sign { return -1 if a_is_negative else +1 }
|
||||
|
||||
/*
|
||||
If `a` is negative, compare in the opposite direction */
|
||||
if a_is_negative { return #force_inline internal_compare_magnitude(b, a); }
|
||||
if a_is_negative { return #force_inline internal_compare_magnitude(b, a) }
|
||||
|
||||
return #force_inline internal_compare_magnitude(a, b)
|
||||
}
|
||||
@@ -1186,20 +1186,20 @@ internal_int_is_square :: proc(a: ^Int, allocator := context.allocator) -> (squa
|
||||
*/
|
||||
square = false
|
||||
|
||||
if internal_is_negative(a) { return; }
|
||||
if internal_is_zero(a) { return; }
|
||||
if internal_is_negative(a) { return }
|
||||
if internal_is_zero(a) { return }
|
||||
|
||||
/*
|
||||
First check mod 128 (suppose that _DIGIT_BITS is at least 7).
|
||||
*/
|
||||
if _private_int_rem_128[127 & a.digit[0]] == 1 { return; }
|
||||
if _private_int_rem_128[127 & a.digit[0]] == 1 { return }
|
||||
|
||||
/*
|
||||
Next check mod 105 (3*5*7).
|
||||
*/
|
||||
c: DIGIT
|
||||
c, err = internal_mod(a, 105)
|
||||
if _private_int_rem_105[c] == 1 { return; }
|
||||
if _private_int_rem_105[c] == 1 { return }
|
||||
|
||||
t := &Int{}
|
||||
defer destroy(t)
|
||||
@@ -1215,13 +1215,13 @@ internal_int_is_square :: proc(a: ^Int, allocator := context.allocator) -> (squa
|
||||
free "t" so the easiest way is to goto LBL_ERR. We know that err
|
||||
is already equal to MP_OKAY from the mp_mod call
|
||||
*/
|
||||
if (1 << (r % 11) & 0x5C4) != 0 { return; }
|
||||
if (1 << (r % 13) & 0x9E4) != 0 { return; }
|
||||
if (1 << (r % 17) & 0x5CE8) != 0 { return; }
|
||||
if (1 << (r % 19) & 0x4F50C) != 0 { return; }
|
||||
if (1 << (r % 23) & 0x7ACCA0) != 0 { return; }
|
||||
if (1 << (r % 29) & 0xC2EDD0C) != 0 { return; }
|
||||
if (1 << (r % 31) & 0x6DE2B848) != 0 { return; }
|
||||
if (1 << (r % 11) & 0x5C4) != 0 { return }
|
||||
if (1 << (r % 13) & 0x9E4) != 0 { return }
|
||||
if (1 << (r % 17) & 0x5CE8) != 0 { return }
|
||||
if (1 << (r % 19) & 0x4F50C) != 0 { return }
|
||||
if (1 << (r % 23) & 0x7ACCA0) != 0 { return }
|
||||
if (1 << (r % 29) & 0xC2EDD0C) != 0 { return }
|
||||
if (1 << (r % 31) & 0x6DE2B848) != 0 { return }
|
||||
|
||||
/*
|
||||
Final check - is sqr(sqrt(arg)) == arg?
|
||||
@@ -1243,20 +1243,20 @@ internal_int_is_square :: proc(a: ^Int, allocator := context.allocator) -> (squa
|
||||
Assumes `a` to not be `nil` and have been iniialized.
|
||||
*/
|
||||
internal_int_log :: proc(a: ^Int, base: DIGIT) -> (res: int, err: Error) {
|
||||
if base < 2 || DIGIT(base) > _DIGIT_MAX { return -1, .Invalid_Argument; }
|
||||
if base < 2 || DIGIT(base) > _DIGIT_MAX { return -1, .Invalid_Argument }
|
||||
|
||||
if internal_is_negative(a) { return -1, .Math_Domain_Error; }
|
||||
if internal_is_zero(a) { return -1, .Math_Domain_Error; }
|
||||
if internal_is_negative(a) { return -1, .Math_Domain_Error }
|
||||
if internal_is_zero(a) { return -1, .Math_Domain_Error }
|
||||
|
||||
/*
|
||||
Fast path for bases that are a power of two.
|
||||
*/
|
||||
if platform_int_is_power_of_two(int(base)) { return _private_log_power_of_two(a, base); }
|
||||
if platform_int_is_power_of_two(int(base)) { return _private_log_power_of_two(a, base) }
|
||||
|
||||
/*
|
||||
Fast path for `Int`s that fit within a single `DIGIT`.
|
||||
*/
|
||||
if a.used == 1 { return internal_log(a.digit[0], DIGIT(base)); }
|
||||
if a.used == 1 { return internal_log(a.digit[0], DIGIT(base)) }
|
||||
|
||||
return _private_int_log(a, base)
|
||||
|
||||
@@ -1270,12 +1270,12 @@ internal_digit_log :: proc(a: DIGIT, base: DIGIT) -> (log: int, err: Error) {
|
||||
If the number is smaller than the base, it fits within a fraction.
|
||||
Therefore, we return 0.
|
||||
*/
|
||||
if a < base { return 0, nil; }
|
||||
if a < base { return 0, nil }
|
||||
|
||||
/*
|
||||
If a number equals the base, the log is 1.
|
||||
*/
|
||||
if a == base { return 1, nil; }
|
||||
if a == base { return 1, nil }
|
||||
|
||||
N := _WORD(a)
|
||||
bracket_low := _WORD(1)
|
||||
@@ -1334,8 +1334,8 @@ internal_int_pow :: proc(dest, base: ^Int, power: int, allocator := context.allo
|
||||
internal_zero(dest) or_return
|
||||
return .Math_Domain_Error
|
||||
}
|
||||
if power == 0 { return internal_one(dest); }
|
||||
if power > 0 { return internal_zero(dest); }
|
||||
if power == 0 { return internal_one(dest) }
|
||||
if power > 0 { return internal_zero(dest) }
|
||||
|
||||
}
|
||||
if power < 0 {
|
||||
@@ -1435,12 +1435,12 @@ internal_int_sqrt :: proc(dest, src: ^Int, allocator := context.allocator) -> (e
|
||||
/*
|
||||
Must be positive.
|
||||
*/
|
||||
if #force_inline internal_is_negative(src) { return .Invalid_Argument; }
|
||||
if #force_inline internal_is_negative(src) { return .Invalid_Argument }
|
||||
|
||||
/*
|
||||
Easy out. If src is zero, so is dest.
|
||||
*/
|
||||
if #force_inline internal_is_zero(src) { return internal_zero(dest); }
|
||||
if #force_inline internal_is_zero(src) { return internal_zero(dest) }
|
||||
|
||||
/*
|
||||
Set up temporaries.
|
||||
@@ -1489,11 +1489,11 @@ internal_int_root_n :: proc(dest, src: ^Int, n: int, allocator := context.alloca
|
||||
/*
|
||||
Fast path for n == 2
|
||||
*/
|
||||
if n == 2 { return #force_inline internal_sqrt(dest, src); }
|
||||
if n == 2 { return #force_inline internal_sqrt(dest, src) }
|
||||
|
||||
if n < 0 || n > int(_DIGIT_MAX) { return .Invalid_Argument; }
|
||||
if n < 0 || n > int(_DIGIT_MAX) { return .Invalid_Argument }
|
||||
|
||||
if n & 1 == 0 && #force_inline internal_is_negative(src) { return .Invalid_Argument; }
|
||||
if n & 1 == 0 && #force_inline internal_is_negative(src) { return .Invalid_Argument }
|
||||
|
||||
/*
|
||||
Set up temporaries.
|
||||
@@ -1576,8 +1576,8 @@ internal_int_root_n :: proc(dest, src: ^Int, n: int, allocator := context.alloca
|
||||
Number of rounds is at most log_2(root). If it is more it
|
||||
got stuck, so break out of the loop and do the rest manually.
|
||||
*/
|
||||
if ilog2 -= 1; ilog2 == 0 { break; }
|
||||
if internal_cmp(t1, t2) == 0 { break; }
|
||||
if ilog2 -= 1; ilog2 == 0 { break }
|
||||
if internal_cmp(t1, t2) == 0 { break }
|
||||
|
||||
iterations += 1
|
||||
if iterations == MAX_ITERATIONS_ROOT_N {
|
||||
@@ -1615,7 +1615,7 @@ internal_int_root_n :: proc(dest, src: ^Int, n: int, allocator := context.alloca
|
||||
for {
|
||||
internal_pow(t2, t1, n) or_return
|
||||
|
||||
if internal_cmp(t2, a) != 1 { break; }
|
||||
if internal_cmp(t2, a) != 1 { break }
|
||||
|
||||
internal_sub(t1, t1, DIGIT(1)) or_return
|
||||
|
||||
@@ -1712,7 +1712,7 @@ internal_int_copy :: proc(dest, src: ^Int, minimize := false, allocator := conte
|
||||
/*
|
||||
If dest == src, do nothing
|
||||
*/
|
||||
if (dest == src) { return nil; }
|
||||
if (dest == src) { return nil }
|
||||
|
||||
internal_error_if_immutable(dest) or_return
|
||||
|
||||
@@ -1821,17 +1821,17 @@ internal_int_inverse_modulo :: proc(dest, a, b: ^Int, allocator := context.alloc
|
||||
/*
|
||||
For all n in N and n > 0, n = 0 mod 1.
|
||||
*/
|
||||
if internal_is_positive(a) && internal_cmp(b, 1) == 0 { return internal_zero(dest); }
|
||||
if internal_is_positive(a) && internal_cmp(b, 1) == 0 { return internal_zero(dest) }
|
||||
|
||||
/*
|
||||
`b` cannot be negative and has to be > 1
|
||||
*/
|
||||
if internal_is_negative(b) && internal_cmp(b, 1) != 1 { return .Invalid_Argument; }
|
||||
if internal_is_negative(b) && internal_cmp(b, 1) != 1 { return .Invalid_Argument }
|
||||
|
||||
/*
|
||||
If the modulus is odd we can use a faster routine instead.
|
||||
*/
|
||||
if internal_is_odd(b) { return _private_inverse_modulo_odd(dest, a, b); }
|
||||
if internal_is_odd(b) { return _private_inverse_modulo_odd(dest, a, b) }
|
||||
|
||||
return _private_inverse_modulo(dest, a, b)
|
||||
}
|
||||
@@ -1850,12 +1850,12 @@ internal_int_bitfield_extract :: proc(a: ^Int, offset, count: int) -> (res: _WOR
|
||||
*/
|
||||
if count == 1 {
|
||||
limb := offset / _DIGIT_BITS
|
||||
if limb < 0 || limb >= a.used { return 0, .Invalid_Argument; }
|
||||
if limb < 0 || limb >= a.used { return 0, .Invalid_Argument }
|
||||
i := _WORD(1 << _WORD((offset % _DIGIT_BITS)))
|
||||
return 1 if ((_WORD(a.digit[limb]) & i) != 0) else 0, nil
|
||||
}
|
||||
|
||||
if count > _WORD_BITS || count < 1 { return 0, .Invalid_Argument; }
|
||||
if count > _WORD_BITS || count < 1 { return 0, .Invalid_Argument }
|
||||
|
||||
/*
|
||||
There are 3 possible cases.
|
||||
@@ -1880,7 +1880,7 @@ internal_int_bitfield_extract :: proc(a: ^Int, offset, count: int) -> (res: _WOR
|
||||
res = (_WORD(a.digit[limb]) >> uint(shift)) & mask
|
||||
|
||||
bits_left -= num_bits
|
||||
if bits_left == 0 { return res, nil; }
|
||||
if bits_left == 0 { return res, nil }
|
||||
|
||||
res_shift := num_bits
|
||||
num_bits = min(bits_left, _DIGIT_BITS)
|
||||
@@ -1889,7 +1889,7 @@ internal_int_bitfield_extract :: proc(a: ^Int, offset, count: int) -> (res: _WOR
|
||||
res |= (_WORD(a.digit[limb + 1]) & mask) << uint(res_shift)
|
||||
|
||||
bits_left -= num_bits
|
||||
if bits_left == 0 { return res, nil; }
|
||||
if bits_left == 0 { return res, nil }
|
||||
|
||||
mask = (1 << uint(bits_left)) - 1
|
||||
res_shift += _DIGIT_BITS
|
||||
@@ -1908,7 +1908,7 @@ internal_int_bitfield_extract :: proc(a: ^Int, offset, count: int) -> (res: _WOR
|
||||
internal_int_shrink :: proc(a: ^Int) -> (err: Error) {
|
||||
needed := max(_MIN_DIGIT_COUNT, a.used)
|
||||
|
||||
if a.used != needed { return internal_grow(a, needed, true); }
|
||||
if a.used != needed { return internal_grow(a, needed, true) }
|
||||
return nil
|
||||
}
|
||||
internal_shrink :: proc { internal_int_shrink, }
|
||||
@@ -2006,7 +2006,7 @@ internal_nan :: proc { internal_int_nan, }
|
||||
internal_int_power_of_two :: proc(a: ^Int, power: int, allocator := context.allocator) -> (err: Error) {
|
||||
context.allocator = allocator
|
||||
|
||||
if power < 0 || power > _MAX_BIT_COUNT { return .Invalid_Argument; }
|
||||
if power < 0 || power > _MAX_BIT_COUNT { return .Invalid_Argument }
|
||||
|
||||
/*
|
||||
Grow to accomodate the single bit.
|
||||
@@ -2080,7 +2080,7 @@ internal_int_get :: proc(a: ^Int, $T: typeid) -> (res: T, err: Error) where intr
|
||||
/*
|
||||
Set the sign.
|
||||
*/
|
||||
if a.sign == .Negative { res = -res; }
|
||||
if a.sign == .Negative { res = -res }
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -2326,7 +2326,7 @@ internal_int_shrmod :: proc(quotient, remainder, numerator: ^Int, bits: int, all
|
||||
context.allocator = allocator
|
||||
|
||||
bits := bits
|
||||
if bits < 0 { return .Invalid_Argument; }
|
||||
if bits < 0 { return .Invalid_Argument }
|
||||
|
||||
internal_copy(quotient, numerator) or_return
|
||||
|
||||
@@ -2387,12 +2387,12 @@ internal_shr :: proc { internal_int_shr, }
|
||||
internal_int_shr_digit :: proc(quotient: ^Int, digits: int, allocator := context.allocator) -> (err: Error) {
|
||||
context.allocator = allocator
|
||||
|
||||
if digits <= 0 { return nil; }
|
||||
if digits <= 0 { return nil }
|
||||
|
||||
/*
|
||||
If digits > used simply zero and return.
|
||||
*/
|
||||
if digits > quotient.used { return internal_zero(quotient); }
|
||||
if digits > quotient.used { return internal_zero(quotient) }
|
||||
|
||||
/*
|
||||
Much like `int_shl_digit`, this is implemented using a sliding window,
|
||||
@@ -2436,7 +2436,7 @@ internal_int_shl :: proc(dest, src: ^Int, bits: int, allocator := context.alloca
|
||||
|
||||
bits := bits
|
||||
|
||||
if bits < 0 { return .Invalid_Argument; }
|
||||
if bits < 0 { return .Invalid_Argument }
|
||||
|
||||
internal_copy(dest, src) or_return
|
||||
|
||||
@@ -2487,7 +2487,7 @@ internal_shl :: proc { internal_int_shl, }
|
||||
internal_int_shl_digit :: proc(quotient: ^Int, digits: int, allocator := context.allocator) -> (err: Error) {
|
||||
context.allocator = allocator
|
||||
|
||||
if digits <= 0 { return nil; }
|
||||
if digits <= 0 { return nil }
|
||||
|
||||
/*
|
||||
No need to shift a zero.
|
||||
@@ -2527,7 +2527,7 @@ internal_count_bits :: proc(a: ^Int) -> (count: int) {
|
||||
/*
|
||||
Fast path for zero.
|
||||
*/
|
||||
if #force_inline internal_is_zero(a) { return {}; }
|
||||
if #force_inline internal_is_zero(a) { return {} }
|
||||
/*
|
||||
Get the number of DIGITs and use it.
|
||||
*/
|
||||
@@ -2550,7 +2550,7 @@ internal_int_count_lsb :: proc(a: ^Int) -> (count: int, err: Error) {
|
||||
/*
|
||||
Easy out.
|
||||
*/
|
||||
if #force_inline internal_is_zero(a) { return {}, nil; }
|
||||
if #force_inline internal_is_zero(a) { return {}, nil }
|
||||
|
||||
/*
|
||||
Scan lower digits until non-zero.
|
||||
@@ -2588,7 +2588,7 @@ internal_int_rand :: proc(dest: ^Int, bits: int, r: ^rnd.Rand = nil, allocator :
|
||||
|
||||
bits := bits
|
||||
|
||||
if bits <= 0 { return .Invalid_Argument; }
|
||||
if bits <= 0 { return .Invalid_Argument }
|
||||
|
||||
digits := bits / _DIGIT_BITS
|
||||
bits %= _DIGIT_BITS
|
||||
@@ -2632,7 +2632,7 @@ internal_clear_if_uninitialized_multi :: proc(args: ..^Int, allocator := context
|
||||
for i in args {
|
||||
if ! #force_inline internal_is_initialized(i) {
|
||||
e := #force_inline internal_grow(i, _DEFAULT_DIGIT_COUNT)
|
||||
if e != nil { err = e; }
|
||||
if e != nil { err = e }
|
||||
}
|
||||
}
|
||||
return err
|
||||
@@ -2640,13 +2640,13 @@ internal_clear_if_uninitialized_multi :: proc(args: ..^Int, allocator := context
|
||||
internal_clear_if_uninitialized :: proc {internal_clear_if_uninitialized_single, internal_clear_if_uninitialized_multi, }
|
||||
|
||||
internal_error_if_immutable_single :: proc(arg: ^Int) -> (err: Error) {
|
||||
if arg != nil && .Immutable in arg.flags { return .Assignment_To_Immutable; }
|
||||
if arg != nil && .Immutable in arg.flags { return .Assignment_To_Immutable }
|
||||
return nil
|
||||
}
|
||||
|
||||
internal_error_if_immutable_multi :: proc(args: ..^Int) -> (err: Error) {
|
||||
for i in args {
|
||||
if i != nil && .Immutable in i.flags { return .Assignment_To_Immutable; }
|
||||
if i != nil && .Immutable in i.flags { return .Assignment_To_Immutable }
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -2674,9 +2674,9 @@ internal_init_multi :: proc { internal_int_init_multi, }
|
||||
Typically very fast. Also fixes the sign if there are no more leading digits.
|
||||
*/
|
||||
internal_clamp :: proc(a: ^Int) -> (err: Error) {
|
||||
for a.used > 0 && a.digit[a.used - 1] == 0 { a.used -= 1; }
|
||||
for a.used > 0 && a.digit[a.used - 1] == 0 { a.used -= 1 }
|
||||
|
||||
if #force_inline internal_is_zero(a) { a.sign = .Zero_or_Positive; }
|
||||
if #force_inline internal_is_zero(a) { a.sign = .Zero_or_Positive }
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ int_shrmod :: proc(quotient, remainder, numerator: ^Int, bits: int, allocator :=
|
||||
assert_if_nil(quotient, numerator)
|
||||
context.allocator = allocator
|
||||
|
||||
if err = internal_clear_if_uninitialized(quotient, numerator); err != nil { return err; }
|
||||
if err = internal_clear_if_uninitialized(quotient, numerator); err != nil { return err }
|
||||
return #force_inline internal_int_shrmod(quotient, remainder, numerator, bits)
|
||||
}
|
||||
shrmod :: proc { int_shrmod, }
|
||||
|
||||
@@ -183,7 +183,7 @@ internal_int_montgomery_setup :: proc(n: ^Int) -> (rho: DIGIT, err: Error) {
|
||||
=> 2*(1) - (1) = 1
|
||||
*/
|
||||
b := n.digit[0]
|
||||
if b & 1 == 0 { return 0, .Invalid_Argument; }
|
||||
if b & 1 == 0 { return 0, .Invalid_Argument }
|
||||
|
||||
x := (((b + 2) & 4) << 1) + b /* here x*a==1 mod 2**4 */
|
||||
x *= 2 - (b * x) /* here x*a==1 mod 2**8 */
|
||||
|
||||
@@ -1088,7 +1088,7 @@ _private_int_div_school :: proc(quotient, remainder, numerator, denominator: ^In
|
||||
Step 3. for i from n down to (t + 1).
|
||||
*/
|
||||
#no_bounds_check for i := n; i >= (t + 1); i -= 1 {
|
||||
if (i > x.used) { continue; }
|
||||
if (i > x.used) { continue }
|
||||
|
||||
/*
|
||||
step 3.1 if xi == yt then set q{i-t-1} to b-1, otherwise set q{i-t-1} to (xi*b + x{i-1})/yt
|
||||
@@ -1744,7 +1744,7 @@ _private_montgomery_reduce_comba :: proc(x, n: ^Int, rho: DIGIT, allocator := co
|
||||
context.allocator = allocator
|
||||
W: [_WARRAY]_WORD = ---
|
||||
|
||||
if x.used > _WARRAY { return .Invalid_Argument; }
|
||||
if x.used > _WARRAY { return .Invalid_Argument }
|
||||
|
||||
/*
|
||||
Get old used count.
|
||||
@@ -2022,7 +2022,7 @@ _private_inverse_modulo_odd :: proc(dest, a, b: ^Int, allocator := context.alloc
|
||||
/*
|
||||
2. [modified] `b` must be odd.
|
||||
*/
|
||||
if internal_is_even(b) { return .Invalid_Argument; }
|
||||
if internal_is_even(b) { return .Invalid_Argument }
|
||||
|
||||
/*
|
||||
Init all our temps.
|
||||
@@ -2042,7 +2042,7 @@ _private_inverse_modulo_odd :: proc(dest, a, b: ^Int, allocator := context.alloc
|
||||
/*
|
||||
If one of `x`, `y` is zero return an error!
|
||||
*/
|
||||
if internal_is_zero(x) || internal_is_zero(y) { return .Invalid_Argument; }
|
||||
if internal_is_zero(x) || internal_is_zero(y) { return .Invalid_Argument }
|
||||
|
||||
/*
|
||||
3. `u` = `x`, `v` = `y`, `A` = 1, `B` = 0, `C` = 0, `D` = 1
|
||||
@@ -2122,7 +2122,7 @@ _private_inverse_modulo_odd :: proc(dest, a, b: ^Int, allocator := context.alloc
|
||||
/*
|
||||
If not zero goto step 4.
|
||||
*/
|
||||
if internal_is_zero(u) { break; }
|
||||
if internal_is_zero(u) { break }
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+10
-10
@@ -120,7 +120,7 @@ int_double :: proc(dest, src: ^Int, allocator := context.allocator) -> (err: Err
|
||||
/*
|
||||
Grow destination as required.
|
||||
*/
|
||||
if dest != src { grow(dest, src.used + 1) or_return; }
|
||||
if dest != src { grow(dest, src.used + 1) or_return }
|
||||
|
||||
return #force_inline internal_int_shl1(dest, src)
|
||||
}
|
||||
@@ -153,7 +153,7 @@ int_mul :: proc(dest, src, multiplier: ^Int, allocator := context.allocator) ->
|
||||
|
||||
mul :: proc { int_mul, int_mul_digit, }
|
||||
|
||||
sqr :: proc(dest, src: ^Int) -> (err: Error) { return mul(dest, src, src); }
|
||||
sqr :: proc(dest, src: ^Int) -> (err: Error) { return mul(dest, src, src) }
|
||||
|
||||
/*
|
||||
divmod.
|
||||
@@ -165,7 +165,7 @@ int_divmod :: proc(quotient, remainder, numerator, denominator: ^Int, allocator
|
||||
/*
|
||||
Early out if neither of the results is wanted.
|
||||
*/
|
||||
if quotient == nil && remainder == nil { return nil; }
|
||||
if quotient == nil && remainder == nil { return nil }
|
||||
internal_clear_if_uninitialized(numerator, denominator) or_return
|
||||
|
||||
return #force_inline internal_divmod(quotient, remainder, numerator, denominator)
|
||||
@@ -275,7 +275,7 @@ sqrmod :: proc { int_sqrmod, }
|
||||
|
||||
|
||||
int_factorial :: proc(res: ^Int, n: int, allocator := context.allocator) -> (err: Error) {
|
||||
if n < 0 || n > FACTORIAL_MAX_N { return .Invalid_Argument; }
|
||||
if n < 0 || n > FACTORIAL_MAX_N { return .Invalid_Argument }
|
||||
assert_if_nil(res)
|
||||
|
||||
return #force_inline internal_int_factorial(res, n, allocator)
|
||||
@@ -302,8 +302,8 @@ int_choose_digit :: proc(res: ^Int, n, k: int, allocator := context.allocator) -
|
||||
assert_if_nil(res)
|
||||
context.allocator = allocator
|
||||
|
||||
if n < 0 || n > FACTORIAL_MAX_N { return .Invalid_Argument; }
|
||||
if k > n { return internal_zero(res); }
|
||||
if n < 0 || n > FACTORIAL_MAX_N { return .Invalid_Argument }
|
||||
if k > n { return internal_zero(res) }
|
||||
|
||||
/*
|
||||
res = n! / (k! * (n - k)!)
|
||||
@@ -326,7 +326,7 @@ choose :: proc { int_choose_digit, }
|
||||
Function computing both GCD and (if target isn't `nil`) also LCM.
|
||||
*/
|
||||
int_gcd_lcm :: proc(res_gcd, res_lcm, a, b: ^Int, allocator := context.allocator) -> (err: Error) {
|
||||
if res_gcd == nil && res_lcm == nil { return nil; }
|
||||
if res_gcd == nil && res_lcm == nil { return nil }
|
||||
assert_if_nil(a, b)
|
||||
context.allocator = allocator
|
||||
|
||||
@@ -359,7 +359,7 @@ int_mod_bits :: proc(remainder, numerator: ^Int, bits: int, allocator := context
|
||||
context.allocator = allocator
|
||||
|
||||
internal_clear_if_uninitialized(remainder, numerator) or_return
|
||||
if bits < 0 { return .Invalid_Argument; }
|
||||
if bits < 0 { return .Invalid_Argument }
|
||||
|
||||
return #force_inline internal_int_mod_bits(remainder, numerator, bits)
|
||||
}
|
||||
@@ -439,7 +439,7 @@ int_root_n :: proc(dest, src: ^Int, n: int, allocator := context.allocator) -> (
|
||||
/*
|
||||
Fast path for n == 2.
|
||||
*/
|
||||
if n == 2 { return sqrt(dest, src); }
|
||||
if n == 2 { return sqrt(dest, src) }
|
||||
|
||||
assert_if_nil(dest, src)
|
||||
/*
|
||||
@@ -456,7 +456,7 @@ root_n :: proc { int_root_n, }
|
||||
*/
|
||||
|
||||
int_is_initialized :: proc(a: ^Int) -> bool {
|
||||
if a == nil { return false; }
|
||||
if a == nil { return false }
|
||||
|
||||
return #force_inline internal_int_is_initialized(a)
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ int_atoi :: proc(res: ^Int, input: string, radix := i8(10), allocator := context
|
||||
Make sure the radix is ok.
|
||||
*/
|
||||
|
||||
if radix < 2 || radix > 64 { return .Invalid_Argument; }
|
||||
if radix < 2 || radix > 64 { return .Invalid_Argument }
|
||||
|
||||
/*
|
||||
Set the integer to the default of zero.
|
||||
@@ -327,7 +327,7 @@ radix_size :: proc(a: ^Int, radix: i8, zero_terminate := false, allocator := con
|
||||
a := a
|
||||
assert_if_nil(a)
|
||||
|
||||
if radix < 2 || radix > 64 { return -1, .Invalid_Argument; }
|
||||
if radix < 2 || radix > 64 { return -1, .Invalid_Argument }
|
||||
clear_if_uninitialized(a) or_return
|
||||
|
||||
if internal_is_zero(a) {
|
||||
|
||||
+60
-60
@@ -44,17 +44,17 @@ PyRes :: struct {
|
||||
aa, bb, sum := &Int{}, &Int{}, &Int{}
|
||||
defer internal_destroy(aa, bb, sum)
|
||||
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":add:atoi(a):", err=err}; }
|
||||
if err = atoi(bb, string(b), 16); err != nil { return PyRes{res=":add:atoi(b):", err=err}; }
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":add:atoi(a):", err=err} }
|
||||
if err = atoi(bb, string(b), 16); err != nil { return PyRes{res=":add:atoi(b):", err=err} }
|
||||
if bb.used == 1 {
|
||||
if err = #force_inline internal_add(sum, aa, bb.digit[0]); err != nil { return PyRes{res=":add:add(sum,a,b):", err=err}; }
|
||||
if err = #force_inline internal_add(sum, aa, bb.digit[0]); err != nil { return PyRes{res=":add:add(sum,a,b):", err=err} }
|
||||
} else {
|
||||
if err = #force_inline internal_add(sum, aa, bb); err != nil { return PyRes{res=":add:add(sum,a,b):", err=err}; }
|
||||
if err = #force_inline internal_add(sum, aa, bb); err != nil { return PyRes{res=":add:add(sum,a,b):", err=err} }
|
||||
}
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(sum, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":add:itoa(sum):", err=err}; }
|
||||
if err != nil { return PyRes{res=":add:itoa(sum):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -65,17 +65,17 @@ PyRes :: struct {
|
||||
aa, bb, sum := &Int{}, &Int{}, &Int{}
|
||||
defer internal_destroy(aa, bb, sum)
|
||||
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":sub:atoi(a):", err=err}; }
|
||||
if err = atoi(bb, string(b), 16); err != nil { return PyRes{res=":sub:atoi(b):", err=err}; }
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":sub:atoi(a):", err=err} }
|
||||
if err = atoi(bb, string(b), 16); err != nil { return PyRes{res=":sub:atoi(b):", err=err} }
|
||||
if bb.used == 1 {
|
||||
if err = #force_inline internal_sub(sum, aa, bb.digit[0]); err != nil { return PyRes{res=":sub:sub(sum,a,b):", err=err}; }
|
||||
if err = #force_inline internal_sub(sum, aa, bb.digit[0]); err != nil { return PyRes{res=":sub:sub(sum,a,b):", err=err} }
|
||||
} else {
|
||||
if err = #force_inline internal_sub(sum, aa, bb); err != nil { return PyRes{res=":sub:sub(sum,a,b):", err=err}; }
|
||||
if err = #force_inline internal_sub(sum, aa, bb); err != nil { return PyRes{res=":sub:sub(sum,a,b):", err=err} }
|
||||
}
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(sum, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":sub:itoa(sum):", err=err}; }
|
||||
if err != nil { return PyRes{res=":sub:itoa(sum):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -86,13 +86,13 @@ PyRes :: struct {
|
||||
aa, bb, product := &Int{}, &Int{}, &Int{}
|
||||
defer internal_destroy(aa, bb, product)
|
||||
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":mul:atoi(a):", err=err}; }
|
||||
if err = atoi(bb, string(b), 16); err != nil { return PyRes{res=":mul:atoi(b):", err=err}; }
|
||||
if err = #force_inline internal_mul(product, aa, bb); err != nil { return PyRes{res=":mul:mul(product,a,b):", err=err}; }
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":mul:atoi(a):", err=err} }
|
||||
if err = atoi(bb, string(b), 16); err != nil { return PyRes{res=":mul:atoi(b):", err=err} }
|
||||
if err = #force_inline internal_mul(product, aa, bb); err != nil { return PyRes{res=":mul:mul(product,a,b):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(product, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":mul:itoa(product):", err=err}; }
|
||||
if err != nil { return PyRes{res=":mul:itoa(product):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -103,12 +103,12 @@ PyRes :: struct {
|
||||
aa, square := &Int{}, &Int{}
|
||||
defer internal_destroy(aa, square)
|
||||
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":sqr:atoi(a):", err=err}; }
|
||||
if err = #force_inline internal_sqr(square, aa); err != nil { return PyRes{res=":sqr:sqr(square,a):", err=err}; }
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":sqr:atoi(a):", err=err} }
|
||||
if err = #force_inline internal_sqr(square, aa); err != nil { return PyRes{res=":sqr:sqr(square,a):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(square, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":sqr:itoa(square):", err=err}; }
|
||||
if err != nil { return PyRes{res=":sqr:itoa(square):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -122,13 +122,13 @@ PyRes :: struct {
|
||||
aa, bb, quotient := &Int{}, &Int{}, &Int{}
|
||||
defer internal_destroy(aa, bb, quotient)
|
||||
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":div:atoi(a):", err=err}; }
|
||||
if err = atoi(bb, string(b), 16); err != nil { return PyRes{res=":div:atoi(b):", err=err}; }
|
||||
if err = #force_inline internal_div(quotient, aa, bb); err != nil { return PyRes{res=":div:div(quotient,a,b):", err=err}; }
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":div:atoi(a):", err=err} }
|
||||
if err = atoi(bb, string(b), 16); err != nil { return PyRes{res=":div:atoi(b):", err=err} }
|
||||
if err = #force_inline internal_div(quotient, aa, bb); err != nil { return PyRes{res=":div:div(quotient,a,b):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(quotient, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":div:itoa(quotient):", err=err}; }
|
||||
if err != nil { return PyRes{res=":div:itoa(quotient):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -144,8 +144,8 @@ PyRes :: struct {
|
||||
aa := &Int{}
|
||||
defer internal_destroy(aa)
|
||||
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":log:atoi(a):", err=err}; }
|
||||
if l, err = #force_inline internal_log(aa, base); err != nil { return PyRes{res=":log:log(a, base):", err=err}; }
|
||||
if err = atoi(aa, string(a), 16); err != nil { return PyRes{res=":log:atoi(a):", err=err} }
|
||||
if l, err = #force_inline internal_log(aa, base); err != nil { return PyRes{res=":log:log(a, base):", err=err} }
|
||||
|
||||
#force_inline internal_zero(aa)
|
||||
aa.digit[0] = DIGIT(l) & _MASK
|
||||
@@ -155,7 +155,7 @@ PyRes :: struct {
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(aa, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":log:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":log:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -169,12 +169,12 @@ PyRes :: struct {
|
||||
dest, bb := &Int{}, &Int{}
|
||||
defer internal_destroy(dest, bb)
|
||||
|
||||
if err = atoi(bb, string(base), 16); err != nil { return PyRes{res=":pow:atoi(base):", err=err}; }
|
||||
if err = #force_inline internal_pow(dest, bb, power); err != nil { return PyRes{res=":pow:pow(dest, base, power):", err=err}; }
|
||||
if err = atoi(bb, string(base), 16); err != nil { return PyRes{res=":pow:atoi(base):", err=err} }
|
||||
if err = #force_inline internal_pow(dest, bb, power); err != nil { return PyRes{res=":pow:pow(dest, base, power):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(dest, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":log:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":log:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -188,12 +188,12 @@ PyRes :: struct {
|
||||
src := &Int{}
|
||||
defer internal_destroy(src)
|
||||
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":sqrt:atoi(src):", err=err}; }
|
||||
if err = #force_inline internal_sqrt(src, src); err != nil { return PyRes{res=":sqrt:sqrt(src):", err=err}; }
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":sqrt:atoi(src):", err=err} }
|
||||
if err = #force_inline internal_sqrt(src, src); err != nil { return PyRes{res=":sqrt:sqrt(src):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(src, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":log:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":log:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -207,12 +207,12 @@ PyRes :: struct {
|
||||
src := &Int{}
|
||||
defer internal_destroy(src)
|
||||
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":root_n:atoi(src):", err=err}; }
|
||||
if err = #force_inline internal_root_n(src, src, power); err != nil { return PyRes{res=":root_n:root_n(src):", err=err}; }
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":root_n:atoi(src):", err=err} }
|
||||
if err = #force_inline internal_root_n(src, src, power); err != nil { return PyRes{res=":root_n:root_n(src):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(src, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":root_n:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":root_n:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -226,12 +226,12 @@ PyRes :: struct {
|
||||
src := &Int{}
|
||||
defer internal_destroy(src)
|
||||
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":shr_digit:atoi(src):", err=err}; }
|
||||
if err = #force_inline internal_shr_digit(src, digits); err != nil { return PyRes{res=":shr_digit:shr_digit(src):", err=err}; }
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":shr_digit:atoi(src):", err=err} }
|
||||
if err = #force_inline internal_shr_digit(src, digits); err != nil { return PyRes{res=":shr_digit:shr_digit(src):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(src, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":shr_digit:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":shr_digit:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -245,12 +245,12 @@ PyRes :: struct {
|
||||
src := &Int{}
|
||||
defer internal_destroy(src)
|
||||
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":shl_digit:atoi(src):", err=err}; }
|
||||
if err = #force_inline internal_shl_digit(src, digits); err != nil { return PyRes{res=":shl_digit:shr_digit(src):", err=err}; }
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":shl_digit:atoi(src):", err=err} }
|
||||
if err = #force_inline internal_shl_digit(src, digits); err != nil { return PyRes{res=":shl_digit:shr_digit(src):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(src, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":shl_digit:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":shl_digit:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -264,12 +264,12 @@ PyRes :: struct {
|
||||
src := &Int{}
|
||||
defer internal_destroy(src)
|
||||
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":shr:atoi(src):", err=err}; }
|
||||
if err = #force_inline internal_shr(src, src, bits); err != nil { return PyRes{res=":shr:shr(src, bits):", err=err}; }
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":shr:atoi(src):", err=err} }
|
||||
if err = #force_inline internal_shr(src, src, bits); err != nil { return PyRes{res=":shr:shr(src, bits):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(src, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":shr:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":shr:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -283,12 +283,12 @@ PyRes :: struct {
|
||||
src := &Int{}
|
||||
defer internal_destroy(src)
|
||||
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":shr_signed:atoi(src):", err=err}; }
|
||||
if err = #force_inline internal_shr_signed(src, src, bits); err != nil { return PyRes{res=":shr_signed:shr_signed(src, bits):", err=err}; }
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":shr_signed:atoi(src):", err=err} }
|
||||
if err = #force_inline internal_shr_signed(src, src, bits); err != nil { return PyRes{res=":shr_signed:shr_signed(src, bits):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(src, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":shr_signed:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":shr_signed:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -302,12 +302,12 @@ PyRes :: struct {
|
||||
src := &Int{}
|
||||
defer internal_destroy(src)
|
||||
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":shl:atoi(src):", err=err}; }
|
||||
if err = #force_inline internal_shl(src, src, bits); err != nil { return PyRes{res=":shl:shl(src, bits):", err=err}; }
|
||||
if err = atoi(src, string(source), 16); err != nil { return PyRes{res=":shl:atoi(src):", err=err} }
|
||||
if err = #force_inline internal_shl(src, src, bits); err != nil { return PyRes{res=":shl:shl(src, bits):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(src, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":shl:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":shl:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -321,11 +321,11 @@ PyRes :: struct {
|
||||
dest := &Int{}
|
||||
defer internal_destroy(dest)
|
||||
|
||||
if err = #force_inline internal_int_factorial(dest, n); err != nil { return PyRes{res=":factorial:factorial(n):", err=err}; }
|
||||
if err = #force_inline internal_int_factorial(dest, n); err != nil { return PyRes{res=":factorial:factorial(n):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(dest, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":factorial:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":factorial:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -339,13 +339,13 @@ PyRes :: struct {
|
||||
ai, bi, dest := &Int{}, &Int{}, &Int{}
|
||||
defer internal_destroy(ai, bi, dest)
|
||||
|
||||
if err = atoi(ai, string(a), 16); err != nil { return PyRes{res=":gcd:atoi(a):", err=err}; }
|
||||
if err = atoi(bi, string(b), 16); err != nil { return PyRes{res=":gcd:atoi(b):", err=err}; }
|
||||
if err = #force_inline internal_int_gcd_lcm(dest, nil, ai, bi); err != nil { return PyRes{res=":gcd:gcd(a, b):", err=err}; }
|
||||
if err = atoi(ai, string(a), 16); err != nil { return PyRes{res=":gcd:atoi(a):", err=err} }
|
||||
if err = atoi(bi, string(b), 16); err != nil { return PyRes{res=":gcd:atoi(b):", err=err} }
|
||||
if err = #force_inline internal_int_gcd_lcm(dest, nil, ai, bi); err != nil { return PyRes{res=":gcd:gcd(a, b):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(dest, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":gcd:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":gcd:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -359,13 +359,13 @@ PyRes :: struct {
|
||||
ai, bi, dest := &Int{}, &Int{}, &Int{}
|
||||
defer internal_destroy(ai, bi, dest)
|
||||
|
||||
if err = atoi(ai, string(a), 16); err != nil { return PyRes{res=":lcm:atoi(a):", err=err}; }
|
||||
if err = atoi(bi, string(b), 16); err != nil { return PyRes{res=":lcm:atoi(b):", err=err}; }
|
||||
if err = #force_inline internal_int_gcd_lcm(nil, dest, ai, bi); err != nil { return PyRes{res=":lcm:lcm(a, b):", err=err}; }
|
||||
if err = atoi(ai, string(a), 16); err != nil { return PyRes{res=":lcm:atoi(a):", err=err} }
|
||||
if err = atoi(bi, string(b), 16); err != nil { return PyRes{res=":lcm:atoi(b):", err=err} }
|
||||
if err = #force_inline internal_int_gcd_lcm(nil, dest, ai, bi); err != nil { return PyRes{res=":lcm:lcm(a, b):", err=err} }
|
||||
|
||||
r: cstring
|
||||
r, err = int_itoa_cstring(dest, 16, context.temp_allocator)
|
||||
if err != nil { return PyRes{res=":lcm:itoa(res):", err=err}; }
|
||||
if err != nil { return PyRes{res=":lcm:itoa(res):", err=err} }
|
||||
return PyRes{res = r, err = nil}
|
||||
}
|
||||
|
||||
@@ -380,8 +380,8 @@ PyRes :: struct {
|
||||
ai := &Int{}
|
||||
defer internal_destroy(ai)
|
||||
|
||||
if err = atoi(ai, string(a), 16); err != nil { return PyRes{res=":is_square:atoi(a):", err=err}; }
|
||||
if square, err = #force_inline internal_int_is_square(ai); err != nil { return PyRes{res=":is_square:is_square(a):", err=err}; }
|
||||
if err = atoi(ai, string(a), 16); err != nil { return PyRes{res=":is_square:atoi(a):", err=err} }
|
||||
if square, err = #force_inline internal_int_is_square(ai); err != nil { return PyRes{res=":is_square:is_square(a):", err=err} }
|
||||
|
||||
if square {
|
||||
return PyRes{"True", nil}
|
||||
|
||||
+36
-36
@@ -64,30 +64,30 @@ rotate_left :: proc(x: uint, k: int) -> uint {
|
||||
return x <<s | x>>(n-s)
|
||||
}
|
||||
|
||||
from_be_u8 :: proc(i: u8) -> u8 { return i; }
|
||||
from_be_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
from_be_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
from_be_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
from_be_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
from_be_u8 :: proc(i: u8) -> u8 { return i }
|
||||
from_be_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "big" { return i } else { return byte_swap(i) } }
|
||||
from_be_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "big" { return i } else { return byte_swap(i) } }
|
||||
from_be_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "big" { return i } else { return byte_swap(i) } }
|
||||
from_be_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "big" { return i } else { return byte_swap(i) } }
|
||||
|
||||
from_le_u8 :: proc(i: u8) -> u8 { return i; }
|
||||
from_le_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
from_le_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
from_le_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
from_le_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
from_le_u8 :: proc(i: u8) -> u8 { return i }
|
||||
from_le_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "little" { return i } else { return byte_swap(i) } }
|
||||
from_le_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "little" { return i } else { return byte_swap(i) } }
|
||||
from_le_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "little" { return i } else { return byte_swap(i) } }
|
||||
from_le_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "little" { return i } else { return byte_swap(i) } }
|
||||
|
||||
to_be_u8 :: proc(i: u8) -> u8 { return i; }
|
||||
to_be_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
to_be_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
to_be_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
to_be_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
to_be_u8 :: proc(i: u8) -> u8 { return i }
|
||||
to_be_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "big" { return i } else { return byte_swap(i) } }
|
||||
to_be_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "big" { return i } else { return byte_swap(i) } }
|
||||
to_be_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "big" { return i } else { return byte_swap(i) } }
|
||||
to_be_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "big" { return i } else { return byte_swap(i) } }
|
||||
|
||||
|
||||
to_le_u8 :: proc(i: u8) -> u8 { return i; }
|
||||
to_le_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
to_le_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
to_le_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
to_le_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
to_le_u8 :: proc(i: u8) -> u8 { return i }
|
||||
to_le_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "little" { return i } else { return byte_swap(i) } }
|
||||
to_le_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "little" { return i } else { return byte_swap(i) } }
|
||||
to_le_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "little" { return i } else { return byte_swap(i) } }
|
||||
to_le_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "little" { return i } else { return byte_swap(i) } }
|
||||
|
||||
|
||||
|
||||
@@ -294,16 +294,16 @@ div :: proc{div_u32, div_u64, div_uint}
|
||||
|
||||
|
||||
|
||||
is_power_of_two_u8 :: proc(i: u8) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_i8 :: proc(i: i8) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_u16 :: proc(i: u16) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_i16 :: proc(i: i16) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_u32 :: proc(i: u32) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_i32 :: proc(i: i32) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_u64 :: proc(i: u64) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_i64 :: proc(i: i64) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_uint :: proc(i: uint) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_int :: proc(i: int) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_u8 :: proc(i: u8) -> bool { return i > 0 && (i & (i-1)) == 0 }
|
||||
is_power_of_two_i8 :: proc(i: i8) -> bool { return i > 0 && (i & (i-1)) == 0 }
|
||||
is_power_of_two_u16 :: proc(i: u16) -> bool { return i > 0 && (i & (i-1)) == 0 }
|
||||
is_power_of_two_i16 :: proc(i: i16) -> bool { return i > 0 && (i & (i-1)) == 0 }
|
||||
is_power_of_two_u32 :: proc(i: u32) -> bool { return i > 0 && (i & (i-1)) == 0 }
|
||||
is_power_of_two_i32 :: proc(i: i32) -> bool { return i > 0 && (i & (i-1)) == 0 }
|
||||
is_power_of_two_u64 :: proc(i: u64) -> bool { return i > 0 && (i & (i-1)) == 0 }
|
||||
is_power_of_two_i64 :: proc(i: i64) -> bool { return i > 0 && (i & (i-1)) == 0 }
|
||||
is_power_of_two_uint :: proc(i: uint) -> bool { return i > 0 && (i & (i-1)) == 0 }
|
||||
is_power_of_two_int :: proc(i: int) -> bool { return i > 0 && (i & (i-1)) == 0 }
|
||||
|
||||
is_power_of_two :: proc{
|
||||
is_power_of_two_u8, is_power_of_two_i8,
|
||||
@@ -328,12 +328,12 @@ len_u8_table := [256]u8{
|
||||
}
|
||||
|
||||
|
||||
bitfield_extract_u8 :: proc(value: u8, offset, bits: uint) -> u8 { return (value >> offset) & u8(1<<bits - 1); }
|
||||
bitfield_extract_u16 :: proc(value: u16, offset, bits: uint) -> u16 { return (value >> offset) & u16(1<<bits - 1); }
|
||||
bitfield_extract_u32 :: proc(value: u32, offset, bits: uint) -> u32 { return (value >> offset) & u32(1<<bits - 1); }
|
||||
bitfield_extract_u64 :: proc(value: u64, offset, bits: uint) -> u64 { return (value >> offset) & u64(1<<bits - 1); }
|
||||
bitfield_extract_u128 :: proc(value: u128, offset, bits: uint) -> u128 { return (value >> offset) & u128(1<<bits - 1); }
|
||||
bitfield_extract_uint :: proc(value: uint, offset, bits: uint) -> uint { return (value >> offset) & uint(1<<bits - 1); }
|
||||
bitfield_extract_u8 :: proc(value: u8, offset, bits: uint) -> u8 { return (value >> offset) & u8(1<<bits - 1) }
|
||||
bitfield_extract_u16 :: proc(value: u16, offset, bits: uint) -> u16 { return (value >> offset) & u16(1<<bits - 1) }
|
||||
bitfield_extract_u32 :: proc(value: u32, offset, bits: uint) -> u32 { return (value >> offset) & u32(1<<bits - 1) }
|
||||
bitfield_extract_u64 :: proc(value: u64, offset, bits: uint) -> u64 { return (value >> offset) & u64(1<<bits - 1) }
|
||||
bitfield_extract_u128 :: proc(value: u128, offset, bits: uint) -> u128 { return (value >> offset) & u128(1<<bits - 1) }
|
||||
bitfield_extract_uint :: proc(value: uint, offset, bits: uint) -> uint { return (value >> offset) & uint(1<<bits - 1) }
|
||||
|
||||
bitfield_extract_i8 :: proc(value: i8, offset, bits: uint) -> i8 {
|
||||
v := (u8(value) >> offset) & u8(1<<bits - 1)
|
||||
|
||||
@@ -478,12 +478,12 @@ is_inf :: proc{is_inf_single, is_inf_array}
|
||||
classify :: proc{classify_single, classify_array}
|
||||
|
||||
|
||||
less_than_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x < y; }
|
||||
less_than_equal_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x <= y; }
|
||||
greater_than_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x > y; }
|
||||
greater_than_equal_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x >= y; }
|
||||
equal_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x == y; }
|
||||
not_equal_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x != y; }
|
||||
less_than_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x < y }
|
||||
less_than_equal_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x <= y }
|
||||
greater_than_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x > y }
|
||||
greater_than_equal_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x >= y }
|
||||
equal_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x == y }
|
||||
not_equal_single :: proc(x, y: $T) -> (out: bool) where !IS_ARRAY(T), IS_FLOAT(T) { return x != y }
|
||||
|
||||
less_than_array :: proc(x, y: $A/[$N]$T) -> (out: [N]bool) where IS_ARRAY(A), IS_FLOAT(ELEM_TYPE(A)) {
|
||||
for i in 0..<N {
|
||||
|
||||
@@ -339,24 +339,24 @@ matrix_cast :: proc(v: $A/[$M][$N]$T, $Elem_Type: typeid) -> (w: [M][N]Elem_Type
|
||||
return
|
||||
}
|
||||
|
||||
to_f32 :: #force_inline proc(v: $A/[$N]$T) -> [N]f32 { return array_cast(v, f32); }
|
||||
to_f64 :: #force_inline proc(v: $A/[$N]$T) -> [N]f64 { return array_cast(v, f64); }
|
||||
to_f32 :: #force_inline proc(v: $A/[$N]$T) -> [N]f32 { return array_cast(v, f32) }
|
||||
to_f64 :: #force_inline proc(v: $A/[$N]$T) -> [N]f64 { return array_cast(v, f64) }
|
||||
|
||||
to_i8 :: #force_inline proc(v: $A/[$N]$T) -> [N]i8 { return array_cast(v, i8); }
|
||||
to_i16 :: #force_inline proc(v: $A/[$N]$T) -> [N]i16 { return array_cast(v, i16); }
|
||||
to_i32 :: #force_inline proc(v: $A/[$N]$T) -> [N]i32 { return array_cast(v, i32); }
|
||||
to_i64 :: #force_inline proc(v: $A/[$N]$T) -> [N]i64 { return array_cast(v, i64); }
|
||||
to_int :: #force_inline proc(v: $A/[$N]$T) -> [N]int { return array_cast(v, int); }
|
||||
to_i8 :: #force_inline proc(v: $A/[$N]$T) -> [N]i8 { return array_cast(v, i8) }
|
||||
to_i16 :: #force_inline proc(v: $A/[$N]$T) -> [N]i16 { return array_cast(v, i16) }
|
||||
to_i32 :: #force_inline proc(v: $A/[$N]$T) -> [N]i32 { return array_cast(v, i32) }
|
||||
to_i64 :: #force_inline proc(v: $A/[$N]$T) -> [N]i64 { return array_cast(v, i64) }
|
||||
to_int :: #force_inline proc(v: $A/[$N]$T) -> [N]int { return array_cast(v, int) }
|
||||
|
||||
to_u8 :: #force_inline proc(v: $A/[$N]$T) -> [N]u8 { return array_cast(v, u8); }
|
||||
to_u16 :: #force_inline proc(v: $A/[$N]$T) -> [N]u16 { return array_cast(v, u16); }
|
||||
to_u32 :: #force_inline proc(v: $A/[$N]$T) -> [N]u32 { return array_cast(v, u32); }
|
||||
to_u64 :: #force_inline proc(v: $A/[$N]$T) -> [N]u64 { return array_cast(v, u64); }
|
||||
to_uint :: #force_inline proc(v: $A/[$N]$T) -> [N]uint { return array_cast(v, uint); }
|
||||
to_u8 :: #force_inline proc(v: $A/[$N]$T) -> [N]u8 { return array_cast(v, u8) }
|
||||
to_u16 :: #force_inline proc(v: $A/[$N]$T) -> [N]u16 { return array_cast(v, u16) }
|
||||
to_u32 :: #force_inline proc(v: $A/[$N]$T) -> [N]u32 { return array_cast(v, u32) }
|
||||
to_u64 :: #force_inline proc(v: $A/[$N]$T) -> [N]u64 { return array_cast(v, u64) }
|
||||
to_uint :: #force_inline proc(v: $A/[$N]$T) -> [N]uint { return array_cast(v, uint) }
|
||||
|
||||
to_complex32 :: #force_inline proc(v: $A/[$N]$T) -> [N]complex32 { return array_cast(v, complex32); }
|
||||
to_complex64 :: #force_inline proc(v: $A/[$N]$T) -> [N]complex64 { return array_cast(v, complex64); }
|
||||
to_complex128 :: #force_inline proc(v: $A/[$N]$T) -> [N]complex128 { return array_cast(v, complex128); }
|
||||
to_quaternion64 :: #force_inline proc(v: $A/[$N]$T) -> [N]quaternion64 { return array_cast(v, quaternion64); }
|
||||
to_quaternion128 :: #force_inline proc(v: $A/[$N]$T) -> [N]quaternion128 { return array_cast(v, quaternion128); }
|
||||
to_quaternion256 :: #force_inline proc(v: $A/[$N]$T) -> [N]quaternion256 { return array_cast(v, quaternion256); }
|
||||
to_complex32 :: #force_inline proc(v: $A/[$N]$T) -> [N]complex32 { return array_cast(v, complex32) }
|
||||
to_complex64 :: #force_inline proc(v: $A/[$N]$T) -> [N]complex64 { return array_cast(v, complex64) }
|
||||
to_complex128 :: #force_inline proc(v: $A/[$N]$T) -> [N]complex128 { return array_cast(v, complex128) }
|
||||
to_quaternion64 :: #force_inline proc(v: $A/[$N]$T) -> [N]quaternion64 { return array_cast(v, quaternion64) }
|
||||
to_quaternion128 :: #force_inline proc(v: $A/[$N]$T) -> [N]quaternion128 { return array_cast(v, quaternion128) }
|
||||
to_quaternion256 :: #force_inline proc(v: $A/[$N]$T) -> [N]quaternion256 { return array_cast(v, quaternion256) }
|
||||
|
||||
@@ -260,8 +260,8 @@ vector4_linear_to_srgb :: proc{
|
||||
vector4_hsl_to_rgb_f16 :: proc(h, s, l: f16, a: f16 = 1) -> Vector4f16 {
|
||||
hue_to_rgb :: proc(p, q, t: f16) -> f16 {
|
||||
t := t
|
||||
if t < 0 { t += 1; }
|
||||
if t > 1 { t -= 1; }
|
||||
if t < 0 { t += 1 }
|
||||
if t > 1 { t -= 1 }
|
||||
switch {
|
||||
case t < 1.0/6.0: return p + (q - p) * 6.0 * t
|
||||
case t < 1.0/2.0: return q
|
||||
@@ -287,8 +287,8 @@ vector4_hsl_to_rgb_f16 :: proc(h, s, l: f16, a: f16 = 1) -> Vector4f16 {
|
||||
vector4_hsl_to_rgb_f32 :: proc(h, s, l: f32, a: f32 = 1) -> Vector4f32 {
|
||||
hue_to_rgb :: proc(p, q, t: f32) -> f32 {
|
||||
t := t
|
||||
if t < 0 { t += 1; }
|
||||
if t > 1 { t -= 1; }
|
||||
if t < 0 { t += 1 }
|
||||
if t > 1 { t -= 1 }
|
||||
switch {
|
||||
case t < 1.0/6.0: return p + (q - p) * 6.0 * t
|
||||
case t < 1.0/2.0: return q
|
||||
@@ -314,8 +314,8 @@ vector4_hsl_to_rgb_f32 :: proc(h, s, l: f32, a: f32 = 1) -> Vector4f32 {
|
||||
vector4_hsl_to_rgb_f64 :: proc(h, s, l: f64, a: f64 = 1) -> Vector4f64 {
|
||||
hue_to_rgb :: proc(p, q, t: f64) -> f64 {
|
||||
t := t
|
||||
if t < 0 { t += 1; }
|
||||
if t > 1 { t -= 1; }
|
||||
if t < 0 { t += 1 }
|
||||
if t > 1 { t -= 1 }
|
||||
switch {
|
||||
case t < 1.0/6.0: return p + (q - p) * 6.0 * t
|
||||
case t < 1.0/2.0: return q
|
||||
|
||||
+176
-176
@@ -96,96 +96,96 @@ foreign _ {
|
||||
ldexp_f64 :: proc(val: f64, exp: i32) -> f64 ---
|
||||
}
|
||||
|
||||
sqrt_f16le :: proc(x: f16le) -> f16le { return #force_inline f16le(sqrt_f16(f16(x))); }
|
||||
sqrt_f16be :: proc(x: f16be) -> f16be { return #force_inline f16be(sqrt_f16(f16(x))); }
|
||||
sqrt_f32le :: proc(x: f32le) -> f32le { return #force_inline f32le(sqrt_f32(f32(x))); }
|
||||
sqrt_f32be :: proc(x: f32be) -> f32be { return #force_inline f32be(sqrt_f32(f32(x))); }
|
||||
sqrt_f64le :: proc(x: f64le) -> f64le { return #force_inline f64le(sqrt_f64(f64(x))); }
|
||||
sqrt_f64be :: proc(x: f64be) -> f64be { return #force_inline f64be(sqrt_f64(f64(x))); }
|
||||
sqrt_f16le :: proc(x: f16le) -> f16le { return #force_inline f16le(sqrt_f16(f16(x))) }
|
||||
sqrt_f16be :: proc(x: f16be) -> f16be { return #force_inline f16be(sqrt_f16(f16(x))) }
|
||||
sqrt_f32le :: proc(x: f32le) -> f32le { return #force_inline f32le(sqrt_f32(f32(x))) }
|
||||
sqrt_f32be :: proc(x: f32be) -> f32be { return #force_inline f32be(sqrt_f32(f32(x))) }
|
||||
sqrt_f64le :: proc(x: f64le) -> f64le { return #force_inline f64le(sqrt_f64(f64(x))) }
|
||||
sqrt_f64be :: proc(x: f64be) -> f64be { return #force_inline f64be(sqrt_f64(f64(x))) }
|
||||
sqrt :: proc{
|
||||
sqrt_f16, sqrt_f16le, sqrt_f16be,
|
||||
sqrt_f32, sqrt_f32le, sqrt_f32be,
|
||||
sqrt_f64, sqrt_f64le, sqrt_f64be,
|
||||
}
|
||||
|
||||
sin_f16le :: proc(θ: f16le) -> f16le { return #force_inline f16le(sin_f16(f16(θ))); }
|
||||
sin_f16be :: proc(θ: f16be) -> f16be { return #force_inline f16be(sin_f16(f16(θ))); }
|
||||
sin_f32le :: proc(θ: f32le) -> f32le { return #force_inline f32le(sin_f32(f32(θ))); }
|
||||
sin_f32be :: proc(θ: f32be) -> f32be { return #force_inline f32be(sin_f32(f32(θ))); }
|
||||
sin_f64le :: proc(θ: f64le) -> f64le { return #force_inline f64le(sin_f64(f64(θ))); }
|
||||
sin_f64be :: proc(θ: f64be) -> f64be { return #force_inline f64be(sin_f64(f64(θ))); }
|
||||
sin_f16le :: proc(θ: f16le) -> f16le { return #force_inline f16le(sin_f16(f16(θ))) }
|
||||
sin_f16be :: proc(θ: f16be) -> f16be { return #force_inline f16be(sin_f16(f16(θ))) }
|
||||
sin_f32le :: proc(θ: f32le) -> f32le { return #force_inline f32le(sin_f32(f32(θ))) }
|
||||
sin_f32be :: proc(θ: f32be) -> f32be { return #force_inline f32be(sin_f32(f32(θ))) }
|
||||
sin_f64le :: proc(θ: f64le) -> f64le { return #force_inline f64le(sin_f64(f64(θ))) }
|
||||
sin_f64be :: proc(θ: f64be) -> f64be { return #force_inline f64be(sin_f64(f64(θ))) }
|
||||
sin :: proc{
|
||||
sin_f16, sin_f16le, sin_f16be,
|
||||
sin_f32, sin_f32le, sin_f32be,
|
||||
sin_f64, sin_f64le, sin_f64be,
|
||||
}
|
||||
|
||||
cos_f16le :: proc(θ: f16le) -> f16le { return #force_inline f16le(cos_f16(f16(θ))); }
|
||||
cos_f16be :: proc(θ: f16be) -> f16be { return #force_inline f16be(cos_f16(f16(θ))); }
|
||||
cos_f32le :: proc(θ: f32le) -> f32le { return #force_inline f32le(cos_f32(f32(θ))); }
|
||||
cos_f32be :: proc(θ: f32be) -> f32be { return #force_inline f32be(cos_f32(f32(θ))); }
|
||||
cos_f64le :: proc(θ: f64le) -> f64le { return #force_inline f64le(cos_f64(f64(θ))); }
|
||||
cos_f64be :: proc(θ: f64be) -> f64be { return #force_inline f64be(cos_f64(f64(θ))); }
|
||||
cos_f16le :: proc(θ: f16le) -> f16le { return #force_inline f16le(cos_f16(f16(θ))) }
|
||||
cos_f16be :: proc(θ: f16be) -> f16be { return #force_inline f16be(cos_f16(f16(θ))) }
|
||||
cos_f32le :: proc(θ: f32le) -> f32le { return #force_inline f32le(cos_f32(f32(θ))) }
|
||||
cos_f32be :: proc(θ: f32be) -> f32be { return #force_inline f32be(cos_f32(f32(θ))) }
|
||||
cos_f64le :: proc(θ: f64le) -> f64le { return #force_inline f64le(cos_f64(f64(θ))) }
|
||||
cos_f64be :: proc(θ: f64be) -> f64be { return #force_inline f64be(cos_f64(f64(θ))) }
|
||||
cos :: proc{
|
||||
cos_f16, cos_f16le, cos_f16be,
|
||||
cos_f32, cos_f32le, cos_f32be,
|
||||
cos_f64, cos_f64le, cos_f64be,
|
||||
}
|
||||
|
||||
pow_f16le :: proc(x, power: f16le) -> f16le { return #force_inline f16le(pow_f16(f16(x), f16(power))); }
|
||||
pow_f16be :: proc(x, power: f16be) -> f16be { return #force_inline f16be(pow_f16(f16(x), f16(power))); }
|
||||
pow_f32le :: proc(x, power: f32le) -> f32le { return #force_inline f32le(pow_f32(f32(x), f32(power))); }
|
||||
pow_f32be :: proc(x, power: f32be) -> f32be { return #force_inline f32be(pow_f32(f32(x), f32(power))); }
|
||||
pow_f64le :: proc(x, power: f64le) -> f64le { return #force_inline f64le(pow_f64(f64(x), f64(power))); }
|
||||
pow_f64be :: proc(x, power: f64be) -> f64be { return #force_inline f64be(pow_f64(f64(x), f64(power))); }
|
||||
pow_f16le :: proc(x, power: f16le) -> f16le { return #force_inline f16le(pow_f16(f16(x), f16(power))) }
|
||||
pow_f16be :: proc(x, power: f16be) -> f16be { return #force_inline f16be(pow_f16(f16(x), f16(power))) }
|
||||
pow_f32le :: proc(x, power: f32le) -> f32le { return #force_inline f32le(pow_f32(f32(x), f32(power))) }
|
||||
pow_f32be :: proc(x, power: f32be) -> f32be { return #force_inline f32be(pow_f32(f32(x), f32(power))) }
|
||||
pow_f64le :: proc(x, power: f64le) -> f64le { return #force_inline f64le(pow_f64(f64(x), f64(power))) }
|
||||
pow_f64be :: proc(x, power: f64be) -> f64be { return #force_inline f64be(pow_f64(f64(x), f64(power))) }
|
||||
pow :: proc{
|
||||
pow_f16, pow_f16le, pow_f16be,
|
||||
pow_f32, pow_f32le, pow_f32be,
|
||||
pow_f64, pow_f64le, pow_f64be,
|
||||
}
|
||||
|
||||
fmuladd_f16le :: proc(a, b, c: f16le) -> f16le { return #force_inline f16le(fmuladd_f16(f16(a), f16(b), f16(c))); }
|
||||
fmuladd_f16be :: proc(a, b, c: f16be) -> f16be { return #force_inline f16be(fmuladd_f16(f16(a), f16(b), f16(c))); }
|
||||
fmuladd_f32le :: proc(a, b, c: f32le) -> f32le { return #force_inline f32le(fmuladd_f32(f32(a), f32(b), f32(c))); }
|
||||
fmuladd_f32be :: proc(a, b, c: f32be) -> f32be { return #force_inline f32be(fmuladd_f32(f32(a), f32(b), f32(c))); }
|
||||
fmuladd_f64le :: proc(a, b, c: f64le) -> f64le { return #force_inline f64le(fmuladd_f64(f64(a), f64(b), f64(c))); }
|
||||
fmuladd_f64be :: proc(a, b, c: f64be) -> f64be { return #force_inline f64be(fmuladd_f64(f64(a), f64(b), f64(c))); }
|
||||
fmuladd_f16le :: proc(a, b, c: f16le) -> f16le { return #force_inline f16le(fmuladd_f16(f16(a), f16(b), f16(c))) }
|
||||
fmuladd_f16be :: proc(a, b, c: f16be) -> f16be { return #force_inline f16be(fmuladd_f16(f16(a), f16(b), f16(c))) }
|
||||
fmuladd_f32le :: proc(a, b, c: f32le) -> f32le { return #force_inline f32le(fmuladd_f32(f32(a), f32(b), f32(c))) }
|
||||
fmuladd_f32be :: proc(a, b, c: f32be) -> f32be { return #force_inline f32be(fmuladd_f32(f32(a), f32(b), f32(c))) }
|
||||
fmuladd_f64le :: proc(a, b, c: f64le) -> f64le { return #force_inline f64le(fmuladd_f64(f64(a), f64(b), f64(c))) }
|
||||
fmuladd_f64be :: proc(a, b, c: f64be) -> f64be { return #force_inline f64be(fmuladd_f64(f64(a), f64(b), f64(c))) }
|
||||
fmuladd :: proc{
|
||||
fmuladd_f16, fmuladd_f16le, fmuladd_f16be,
|
||||
fmuladd_f32, fmuladd_f32le, fmuladd_f32be,
|
||||
fmuladd_f64, fmuladd_f64le, fmuladd_f64be,
|
||||
}
|
||||
|
||||
ln_f16le :: proc(x: f16le) -> f16le { return #force_inline f16le(ln_f16(f16(x))); }
|
||||
ln_f16be :: proc(x: f16be) -> f16be { return #force_inline f16be(ln_f16(f16(x))); }
|
||||
ln_f32le :: proc(x: f32le) -> f32le { return #force_inline f32le(ln_f32(f32(x))); }
|
||||
ln_f32be :: proc(x: f32be) -> f32be { return #force_inline f32be(ln_f32(f32(x))); }
|
||||
ln_f64le :: proc(x: f64le) -> f64le { return #force_inline f64le(ln_f64(f64(x))); }
|
||||
ln_f64be :: proc(x: f64be) -> f64be { return #force_inline f64be(ln_f64(f64(x))); }
|
||||
ln_f16le :: proc(x: f16le) -> f16le { return #force_inline f16le(ln_f16(f16(x))) }
|
||||
ln_f16be :: proc(x: f16be) -> f16be { return #force_inline f16be(ln_f16(f16(x))) }
|
||||
ln_f32le :: proc(x: f32le) -> f32le { return #force_inline f32le(ln_f32(f32(x))) }
|
||||
ln_f32be :: proc(x: f32be) -> f32be { return #force_inline f32be(ln_f32(f32(x))) }
|
||||
ln_f64le :: proc(x: f64le) -> f64le { return #force_inline f64le(ln_f64(f64(x))) }
|
||||
ln_f64be :: proc(x: f64be) -> f64be { return #force_inline f64be(ln_f64(f64(x))) }
|
||||
ln :: proc{
|
||||
ln_f16, ln_f16le, ln_f16be,
|
||||
ln_f32, ln_f32le, ln_f32be,
|
||||
ln_f64, ln_f64le, ln_f64be,
|
||||
}
|
||||
|
||||
exp_f16le :: proc(x: f16le) -> f16le { return #force_inline f16le(exp_f16(f16(x))); }
|
||||
exp_f16be :: proc(x: f16be) -> f16be { return #force_inline f16be(exp_f16(f16(x))); }
|
||||
exp_f32le :: proc(x: f32le) -> f32le { return #force_inline f32le(exp_f32(f32(x))); }
|
||||
exp_f32be :: proc(x: f32be) -> f32be { return #force_inline f32be(exp_f32(f32(x))); }
|
||||
exp_f64le :: proc(x: f64le) -> f64le { return #force_inline f64le(exp_f64(f64(x))); }
|
||||
exp_f64be :: proc(x: f64be) -> f64be { return #force_inline f64be(exp_f64(f64(x))); }
|
||||
exp_f16le :: proc(x: f16le) -> f16le { return #force_inline f16le(exp_f16(f16(x))) }
|
||||
exp_f16be :: proc(x: f16be) -> f16be { return #force_inline f16be(exp_f16(f16(x))) }
|
||||
exp_f32le :: proc(x: f32le) -> f32le { return #force_inline f32le(exp_f32(f32(x))) }
|
||||
exp_f32be :: proc(x: f32be) -> f32be { return #force_inline f32be(exp_f32(f32(x))) }
|
||||
exp_f64le :: proc(x: f64le) -> f64le { return #force_inline f64le(exp_f64(f64(x))) }
|
||||
exp_f64be :: proc(x: f64be) -> f64be { return #force_inline f64be(exp_f64(f64(x))) }
|
||||
exp :: proc{
|
||||
exp_f16, exp_f16le, exp_f16be,
|
||||
exp_f32, exp_f32le, exp_f32be,
|
||||
exp_f64, exp_f64le, exp_f64be,
|
||||
}
|
||||
|
||||
ldexp_f16le :: proc(val: f16le, exp: i32) -> f16le { return #force_inline f16le(ldexp_f16(f16(val), exp)); }
|
||||
ldexp_f16be :: proc(val: f16be, exp: i32) -> f16be { return #force_inline f16be(ldexp_f16(f16(val), exp)); }
|
||||
ldexp_f32le :: proc(val: f32le, exp: i32) -> f32le { return #force_inline f32le(ldexp_f32(f32(val), exp)); }
|
||||
ldexp_f32be :: proc(val: f32be, exp: i32) -> f32be { return #force_inline f32be(ldexp_f32(f32(val), exp)); }
|
||||
ldexp_f64le :: proc(val: f64le, exp: i32) -> f64le { return #force_inline f64le(ldexp_f64(f64(val), exp)); }
|
||||
ldexp_f64be :: proc(val: f64be, exp: i32) -> f64be { return #force_inline f64be(ldexp_f64(f64(val), exp)); }
|
||||
ldexp_f16le :: proc(val: f16le, exp: i32) -> f16le { return #force_inline f16le(ldexp_f16(f16(val), exp)) }
|
||||
ldexp_f16be :: proc(val: f16be, exp: i32) -> f16be { return #force_inline f16be(ldexp_f16(f16(val), exp)) }
|
||||
ldexp_f32le :: proc(val: f32le, exp: i32) -> f32le { return #force_inline f32le(ldexp_f32(f32(val), exp)) }
|
||||
ldexp_f32be :: proc(val: f32be, exp: i32) -> f32be { return #force_inline f32be(ldexp_f32(f32(val), exp)) }
|
||||
ldexp_f64le :: proc(val: f64le, exp: i32) -> f64le { return #force_inline f64le(ldexp_f64(f64(val), exp)) }
|
||||
ldexp_f64be :: proc(val: f64be, exp: i32) -> f64be { return #force_inline f64be(ldexp_f64(f64(val), exp)) }
|
||||
ldexp :: proc{
|
||||
ldexp_f16, ldexp_f16le, ldexp_f16be,
|
||||
ldexp_f32, ldexp_f32le, ldexp_f32be,
|
||||
@@ -193,76 +193,76 @@ ldexp :: proc{
|
||||
}
|
||||
|
||||
|
||||
log_f16 :: proc(x, base: f16) -> f16 { return ln(x) / ln(base); }
|
||||
log_f16le :: proc(x, base: f16le) -> f16le { return f16le(log_f16(f16(x), f16(base))); }
|
||||
log_f16be :: proc(x, base: f16be) -> f16be { return f16be(log_f16(f16(x), f16(base))); }
|
||||
log_f16 :: proc(x, base: f16) -> f16 { return ln(x) / ln(base) }
|
||||
log_f16le :: proc(x, base: f16le) -> f16le { return f16le(log_f16(f16(x), f16(base))) }
|
||||
log_f16be :: proc(x, base: f16be) -> f16be { return f16be(log_f16(f16(x), f16(base))) }
|
||||
|
||||
log_f32 :: proc(x, base: f32) -> f32 { return ln(x) / ln(base); }
|
||||
log_f32le :: proc(x, base: f32le) -> f32le { return f32le(log_f32(f32(x), f32(base))); }
|
||||
log_f32be :: proc(x, base: f32be) -> f32be { return f32be(log_f32(f32(x), f32(base))); }
|
||||
log_f32 :: proc(x, base: f32) -> f32 { return ln(x) / ln(base) }
|
||||
log_f32le :: proc(x, base: f32le) -> f32le { return f32le(log_f32(f32(x), f32(base))) }
|
||||
log_f32be :: proc(x, base: f32be) -> f32be { return f32be(log_f32(f32(x), f32(base))) }
|
||||
|
||||
log_f64 :: proc(x, base: f64) -> f64 { return ln(x) / ln(base); }
|
||||
log_f64le :: proc(x, base: f64le) -> f64le { return f64le(log_f64(f64(x), f64(base))); }
|
||||
log_f64be :: proc(x, base: f64be) -> f64be { return f64be(log_f64(f64(x), f64(base))); }
|
||||
log_f64 :: proc(x, base: f64) -> f64 { return ln(x) / ln(base) }
|
||||
log_f64le :: proc(x, base: f64le) -> f64le { return f64le(log_f64(f64(x), f64(base))) }
|
||||
log_f64be :: proc(x, base: f64be) -> f64be { return f64be(log_f64(f64(x), f64(base))) }
|
||||
log :: proc{
|
||||
log_f16, log_f16le, log_f16be,
|
||||
log_f32, log_f32le, log_f32be,
|
||||
log_f64, log_f64le, log_f64be,
|
||||
}
|
||||
|
||||
log2_f16 :: proc(x: f16) -> f16 { return ln(x)/LN2; }
|
||||
log2_f16le :: proc(x: f16le) -> f16le { return f16le(log2_f16(f16(x))); }
|
||||
log2_f16be :: proc(x: f16be) -> f16be { return f16be(log2_f16(f16(x))); }
|
||||
log2_f16 :: proc(x: f16) -> f16 { return ln(x)/LN2 }
|
||||
log2_f16le :: proc(x: f16le) -> f16le { return f16le(log2_f16(f16(x))) }
|
||||
log2_f16be :: proc(x: f16be) -> f16be { return f16be(log2_f16(f16(x))) }
|
||||
|
||||
log2_f32 :: proc(x: f32) -> f32 { return ln(x)/LN2; }
|
||||
log2_f32le :: proc(x: f32le) -> f32le { return f32le(log2_f32(f32(x))); }
|
||||
log2_f32be :: proc(x: f32be) -> f32be { return f32be(log2_f32(f32(x))); }
|
||||
log2_f32 :: proc(x: f32) -> f32 { return ln(x)/LN2 }
|
||||
log2_f32le :: proc(x: f32le) -> f32le { return f32le(log2_f32(f32(x))) }
|
||||
log2_f32be :: proc(x: f32be) -> f32be { return f32be(log2_f32(f32(x))) }
|
||||
|
||||
log2_f64 :: proc(x: f64) -> f64 { return ln(x)/LN2; }
|
||||
log2_f64le :: proc(x: f64le) -> f64le { return f64le(log2_f64(f64(x))); }
|
||||
log2_f64be :: proc(x: f64be) -> f64be { return f64be(log2_f64(f64(x))); }
|
||||
log2_f64 :: proc(x: f64) -> f64 { return ln(x)/LN2 }
|
||||
log2_f64le :: proc(x: f64le) -> f64le { return f64le(log2_f64(f64(x))) }
|
||||
log2_f64be :: proc(x: f64be) -> f64be { return f64be(log2_f64(f64(x))) }
|
||||
log2 :: proc{
|
||||
log2_f16, log2_f16le, log2_f16be,
|
||||
log2_f32, log2_f32le, log2_f32be,
|
||||
log2_f64, log2_f64le, log2_f64be,
|
||||
}
|
||||
|
||||
log10_f16 :: proc(x: f16) -> f16 { return ln(x)/LN10; }
|
||||
log10_f16le :: proc(x: f16le) -> f16le { return f16le(log10_f16(f16(x))); }
|
||||
log10_f16be :: proc(x: f16be) -> f16be { return f16be(log10_f16(f16(x))); }
|
||||
log10_f16 :: proc(x: f16) -> f16 { return ln(x)/LN10 }
|
||||
log10_f16le :: proc(x: f16le) -> f16le { return f16le(log10_f16(f16(x))) }
|
||||
log10_f16be :: proc(x: f16be) -> f16be { return f16be(log10_f16(f16(x))) }
|
||||
|
||||
log10_f32 :: proc(x: f32) -> f32 { return ln(x)/LN10; }
|
||||
log10_f32le :: proc(x: f32le) -> f32le { return f32le(log10_f32(f32(x))); }
|
||||
log10_f32be :: proc(x: f32be) -> f32be { return f32be(log10_f32(f32(x))); }
|
||||
log10_f32 :: proc(x: f32) -> f32 { return ln(x)/LN10 }
|
||||
log10_f32le :: proc(x: f32le) -> f32le { return f32le(log10_f32(f32(x))) }
|
||||
log10_f32be :: proc(x: f32be) -> f32be { return f32be(log10_f32(f32(x))) }
|
||||
|
||||
log10_f64 :: proc(x: f64) -> f64 { return ln(x)/LN10; }
|
||||
log10_f64le :: proc(x: f64le) -> f64le { return f64le(log10_f64(f64(x))); }
|
||||
log10_f64be :: proc(x: f64be) -> f64be { return f64be(log10_f64(f64(x))); }
|
||||
log10_f64 :: proc(x: f64) -> f64 { return ln(x)/LN10 }
|
||||
log10_f64le :: proc(x: f64le) -> f64le { return f64le(log10_f64(f64(x))) }
|
||||
log10_f64be :: proc(x: f64be) -> f64be { return f64be(log10_f64(f64(x))) }
|
||||
log10 :: proc{
|
||||
log10_f16, log10_f16le, log10_f16be,
|
||||
log10_f32, log10_f32le, log10_f32be,
|
||||
log10_f64, log10_f64le, log10_f64be,
|
||||
}
|
||||
|
||||
tan_f16 :: proc(θ: f16) -> f16 { return sin(θ)/cos(θ); }
|
||||
tan_f16le :: proc(θ: f16le) -> f16le { return f16le(tan_f16(f16(θ))); }
|
||||
tan_f16be :: proc(θ: f16be) -> f16be { return f16be(tan_f16(f16(θ))); }
|
||||
tan_f16 :: proc(θ: f16) -> f16 { return sin(θ)/cos(θ) }
|
||||
tan_f16le :: proc(θ: f16le) -> f16le { return f16le(tan_f16(f16(θ))) }
|
||||
tan_f16be :: proc(θ: f16be) -> f16be { return f16be(tan_f16(f16(θ))) }
|
||||
|
||||
tan_f32 :: proc(θ: f32) -> f32 { return sin(θ)/cos(θ); }
|
||||
tan_f32le :: proc(θ: f32le) -> f32le { return f32le(tan_f32(f32(θ))); }
|
||||
tan_f32be :: proc(θ: f32be) -> f32be { return f32be(tan_f32(f32(θ))); }
|
||||
tan_f32 :: proc(θ: f32) -> f32 { return sin(θ)/cos(θ) }
|
||||
tan_f32le :: proc(θ: f32le) -> f32le { return f32le(tan_f32(f32(θ))) }
|
||||
tan_f32be :: proc(θ: f32be) -> f32be { return f32be(tan_f32(f32(θ))) }
|
||||
|
||||
tan_f64 :: proc(θ: f64) -> f64 { return sin(θ)/cos(θ); }
|
||||
tan_f64le :: proc(θ: f64le) -> f64le { return f64le(tan_f64(f64(θ))); }
|
||||
tan_f64be :: proc(θ: f64be) -> f64be { return f64be(tan_f64(f64(θ))); }
|
||||
tan_f64 :: proc(θ: f64) -> f64 { return sin(θ)/cos(θ) }
|
||||
tan_f64le :: proc(θ: f64le) -> f64le { return f64le(tan_f64(f64(θ))) }
|
||||
tan_f64be :: proc(θ: f64be) -> f64be { return f64be(tan_f64(f64(θ))) }
|
||||
tan :: proc{
|
||||
tan_f16, tan_f16le, tan_f16be,
|
||||
tan_f32, tan_f32le, tan_f32be,
|
||||
tan_f64, tan_f64le, tan_f64be,
|
||||
}
|
||||
|
||||
lerp :: proc(a, b: $T, t: $E) -> (x: T) { return a*(1-t) + b*t; }
|
||||
saturate :: proc(a: $T) -> (x: T) { return clamp(a, 0, 1); }
|
||||
lerp :: proc(a, b: $T, t: $E) -> (x: T) { return a*(1-t) + b*t }
|
||||
saturate :: proc(a: $T) -> (x: T) { return clamp(a, 0, 1) }
|
||||
|
||||
unlerp :: proc(a, b, x: $T) -> (t: T) where intrinsics.type_is_float(T), !intrinsics.type_is_array(T) {
|
||||
return (x-a)/(b-a)
|
||||
@@ -311,15 +311,15 @@ gain :: proc(t, g: $T) -> T where intrinsics.type_is_numeric(T) {
|
||||
}
|
||||
|
||||
|
||||
sign_f16 :: proc(x: f16) -> f16 { return f16(int(0 < x) - int(x < 0)); }
|
||||
sign_f16le :: proc(x: f16le) -> f16le { return f16le(int(0 < x) - int(x < 0)); }
|
||||
sign_f16be :: proc(x: f16be) -> f16be { return f16be(int(0 < x) - int(x < 0)); }
|
||||
sign_f32 :: proc(x: f32) -> f32 { return f32(int(0 < x) - int(x < 0)); }
|
||||
sign_f32le :: proc(x: f32le) -> f32le { return f32le(int(0 < x) - int(x < 0)); }
|
||||
sign_f32be :: proc(x: f32be) -> f32be { return f32be(int(0 < x) - int(x < 0)); }
|
||||
sign_f64 :: proc(x: f64) -> f64 { return f64(int(0 < x) - int(x < 0)); }
|
||||
sign_f64le :: proc(x: f64le) -> f64le { return f64le(int(0 < x) - int(x < 0)); }
|
||||
sign_f64be :: proc(x: f64be) -> f64be { return f64be(int(0 < x) - int(x < 0)); }
|
||||
sign_f16 :: proc(x: f16) -> f16 { return f16(int(0 < x) - int(x < 0)) }
|
||||
sign_f16le :: proc(x: f16le) -> f16le { return f16le(int(0 < x) - int(x < 0)) }
|
||||
sign_f16be :: proc(x: f16be) -> f16be { return f16be(int(0 < x) - int(x < 0)) }
|
||||
sign_f32 :: proc(x: f32) -> f32 { return f32(int(0 < x) - int(x < 0)) }
|
||||
sign_f32le :: proc(x: f32le) -> f32le { return f32le(int(0 < x) - int(x < 0)) }
|
||||
sign_f32be :: proc(x: f32be) -> f32be { return f32be(int(0 < x) - int(x < 0)) }
|
||||
sign_f64 :: proc(x: f64) -> f64 { return f64(int(0 < x) - int(x < 0)) }
|
||||
sign_f64le :: proc(x: f64le) -> f64le { return f64le(int(0 < x) - int(x < 0)) }
|
||||
sign_f64be :: proc(x: f64be) -> f64be { return f64be(int(0 < x) - int(x < 0)) }
|
||||
sign :: proc{
|
||||
sign_f16, sign_f16le, sign_f16be,
|
||||
sign_f32, sign_f32le, sign_f32be,
|
||||
@@ -329,18 +329,18 @@ sign :: proc{
|
||||
sign_bit_f16 :: proc(x: f16) -> bool {
|
||||
return (transmute(u16)x) & (1<<15) != 0
|
||||
}
|
||||
sign_bit_f16le :: proc(x: f16le) -> bool { return #force_inline sign_bit_f16(f16(x)); }
|
||||
sign_bit_f16be :: proc(x: f16be) -> bool { return #force_inline sign_bit_f16(f16(x)); }
|
||||
sign_bit_f16le :: proc(x: f16le) -> bool { return #force_inline sign_bit_f16(f16(x)) }
|
||||
sign_bit_f16be :: proc(x: f16be) -> bool { return #force_inline sign_bit_f16(f16(x)) }
|
||||
sign_bit_f32 :: proc(x: f32) -> bool {
|
||||
return (transmute(u32)x) & (1<<31) != 0
|
||||
}
|
||||
sign_bit_f32le :: proc(x: f32le) -> bool { return #force_inline sign_bit_f32(f32(x)); }
|
||||
sign_bit_f32be :: proc(x: f32be) -> bool { return #force_inline sign_bit_f32(f32(x)); }
|
||||
sign_bit_f32le :: proc(x: f32le) -> bool { return #force_inline sign_bit_f32(f32(x)) }
|
||||
sign_bit_f32be :: proc(x: f32be) -> bool { return #force_inline sign_bit_f32(f32(x)) }
|
||||
sign_bit_f64 :: proc(x: f64) -> bool {
|
||||
return (transmute(u64)x) & (1<<63) != 0
|
||||
}
|
||||
sign_bit_f64le :: proc(x: f64le) -> bool { return #force_inline sign_bit_f64(f64(x)); }
|
||||
sign_bit_f64be :: proc(x: f64be) -> bool { return #force_inline sign_bit_f64(f64(x)); }
|
||||
sign_bit_f64le :: proc(x: f64le) -> bool { return #force_inline sign_bit_f64(f64(x)) }
|
||||
sign_bit_f64be :: proc(x: f64be) -> bool { return #force_inline sign_bit_f64(f64(x)) }
|
||||
sign_bit :: proc{
|
||||
sign_bit_f16, sign_bit_f16le, sign_bit_f16be,
|
||||
sign_bit_f32, sign_bit_f32le, sign_bit_f32be,
|
||||
@@ -354,8 +354,8 @@ copy_sign_f16 :: proc(x, y: f16) -> f16 {
|
||||
ix |= iy & 0x8000
|
||||
return transmute(f16)ix
|
||||
}
|
||||
copy_sign_f16le :: proc(x, y: f16le) -> f16le { return #force_inline f16le(copy_sign_f16(f16(x), f16(y))); }
|
||||
copy_sign_f16be :: proc(x, y: f16be) -> f16be { return #force_inline f16be(copy_sign_f16(f16(x), f16(y))); }
|
||||
copy_sign_f16le :: proc(x, y: f16le) -> f16le { return #force_inline f16le(copy_sign_f16(f16(x), f16(y))) }
|
||||
copy_sign_f16be :: proc(x, y: f16be) -> f16be { return #force_inline f16be(copy_sign_f16(f16(x), f16(y))) }
|
||||
copy_sign_f32 :: proc(x, y: f32) -> f32 {
|
||||
ix := transmute(u32)x
|
||||
iy := transmute(u32)y
|
||||
@@ -363,8 +363,8 @@ copy_sign_f32 :: proc(x, y: f32) -> f32 {
|
||||
ix |= iy & 0x8000_0000
|
||||
return transmute(f32)ix
|
||||
}
|
||||
copy_sign_f32le :: proc(x, y: f32le) -> f32le { return #force_inline f32le(copy_sign_f32(f32(x), f32(y))); }
|
||||
copy_sign_f32be :: proc(x, y: f32be) -> f32be { return #force_inline f32be(copy_sign_f32(f32(x), f32(y))); }
|
||||
copy_sign_f32le :: proc(x, y: f32le) -> f32le { return #force_inline f32le(copy_sign_f32(f32(x), f32(y))) }
|
||||
copy_sign_f32be :: proc(x, y: f32be) -> f32be { return #force_inline f32be(copy_sign_f32(f32(x), f32(y))) }
|
||||
copy_sign_f64 :: proc(x, y: f64) -> f64 {
|
||||
ix := transmute(u64)x
|
||||
iy := transmute(u64)y
|
||||
@@ -372,32 +372,32 @@ copy_sign_f64 :: proc(x, y: f64) -> f64 {
|
||||
ix |= iy & 0x8000_0000_0000_0000
|
||||
return transmute(f64)ix
|
||||
}
|
||||
copy_sign_f64le :: proc(x, y: f64le) -> f64le { return #force_inline f64le(copy_sign_f64(f64(x), f64(y))); }
|
||||
copy_sign_f64be :: proc(x, y: f64be) -> f64be { return #force_inline f64be(copy_sign_f64(f64(x), f64(y))); }
|
||||
copy_sign_f64le :: proc(x, y: f64le) -> f64le { return #force_inline f64le(copy_sign_f64(f64(x), f64(y))) }
|
||||
copy_sign_f64be :: proc(x, y: f64be) -> f64be { return #force_inline f64be(copy_sign_f64(f64(x), f64(y))) }
|
||||
copy_sign :: proc{
|
||||
copy_sign_f16, copy_sign_f16le, copy_sign_f16be,
|
||||
copy_sign_f32, copy_sign_f32le, copy_sign_f32be,
|
||||
copy_sign_f64, copy_sign_f64le, copy_sign_f64be,
|
||||
}
|
||||
|
||||
to_radians_f16 :: proc(degrees: f16) -> f16 { return degrees * RAD_PER_DEG; }
|
||||
to_radians_f16le :: proc(degrees: f16le) -> f16le { return degrees * RAD_PER_DEG; }
|
||||
to_radians_f16be :: proc(degrees: f16be) -> f16be { return degrees * RAD_PER_DEG; }
|
||||
to_radians_f32 :: proc(degrees: f32) -> f32 { return degrees * RAD_PER_DEG; }
|
||||
to_radians_f32le :: proc(degrees: f32le) -> f32le { return degrees * RAD_PER_DEG; }
|
||||
to_radians_f32be :: proc(degrees: f32be) -> f32be { return degrees * RAD_PER_DEG; }
|
||||
to_radians_f64 :: proc(degrees: f64) -> f64 { return degrees * RAD_PER_DEG; }
|
||||
to_radians_f64le :: proc(degrees: f64le) -> f64le { return degrees * RAD_PER_DEG; }
|
||||
to_radians_f64be :: proc(degrees: f64be) -> f64be { return degrees * RAD_PER_DEG; }
|
||||
to_degrees_f16 :: proc(radians: f16) -> f16 { return radians * DEG_PER_RAD; }
|
||||
to_degrees_f16le :: proc(radians: f16le) -> f16le { return radians * DEG_PER_RAD; }
|
||||
to_degrees_f16be :: proc(radians: f16be) -> f16be { return radians * DEG_PER_RAD; }
|
||||
to_degrees_f32 :: proc(radians: f32) -> f32 { return radians * DEG_PER_RAD; }
|
||||
to_degrees_f32le :: proc(radians: f32le) -> f32le { return radians * DEG_PER_RAD; }
|
||||
to_degrees_f32be :: proc(radians: f32be) -> f32be { return radians * DEG_PER_RAD; }
|
||||
to_degrees_f64 :: proc(radians: f64) -> f64 { return radians * DEG_PER_RAD; }
|
||||
to_degrees_f64le :: proc(radians: f64le) -> f64le { return radians * DEG_PER_RAD; }
|
||||
to_degrees_f64be :: proc(radians: f64be) -> f64be { return radians * DEG_PER_RAD; }
|
||||
to_radians_f16 :: proc(degrees: f16) -> f16 { return degrees * RAD_PER_DEG }
|
||||
to_radians_f16le :: proc(degrees: f16le) -> f16le { return degrees * RAD_PER_DEG }
|
||||
to_radians_f16be :: proc(degrees: f16be) -> f16be { return degrees * RAD_PER_DEG }
|
||||
to_radians_f32 :: proc(degrees: f32) -> f32 { return degrees * RAD_PER_DEG }
|
||||
to_radians_f32le :: proc(degrees: f32le) -> f32le { return degrees * RAD_PER_DEG }
|
||||
to_radians_f32be :: proc(degrees: f32be) -> f32be { return degrees * RAD_PER_DEG }
|
||||
to_radians_f64 :: proc(degrees: f64) -> f64 { return degrees * RAD_PER_DEG }
|
||||
to_radians_f64le :: proc(degrees: f64le) -> f64le { return degrees * RAD_PER_DEG }
|
||||
to_radians_f64be :: proc(degrees: f64be) -> f64be { return degrees * RAD_PER_DEG }
|
||||
to_degrees_f16 :: proc(radians: f16) -> f16 { return radians * DEG_PER_RAD }
|
||||
to_degrees_f16le :: proc(radians: f16le) -> f16le { return radians * DEG_PER_RAD }
|
||||
to_degrees_f16be :: proc(radians: f16be) -> f16be { return radians * DEG_PER_RAD }
|
||||
to_degrees_f32 :: proc(radians: f32) -> f32 { return radians * DEG_PER_RAD }
|
||||
to_degrees_f32le :: proc(radians: f32le) -> f32le { return radians * DEG_PER_RAD }
|
||||
to_degrees_f32be :: proc(radians: f32be) -> f32be { return radians * DEG_PER_RAD }
|
||||
to_degrees_f64 :: proc(radians: f64) -> f64 { return radians * DEG_PER_RAD }
|
||||
to_degrees_f64le :: proc(radians: f64le) -> f64le { return radians * DEG_PER_RAD }
|
||||
to_degrees_f64be :: proc(radians: f64be) -> f64be { return radians * DEG_PER_RAD }
|
||||
to_radians :: proc{
|
||||
to_radians_f16, to_radians_f16le, to_radians_f16be,
|
||||
to_radians_f32, to_radians_f32le, to_radians_f32be,
|
||||
@@ -438,8 +438,8 @@ trunc_f16 :: proc(x: f16) -> f16 {
|
||||
}
|
||||
return trunc_internal(x)
|
||||
}
|
||||
trunc_f16le :: proc(x: f16le) -> f16le { return #force_inline f16le(trunc_f16(f16(x))); }
|
||||
trunc_f16be :: proc(x: f16be) -> f16be { return #force_inline f16be(trunc_f16(f16(x))); }
|
||||
trunc_f16le :: proc(x: f16le) -> f16le { return #force_inline f16le(trunc_f16(f16(x))) }
|
||||
trunc_f16be :: proc(x: f16be) -> f16be { return #force_inline f16be(trunc_f16(f16(x))) }
|
||||
|
||||
trunc_f32 :: proc(x: f32) -> f32 {
|
||||
trunc_internal :: proc(f: f32) -> f32 {
|
||||
@@ -470,8 +470,8 @@ trunc_f32 :: proc(x: f32) -> f32 {
|
||||
}
|
||||
return trunc_internal(x)
|
||||
}
|
||||
trunc_f32le :: proc(x: f32le) -> f32le { return #force_inline f32le(trunc_f32(f32(x))); }
|
||||
trunc_f32be :: proc(x: f32be) -> f32be { return #force_inline f32be(trunc_f32(f32(x))); }
|
||||
trunc_f32le :: proc(x: f32le) -> f32le { return #force_inline f32le(trunc_f32(f32(x))) }
|
||||
trunc_f32be :: proc(x: f32be) -> f32be { return #force_inline f32be(trunc_f32(f32(x))) }
|
||||
|
||||
trunc_f64 :: proc(x: f64) -> f64 {
|
||||
trunc_internal :: proc(f: f64) -> f64 {
|
||||
@@ -502,8 +502,8 @@ trunc_f64 :: proc(x: f64) -> f64 {
|
||||
}
|
||||
return trunc_internal(x)
|
||||
}
|
||||
trunc_f64le :: proc(x: f64le) -> f64le { return #force_inline f64le(trunc_f64(f64(x))); }
|
||||
trunc_f64be :: proc(x: f64be) -> f64be { return #force_inline f64be(trunc_f64(f64(x))); }
|
||||
trunc_f64le :: proc(x: f64le) -> f64le { return #force_inline f64le(trunc_f64(f64(x))) }
|
||||
trunc_f64be :: proc(x: f64be) -> f64be { return #force_inline f64be(trunc_f64(f64(x))) }
|
||||
trunc :: proc{
|
||||
trunc_f16, trunc_f16le, trunc_f16be,
|
||||
trunc_f32, trunc_f32le, trunc_f32be,
|
||||
@@ -545,17 +545,17 @@ round :: proc{
|
||||
}
|
||||
|
||||
|
||||
ceil_f16 :: proc(x: f16) -> f16 { return -floor(-x); }
|
||||
ceil_f16le :: proc(x: f16le) -> f16le { return -floor(-x); }
|
||||
ceil_f16be :: proc(x: f16be) -> f16be { return -floor(-x); }
|
||||
ceil_f16 :: proc(x: f16) -> f16 { return -floor(-x) }
|
||||
ceil_f16le :: proc(x: f16le) -> f16le { return -floor(-x) }
|
||||
ceil_f16be :: proc(x: f16be) -> f16be { return -floor(-x) }
|
||||
|
||||
ceil_f32 :: proc(x: f32) -> f32 { return -floor(-x); }
|
||||
ceil_f32le :: proc(x: f32le) -> f32le { return -floor(-x); }
|
||||
ceil_f32be :: proc(x: f32be) -> f32be { return -floor(-x); }
|
||||
ceil_f32 :: proc(x: f32) -> f32 { return -floor(-x) }
|
||||
ceil_f32le :: proc(x: f32le) -> f32le { return -floor(-x) }
|
||||
ceil_f32be :: proc(x: f32be) -> f32be { return -floor(-x) }
|
||||
|
||||
ceil_f64 :: proc(x: f64) -> f64 { return -floor(-x); }
|
||||
ceil_f64le :: proc(x: f64le) -> f64le { return -floor(-x); }
|
||||
ceil_f64be :: proc(x: f64be) -> f64be { return -floor(-x); }
|
||||
ceil_f64 :: proc(x: f64) -> f64 { return -floor(-x) }
|
||||
ceil_f64le :: proc(x: f64le) -> f64le { return -floor(-x) }
|
||||
ceil_f64be :: proc(x: f64be) -> f64be { return -floor(-x) }
|
||||
|
||||
ceil :: proc{
|
||||
ceil_f16, ceil_f16le, ceil_f16be,
|
||||
@@ -577,8 +577,8 @@ floor_f16 :: proc(x: f16) -> f16 {
|
||||
d, _ := modf(x)
|
||||
return d
|
||||
}
|
||||
floor_f16le :: proc(x: f16le) -> f16le { return #force_inline f16le(floor_f16(f16(x))); }
|
||||
floor_f16be :: proc(x: f16be) -> f16be { return #force_inline f16be(floor_f16(f16(x))); }
|
||||
floor_f16le :: proc(x: f16le) -> f16le { return #force_inline f16le(floor_f16(f16(x))) }
|
||||
floor_f16be :: proc(x: f16be) -> f16be { return #force_inline f16be(floor_f16(f16(x))) }
|
||||
floor_f32 :: proc(x: f32) -> f32 {
|
||||
if x == 0 || is_nan(x) || is_inf(x) {
|
||||
return x
|
||||
@@ -593,8 +593,8 @@ floor_f32 :: proc(x: f32) -> f32 {
|
||||
d, _ := modf(x)
|
||||
return d
|
||||
}
|
||||
floor_f32le :: proc(x: f32le) -> f32le { return #force_inline f32le(floor_f32(f32(x))); }
|
||||
floor_f32be :: proc(x: f32be) -> f32be { return #force_inline f32be(floor_f32(f32(x))); }
|
||||
floor_f32le :: proc(x: f32le) -> f32le { return #force_inline f32le(floor_f32(f32(x))) }
|
||||
floor_f32be :: proc(x: f32be) -> f32be { return #force_inline f32be(floor_f32(f32(x))) }
|
||||
floor_f64 :: proc(x: f64) -> f64 {
|
||||
if x == 0 || is_nan(x) || is_inf(x) {
|
||||
return x
|
||||
@@ -609,8 +609,8 @@ floor_f64 :: proc(x: f64) -> f64 {
|
||||
d, _ := modf(x)
|
||||
return d
|
||||
}
|
||||
floor_f64le :: proc(x: f64le) -> f64le { return #force_inline f64le(floor_f64(f64(x))); }
|
||||
floor_f64be :: proc(x: f64be) -> f64be { return #force_inline f64be(floor_f64(f64(x))); }
|
||||
floor_f64le :: proc(x: f64le) -> f64le { return #force_inline f64le(floor_f64(f64(x))) }
|
||||
floor_f64be :: proc(x: f64be) -> f64be { return #force_inline f64be(floor_f64(f64(x))) }
|
||||
floor :: proc{
|
||||
floor_f16, floor_f16le, floor_f16be,
|
||||
floor_f32, floor_f32le, floor_f32be,
|
||||
@@ -754,8 +754,8 @@ mod_f16 :: proc(x, y: f16) -> (n: f16) {
|
||||
}
|
||||
return copy_sign(n, x)
|
||||
}
|
||||
mod_f16le :: proc(x, y: f16le) -> (n: f16le) { return #force_inline f16le(mod_f16(f16(x), f16(y))); }
|
||||
mod_f16be :: proc(x, y: f16be) -> (n: f16be) { return #force_inline f16be(mod_f16(f16(x), f16(y))); }
|
||||
mod_f16le :: proc(x, y: f16le) -> (n: f16le) { return #force_inline f16le(mod_f16(f16(x), f16(y))) }
|
||||
mod_f16be :: proc(x, y: f16be) -> (n: f16be) { return #force_inline f16be(mod_f16(f16(x), f16(y))) }
|
||||
mod_f32 :: proc(x, y: f32) -> (n: f32) {
|
||||
z := abs(y)
|
||||
n = remainder(abs(x), z)
|
||||
@@ -764,8 +764,8 @@ mod_f32 :: proc(x, y: f32) -> (n: f32) {
|
||||
}
|
||||
return copy_sign(n, x)
|
||||
}
|
||||
mod_f32le :: proc(x, y: f32le) -> (n: f32le) { return #force_inline f32le(mod_f32(f32(x), f32(y))); }
|
||||
mod_f32be :: proc(x, y: f32be) -> (n: f32be) { return #force_inline f32be(mod_f32(f32(x), f32(y))); }
|
||||
mod_f32le :: proc(x, y: f32le) -> (n: f32le) { return #force_inline f32le(mod_f32(f32(x), f32(y))) }
|
||||
mod_f32be :: proc(x, y: f32be) -> (n: f32be) { return #force_inline f32be(mod_f32(f32(x), f32(y))) }
|
||||
mod_f64 :: proc(x, y: f64) -> (n: f64) {
|
||||
z := abs(y)
|
||||
n = remainder(abs(x), z)
|
||||
@@ -774,23 +774,23 @@ mod_f64 :: proc(x, y: f64) -> (n: f64) {
|
||||
}
|
||||
return copy_sign(n, x)
|
||||
}
|
||||
mod_f64le :: proc(x, y: f64le) -> (n: f64le) { return #force_inline f64le(mod_f64(f64(x), f64(y))); }
|
||||
mod_f64be :: proc(x, y: f64be) -> (n: f64be) { return #force_inline f64be(mod_f64(f64(x), f64(y))); }
|
||||
mod_f64le :: proc(x, y: f64le) -> (n: f64le) { return #force_inline f64le(mod_f64(f64(x), f64(y))) }
|
||||
mod_f64be :: proc(x, y: f64be) -> (n: f64be) { return #force_inline f64be(mod_f64(f64(x), f64(y))) }
|
||||
mod :: proc{
|
||||
mod_f16, mod_f16le, mod_f16be,
|
||||
mod_f32, mod_f32le, mod_f32be,
|
||||
mod_f64, mod_f64le, mod_f64be,
|
||||
}
|
||||
|
||||
remainder_f16 :: proc(x, y: f16 ) -> f16 { return x - round(x/y) * y; }
|
||||
remainder_f16le :: proc(x, y: f16le) -> f16le { return x - round(x/y) * y; }
|
||||
remainder_f16be :: proc(x, y: f16be) -> f16be { return x - round(x/y) * y; }
|
||||
remainder_f32 :: proc(x, y: f32 ) -> f32 { return x - round(x/y) * y; }
|
||||
remainder_f32le :: proc(x, y: f32le) -> f32le { return x - round(x/y) * y; }
|
||||
remainder_f32be :: proc(x, y: f32be) -> f32be { return x - round(x/y) * y; }
|
||||
remainder_f64 :: proc(x, y: f64 ) -> f64 { return x - round(x/y) * y; }
|
||||
remainder_f64le :: proc(x, y: f64le) -> f64le { return x - round(x/y) * y; }
|
||||
remainder_f64be :: proc(x, y: f64be) -> f64be { return x - round(x/y) * y; }
|
||||
remainder_f16 :: proc(x, y: f16 ) -> f16 { return x - round(x/y) * y }
|
||||
remainder_f16le :: proc(x, y: f16le) -> f16le { return x - round(x/y) * y }
|
||||
remainder_f16be :: proc(x, y: f16be) -> f16be { return x - round(x/y) * y }
|
||||
remainder_f32 :: proc(x, y: f32 ) -> f32 { return x - round(x/y) * y }
|
||||
remainder_f32le :: proc(x, y: f32le) -> f32le { return x - round(x/y) * y }
|
||||
remainder_f32be :: proc(x, y: f32be) -> f32be { return x - round(x/y) * y }
|
||||
remainder_f64 :: proc(x, y: f64 ) -> f64 { return x - round(x/y) * y }
|
||||
remainder_f64le :: proc(x, y: f64le) -> f64le { return x - round(x/y) * y }
|
||||
remainder_f64be :: proc(x, y: f64be) -> f64be { return x - round(x/y) * y }
|
||||
remainder :: proc{
|
||||
remainder_f16, remainder_f16le, remainder_f16be,
|
||||
remainder_f32, remainder_f32le, remainder_f32be,
|
||||
@@ -958,8 +958,8 @@ classify_f16 :: proc(x: f16) -> Float_Class {
|
||||
}
|
||||
return .Normal
|
||||
}
|
||||
classify_f16le :: proc(x: f16le) -> Float_Class { return #force_inline classify_f16(f16(x)); }
|
||||
classify_f16be :: proc(x: f16be) -> Float_Class { return #force_inline classify_f16(f16(x)); }
|
||||
classify_f16le :: proc(x: f16le) -> Float_Class { return #force_inline classify_f16(f16(x)) }
|
||||
classify_f16be :: proc(x: f16be) -> Float_Class { return #force_inline classify_f16(f16(x)) }
|
||||
classify_f32 :: proc(x: f32) -> Float_Class {
|
||||
switch {
|
||||
case x == 0:
|
||||
@@ -984,8 +984,8 @@ classify_f32 :: proc(x: f32) -> Float_Class {
|
||||
}
|
||||
return .Normal
|
||||
}
|
||||
classify_f32le :: proc(x: f32le) -> Float_Class { return #force_inline classify_f32(f32(x)); }
|
||||
classify_f32be :: proc(x: f32be) -> Float_Class { return #force_inline classify_f32(f32(x)); }
|
||||
classify_f32le :: proc(x: f32le) -> Float_Class { return #force_inline classify_f32(f32(x)) }
|
||||
classify_f32be :: proc(x: f32be) -> Float_Class { return #force_inline classify_f32(f32(x)) }
|
||||
classify_f64 :: proc(x: f64) -> Float_Class {
|
||||
switch {
|
||||
case x == 0:
|
||||
@@ -1009,23 +1009,23 @@ classify_f64 :: proc(x: f64) -> Float_Class {
|
||||
}
|
||||
return .Normal
|
||||
}
|
||||
classify_f64le :: proc(x: f64le) -> Float_Class { return #force_inline classify_f64(f64(x)); }
|
||||
classify_f64be :: proc(x: f64be) -> Float_Class { return #force_inline classify_f64(f64(x)); }
|
||||
classify_f64le :: proc(x: f64le) -> Float_Class { return #force_inline classify_f64(f64(x)) }
|
||||
classify_f64be :: proc(x: f64be) -> Float_Class { return #force_inline classify_f64(f64(x)) }
|
||||
classify :: proc{
|
||||
classify_f16, classify_f16le, classify_f16be,
|
||||
classify_f32, classify_f32le, classify_f32be,
|
||||
classify_f64, classify_f64le, classify_f64be,
|
||||
}
|
||||
|
||||
is_nan_f16 :: proc(x: f16) -> bool { return classify(x) == .NaN; }
|
||||
is_nan_f16le :: proc(x: f16le) -> bool { return classify(x) == .NaN; }
|
||||
is_nan_f16be :: proc(x: f16be) -> bool { return classify(x) == .NaN; }
|
||||
is_nan_f32 :: proc(x: f32) -> bool { return classify(x) == .NaN; }
|
||||
is_nan_f32le :: proc(x: f32le) -> bool { return classify(x) == .NaN; }
|
||||
is_nan_f32be :: proc(x: f32be) -> bool { return classify(x) == .NaN; }
|
||||
is_nan_f64 :: proc(x: f64) -> bool { return classify(x) == .NaN; }
|
||||
is_nan_f64le :: proc(x: f64le) -> bool { return classify(x) == .NaN; }
|
||||
is_nan_f64be :: proc(x: f64be) -> bool { return classify(x) == .NaN; }
|
||||
is_nan_f16 :: proc(x: f16) -> bool { return classify(x) == .NaN }
|
||||
is_nan_f16le :: proc(x: f16le) -> bool { return classify(x) == .NaN }
|
||||
is_nan_f16be :: proc(x: f16be) -> bool { return classify(x) == .NaN }
|
||||
is_nan_f32 :: proc(x: f32) -> bool { return classify(x) == .NaN }
|
||||
is_nan_f32le :: proc(x: f32le) -> bool { return classify(x) == .NaN }
|
||||
is_nan_f32be :: proc(x: f32be) -> bool { return classify(x) == .NaN }
|
||||
is_nan_f64 :: proc(x: f64) -> bool { return classify(x) == .NaN }
|
||||
is_nan_f64le :: proc(x: f64le) -> bool { return classify(x) == .NaN }
|
||||
is_nan_f64be :: proc(x: f64be) -> bool { return classify(x) == .NaN }
|
||||
is_nan :: proc{
|
||||
is_nan_f16, is_nan_f16le, is_nan_f16be,
|
||||
is_nan_f32, is_nan_f32le, is_nan_f32be,
|
||||
|
||||
@@ -43,7 +43,7 @@ _random :: proc(r: ^Rand) -> u32 {
|
||||
return (xor_shifted >> rot) | (xor_shifted << ((-rot) & 31))
|
||||
}
|
||||
|
||||
uint32 :: proc(r: ^Rand = nil) -> u32 { return _random(r); }
|
||||
uint32 :: proc(r: ^Rand = nil) -> u32 { return _random(r) }
|
||||
|
||||
uint64 :: proc(r: ^Rand = nil) -> u64 {
|
||||
a := u64(_random(r))
|
||||
@@ -59,9 +59,9 @@ uint128 :: proc(r: ^Rand = nil) -> u128 {
|
||||
return (a<<96) | (b<<64) | (c<<32) | d
|
||||
}
|
||||
|
||||
int31 :: proc(r: ^Rand = nil) -> i32 { return i32(uint32(r) << 1 >> 1); }
|
||||
int63 :: proc(r: ^Rand = nil) -> i64 { return i64(uint64(r) << 1 >> 1); }
|
||||
int127 :: proc(r: ^Rand = nil) -> i128 { return i128(uint128(r) << 1 >> 1); }
|
||||
int31 :: proc(r: ^Rand = nil) -> i32 { return i32(uint32(r) << 1 >> 1) }
|
||||
int63 :: proc(r: ^Rand = nil) -> i64 { return i64(uint64(r) << 1 >> 1) }
|
||||
int127 :: proc(r: ^Rand = nil) -> i128 { return i128(uint128(r) << 1 >> 1) }
|
||||
|
||||
int31_max :: proc(n: i32, r: ^Rand = nil) -> i32 {
|
||||
if n <= 0 {
|
||||
@@ -119,11 +119,11 @@ int_max :: proc(n: int, r: ^Rand = nil) -> int {
|
||||
}
|
||||
}
|
||||
|
||||
float64 :: proc(r: ^Rand = nil) -> f64 { return f64(int63_max(1<<53, r)) / (1 << 53); }
|
||||
float32 :: proc(r: ^Rand = nil) -> f32 { return f32(float64(r)); }
|
||||
float64 :: proc(r: ^Rand = nil) -> f64 { return f64(int63_max(1<<53, r)) / (1 << 53) }
|
||||
float32 :: proc(r: ^Rand = nil) -> f32 { return f32(float64(r)) }
|
||||
|
||||
float64_range :: proc(lo, hi: f64, r: ^Rand = nil) -> f64 { return (hi-lo)*float64(r) + lo; }
|
||||
float32_range :: proc(lo, hi: f32, r: ^Rand = nil) -> f32 { return (hi-lo)*float32(r) + lo; }
|
||||
float64_range :: proc(lo, hi: f64, r: ^Rand = nil) -> f64 { return (hi-lo)*float64(r) + lo }
|
||||
float32_range :: proc(lo, hi: f32, r: ^Rand = nil) -> f32 { return (hi-lo)*float32(r) + lo }
|
||||
|
||||
|
||||
read :: proc(p: []byte, r: ^Rand = nil) -> (n: int) {
|
||||
|
||||
Reference in New Issue
Block a user