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

22 lines
No EOL
4 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>Decimal — Ludic</title>
<meta name="description" content="Exact base-10 fixed-point numbers for game economies — prices, balances and taxes on values like 0.10 that binary floating point cannot represent, so they…">
<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">Decimal</span></div>
<div class="item-head"><span class="kind-badge kind-namespace">namespace</span><h1 id="top">Decimal</h1></div>
<p class="ns-blurb">Exact base-10 fixed-point numbers for game economies — prices, balances and taxes on values like <code>0.10</code> that binary floating point cannot represent, so they always add up exactly. A <code>Decimal</code> is a <code>BigInt</code> mantissa with a decimal <code>scale</code> (the number of digits after the point), giving unbounded range and exact <code>add</code> / <code>sub</code> / <code>mul</code>. Build one with <code>Decimal.from</code> (an <code>int</code>) or <code>Decimal.parse</code> (text like <code>"19.99"</code>), compare with <code>cmp</code> / <code>eq</code>, change precision with <code>rescale</code> (truncates toward zero), read the current precision with <code>scale</code>, and render with <code>str</code>. Every operation is exact and deterministic. The runtime is spliced in only when a program mentions <code>Decimal.*</code> (or <code>BigInt.*</code>).</p>
<div class="ns-methods"><a class="ns-method" href="decimal-from.html"><code class="nm-sig">Decimal.from(value) -&gt; Decimal</code><span class="nm-tip">Turn a whole int into a Decimal.</span></a><a class="ns-method" href="decimal-parse.html"><code class="nm-sig">Decimal.parse(text) -&gt; Decimal</code><span class="nm-tip">Parse decimal text like "19.99".</span></a><a class="ns-method" href="decimal-add.html"><code class="nm-sig">Decimal.add(a, b) -&gt; Decimal</code><span class="nm-tip">Exact sum of two decimals.</span></a><a class="ns-method" href="decimal-sub.html"><code class="nm-sig">Decimal.sub(a, b) -&gt; Decimal</code><span class="nm-tip">Exact difference of two decimals.</span></a><a class="ns-method" href="decimal-mul.html"><code class="nm-sig">Decimal.mul(a, b) -&gt; Decimal</code><span class="nm-tip">Exact product of two decimals.</span></a><a class="ns-method" href="decimal-neg.html"><code class="nm-sig">Decimal.neg(a) -&gt; Decimal</code><span class="nm-tip">Negate a decimal.</span></a><a class="ns-method" href="decimal-cmp.html"><code class="nm-sig">Decimal.cmp(a, b) -&gt; int</code><span class="nm-tip">Compare two decimals: -1, 0, or 1.</span></a><a class="ns-method" href="decimal-eq.html"><code class="nm-sig">Decimal.eq(a, b) -&gt; bool</code><span class="nm-tip">True when two decimals are equal in value.</span></a><a class="ns-method" href="decimal-scale.html"><code class="nm-sig">Decimal.scale(d) -&gt; int</code><span class="nm-tip">The number of digits after the point.</span></a><a class="ns-method" href="decimal-rescale.html"><code class="nm-sig">Decimal.rescale(d, places) -&gt; Decimal</code><span class="nm-tip">Change precision (truncates toward zero).</span></a><a class="ns-method" href="decimal-str.html"><code class="nm-sig">Decimal.str(d) -&gt; string</code><span class="nm-tip">Render a decimal as text.</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>