mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
big: Add ilog2.
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
*/
|
||||
package math_big
|
||||
|
||||
import "core:intrinsics"
|
||||
|
||||
/*
|
||||
===========================
|
||||
User-level routines
|
||||
@@ -383,6 +385,10 @@ digit_log :: proc(a: DIGIT, base: DIGIT) -> (log: int, err: Error) {
|
||||
}
|
||||
log :: proc { int_log, digit_log, };
|
||||
|
||||
ilog2 :: proc(value: $T) -> (log2: T) {
|
||||
return (size_of(T) * 8) - intrinsics.count_leading_zeros(value);
|
||||
}
|
||||
|
||||
/*
|
||||
Calculate `dest = base^power` using a square-multiply algorithm.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user