fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 263: Integer logarithm in base 2
Idiom # 263: Integer logarithm in base 2
See
programming-idioms.org
:
Code
log2 (n f64) f64 => n.log / (f64 2).log log2d (n f64) f64 => (log2 n).floor log2u (n f64) f64 => (log2 n).ceil
What are effects?
Runnable Example
ex263 is log2 (n f64) f64 => n.log / (f64 2).log log2d (n f64) f64 => (log2 n).floor log2u (n f64) f64 => (log2 n).ceil for n in 1..12 do f := f64.from_u32 n.cast_to_u32 say "{n} {log2d f} {log2u f}"
What are effects?
last changed: 2024-07-01
next: Idiom # 264: Automated passing of array bounds