Merge pull request 'move log2 from composer to registered function' (#1977) from tyow/localstrudel:log2 into main

Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1977
This commit is contained in:
froos 2026-02-14 23:34:53 +01:00
commit 60da901952
2 changed files with 4 additions and 3 deletions

View file

@ -1158,7 +1158,6 @@ const COMPOSERS = {
div: [numeralArgs((a, b) => a / b)], div: [numeralArgs((a, b) => a / b)],
mod: [numeralArgs(_mod)], mod: [numeralArgs(_mod)],
pow: [numeralArgs(Math.pow)], pow: [numeralArgs(Math.pow)],
log2: [numeralArgs(Math.log2)],
band: [numeralArgs((a, b) => a & b)], band: [numeralArgs((a, b) => a & b)],
bor: [numeralArgs((a, b) => a | b)], bor: [numeralArgs((a, b) => a | b)],
bxor: [numeralArgs((a, b) => a ^ b)], bxor: [numeralArgs((a, b) => a ^ b)],
@ -1864,6 +1863,8 @@ export const floor = register('floor', function (pat) {
return pat.asNumber().fmap((v) => Math.floor(v)); return pat.asNumber().fmap((v) => Math.floor(v));
}); });
export const log2 = register('log2', (pat) => pat.asNumber().fmap((v) => Math.log2(v)));
/** /**
* Assumes a numerical pattern. Returns a new pattern with all values set to * Assumes a numerical pattern. Returns a new pattern with all values set to
* their mathematical ceiling. E.g. `3.2` replaced with `4`, and `-4.2` * their mathematical ceiling. E.g. `3.2` replaced with `4`, and `-4.2`

View file

@ -316,7 +316,7 @@ export const run = (n) => saw.range(0, n).round().segment(n);
* // "hh".s().struct("1 0 1") * // "hh".s().struct("1 0 1")
*/ */
export const binary = (n) => { export const binary = (n) => {
const nBits = reify(n).log2(0).floor().add(1); const nBits = reify(n).log2().floor().add(1);
return binaryN(n, nBits); return binaryN(n, nBits);
}; };
@ -348,7 +348,7 @@ export const binaryN = (n, nBits = 16) => {
* .partials(binaryL(irand(4096).add(1))) * .partials(binaryL(irand(4096).add(1)))
*/ */
export const binaryL = (n) => { export const binaryL = (n) => {
const nBits = reify(n).log2(0).floor().add(1); const nBits = reify(n).log2().floor().add(1);
return binaryNL(n, nBits); return binaryNL(n, nBits);
}; };