30 lines
No EOL
2.3 KiB
HTML
30 lines
No EOL
2.3 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Arithmetic — Ludic</title>
|
||
<meta name="description" content="Add, subtract, multiply, integer-divide, and remainder — on int and fixed.">
|
||
<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> <a href="api.html#operators">Operators & tokens</a> <span>›</span> <span class="here">Arithmetic</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-operator">operator</span>
|
||
<h1 id="top">Arithmetic</h1>
|
||
</div>
|
||
<code class="sig">+ - * / %</code>
|
||
<div class="desc"><p>The arithmetic operators are <code>+</code> (add), <code>-</code> (subtract), <code>*</code> (multiply), <code>/</code> (divide), and <code>%</code> (remainder). On <code>int</code> values <code>/</code> is integer division that truncates and <code>%</code> gives the remainder — handy for wrapping a value or testing a period, as in <code>elapsed_frames % 30 == 0</code>. On <code>fixed</code> values the same symbols do fixed-point math (multiply and divide are scaled), and mixing an <code>int</code> with a <code>fixed</code> promotes the <code>int</code>. <code>*</code>, <code>/</code>, and <code>%</code> bind tighter than <code>+</code> and <code>-</code>, so <code>column * TILE_SIZE + 1</code> groups as expected.</p></div>
|
||
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">let pixel_x: int = column * TILE_SIZE + 1
|
||
let is_even_row: bool = row % 2 == 0
|
||
let average: int = (current_health + maximum_health) / 2</pre></div>
|
||
|
||
<a class="back" href="api.html">← All symbols</a>
|
||
</main>
|
||
<script src="ludic-highlight.js"></script>
|
||
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
|
||
</body></html> |