ludic/ns-math.html
2026-09-17 22:10:03 +00:00

24 lines
No EOL
7.2 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Math — Ludic</title>
<meta name="description" content="Deterministic fixed-point math.">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="docs.css">
</head>
<body>
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
<main class="wrap item">
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <span class="here">Math</span></div>
<div class="item-head"><span class="kind-badge kind-namespace">namespace</span><h1 id="top">Math</h1></div>
<p class="ns-blurb">Deterministic fixed-point math. Every function is computed in Q16.16 with plain integer arithmetic, so results are bit-identical on every platform and every run — the same guarantee the rest of the runtime gives. Arguments are positional.
Given a <code>float</code> or <code>double</code> argument, the same functions compute in that type instead (using the platform's math library) and return it — <code>floor</code>, <code>ceil</code> and <code>round</code> included, which return an <code>int</code> only for <code>fixed</code>. <code>sign</code> returns an <code>int</code> either way. <code>trunc</code> and <code>atan</code> exist only for floats.</p>
<div class="ns-methods"><a class="ns-method" href="math-min.html"><code class="nm-sig">Math.min(a, b) -&gt; int</code><span class="nm-tip">The smaller of two values.</span></a><a class="ns-method" href="math-max.html"><code class="nm-sig">Math.max(a, b) -&gt; int</code><span class="nm-tip">The larger of two values.</span></a><a class="ns-method" href="math-abs.html"><code class="nm-sig">Math.abs(x) -&gt; int</code><span class="nm-tip">The magnitude of a value, dropping its sign.</span></a><a class="ns-method" href="math-clamp.html"><code class="nm-sig">Math.clamp(v, lo, hi) -&gt; int</code><span class="nm-tip">Constrain a value to the range [lo, hi].</span></a><a class="ns-method" href="math-sign.html"><code class="nm-sig">Math.sign(x) -&gt; int</code><span class="nm-tip">The sign of a value as -1, 0, or 1.</span></a><a class="ns-method" href="math-floor.html"><code class="nm-sig">Math.floor(x) -&gt; int</code><span class="nm-tip">Round a fixed value down to the nearest whole int.</span></a><a class="ns-method" href="math-ceil.html"><code class="nm-sig">Math.ceil(x) -&gt; int</code><span class="nm-tip">Round a fixed value up to the nearest whole int.</span></a><a class="ns-method" href="math-round.html"><code class="nm-sig">Math.round(x) -&gt; int</code><span class="nm-tip">Round a fixed value to the nearest whole int.</span></a><a class="ns-method" href="math-lerp.html"><code class="nm-sig">Math.lerp(a, b, t) -&gt; fixed</code><span class="nm-tip">Blend between two values by a 0..1 amount.</span></a><a class="ns-method" href="math-inverse_lerp.html"><code class="nm-sig">Math.inverse_lerp(a, b, v) -&gt; fixed</code><span class="nm-tip">Find where a value sits between two endpoints as a 0..1 fraction.</span></a><a class="ns-method" href="math-remap.html"><code class="nm-sig">Math.remap(v, in0, in1, out0, out1) -&gt; fixed</code><span class="nm-tip">Rescale a value from one range into another.</span></a><a class="ns-method" href="math-sqrt.html"><code class="nm-sig">Math.sqrt(x) -&gt; fixed</code><span class="nm-tip">The square root of a fixed value.</span></a><a class="ns-method" href="math-sin.html"><code class="nm-sig">Math.sin(radians) -&gt; fixed</code><span class="nm-tip">Sine of an angle in radians.</span></a><a class="ns-method" href="math-cos.html"><code class="nm-sig">Math.cos(radians) -&gt; fixed</code><span class="nm-tip">Cosine of an angle in radians.</span></a><a class="ns-method" href="math-tan.html"><code class="nm-sig">Math.tan(radians) -&gt; fixed</code><span class="nm-tip">Tangent of an angle in radians.</span></a><a class="ns-method" href="math-hypot.html"><code class="nm-sig">Math.hypot(x, y) -&gt; fixed</code><span class="nm-tip">Length of the vector (x, y).</span></a><a class="ns-method" href="math-dist.html"><code class="nm-sig">Math.dist(x0, y0, x1, y1) -&gt; fixed</code><span class="nm-tip">Distance between two points.</span></a><a class="ns-method" href="math-dist2.html"><code class="nm-sig">Math.dist2(x0, y0, x1, y1) -&gt; fixed</code><span class="nm-tip">Squared distance between two points.</span></a><a class="ns-method" href="math-deg_to_rad.html"><code class="nm-sig">Math.deg_to_rad(degrees) -&gt; fixed</code><span class="nm-tip">Convert degrees to radians.</span></a><a class="ns-method" href="math-rad_to_deg.html"><code class="nm-sig">Math.rad_to_deg(radians) -&gt; fixed</code><span class="nm-tip">Convert radians to degrees.</span></a><a class="ns-method" href="math-posmod.html"><code class="nm-sig">Math.posmod(a, m) -&gt; int</code><span class="nm-tip">Modulo that is always non-negative.</span></a><a class="ns-method" href="math-wrap.html"><code class="nm-sig">Math.wrap(v, lo, hi) -&gt; int</code><span class="nm-tip">Wrap a value into the range [lo, hi).</span></a><a class="ns-method" href="math-ping_pong.html"><code class="nm-sig">Math.ping_pong(t, len) -&gt; int</code><span class="nm-tip">Bounce a counter back and forth in [0, len].</span></a><a class="ns-method" href="math-snapped.html"><code class="nm-sig">Math.snapped(v, step) -&gt; fixed</code><span class="nm-tip">Round a value to the nearest multiple of step.</span></a><a class="ns-method" href="math-move_toward.html"><code class="nm-sig">Math.move_toward(from, to, delta) -&gt; fixed</code><span class="nm-tip">Step from one value toward another by at most delta.</span></a><a class="ns-method" href="math-smoothstep.html"><code class="nm-sig">Math.smoothstep(e0, e1, x) -&gt; fixed</code><span class="nm-tip">A smooth 0..1 ramp between two edges.</span></a><a class="ns-method" href="math-atan2.html"><code class="nm-sig">Math.atan2(y, x) -&gt; fixed</code><span class="nm-tip">The angle of the vector (x, y), in radians.</span></a><a class="ns-method" href="math-asin.html"><code class="nm-sig">Math.asin(x) -&gt; fixed</code><span class="nm-tip">The arcsine of a value, in radians.</span></a><a class="ns-method" href="math-acos.html"><code class="nm-sig">Math.acos(x) -&gt; fixed</code><span class="nm-tip">The arccosine of a value, in radians.</span></a><a class="ns-method" href="math-exp.html"><code class="nm-sig">Math.exp(x) -&gt; fixed</code><span class="nm-tip">e raised to the power x.</span></a><a class="ns-method" href="math-log.html"><code class="nm-sig">Math.log(x) -&gt; fixed</code><span class="nm-tip">The natural logarithm of x.</span></a><a class="ns-method" href="math-pow.html"><code class="nm-sig">Math.pow(base, exp) -&gt; fixed</code><span class="nm-tip">base raised to a fixed exponent.</span></a></div>
<a class="back" href="api.html">← All symbols</a>
</main>
<script src="ludic-highlight.js"></script>
<script>Ludic.installCards(); Ludic.flashTarget();</script>
</body></html>