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

math.bits: add some more helpers, to be used in upcoming biginteger

This commit is contained in:
joe-conigliaro
2019-09-21 00:39:36 +10:00
committed by Alexander Medvednikov
parent 5a03eaca89
commit d80a3365c4
3 changed files with 329 additions and 3 deletions

View File

@ -5,13 +5,12 @@
module rand
import(
math
math.bits
encoding.binary
)
pub fn int_u64(max u64) u64? {
// bitlen := int(math.floor(math.log2(f64(max))+1))
bitlen := int(math.floor(math.log(f64(max))/math.log(2)) + 1)
bitlen := bits.len64(max)
if bitlen == 0 {
return u64(0)
}