Skip to content

Add log2 and log10 to lib/math.eigs #545

Description

@InauguralPhysicist

Summary

log (natural) is the only logarithm exposed. Audio/DSP code needs the other two bases constantly — MIDI math is base-2 (midi = 69 + 12*log2(f/440)), decibel math is base-10 (db = 20*log10(v)) — and every consumer writes the same one-liners.

The DeslanStudios port defines _log2 in src/tools/pitch.eigs and inlines (log of x) / (log of 10) in the mixer's meter readouts (mixt_get_peak_db / mixt_get_rms_db); any emulator, SAT-solver bit-math, or entropy code wants log2 too.

What to add

Pure EigenScript, in lib/math.eigs (same shape as #193's find_index):

define log2(x) as:
    return (log of x) / 0.6931471805599453

define log10(x) as:
    return (log of x) / 2.302585092994046

(Or divide by log of 2 / log of 10 if constants are unwanted.) Domain behavior comes free from log's documented input floor at 1e-10 — no new edge cases.

Definition of done

  1. log2 / log10 in lib/math.eigs with signature comments.
  2. Assertions: log2 of 8 == 3, log2 of 1 == 0, log10 of 1000 == 3, round-trip with pow.
  3. Rows in the lib/math.eigs table in docs/STDLIB.md.

Environment

  • EigenScript 0.29.0, HEAD 82ab2ae.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions