In role Numeric§

See primary documentation in context for routine log2

multi sub    log2(Numeric:D)
multi method log2(Numeric:D:)

Calculates the logarithm to base 2. Returns -Inf for 0.

Returns NaN for negative arguments. As of 6.e language version (early implementation exists in Rakudo compiler 2023.02+), will return a Complex value for negative arguments.

In Cool§

See primary documentation in context for routine log2

multi method log2()
multi sub log2(Numeric $x)
multi sub log2(Cool    $x)

Coerces the invocant to Numeric, and returns its Logarithm in base 2, that is, a number that approximately (due to computer precision limitations) produces the original number when 2 is raised to its power. Returns -Inf for 0.

say log2(5);            # OUTPUT: «2.321928094887362␤» 
say "4".log2;           # OUTPUT: «2␤» 
say 4.log2;             # OUTPUT: «2␤»

Returns NaN for negative arguments. As of 6.e language version (early implementation exists in Rakudo compiler 2023.02+), will return a Complex value for negative arguments.