qml.math.ceil_log2¶
- ceil_log2(n)[source]¶
Compute the ceiling of the base-2 logarithm of an integer, with integer as output data type.
- Parameters:
n (int) – Integer to compute the rounded-up base-2 logarithm of.
- Returns:
Rounded-up base-2 logarithm of
n.- Return type:
int
Example
On powers of two,
ceil_log2simply acts likenp.log2whose result was converted to anint:>>> qml.math.ceil_log2(8) 3
On other numbers, the rounding of the logarithm becomes visible:
>>> qml.math.log2(14) 3.807354922057604 >>> qml.math.ceil_log2(14) 4
Note that we always round up:
>>> qml.math.round(qml.math.log2(9)) 3.0 >>> qml.math.ceil_log2(9) 4
code/api/pennylane.math.ceil_log2
Download Python script
Download Notebook
View on GitHub