34 lines
No EOL
2.2 KiB
HTML
34 lines
No EOL
2.2 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>float — Ludic</title>
|
||
<meta name="description" content="Convert any number to a float (or double).">
|
||
<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#builtins">Builtin functions</a> <span>›</span> <span class="here">float</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-builtin">function</span>
|
||
<h1 id="top">float</h1>
|
||
</div>
|
||
<code class="sig">float(x) -> float / double(x) -> double</code>
|
||
<div class="desc"><p>Converts an <code>int</code>, <code>long</code>, <code>fixed</code>, <code>float</code> or <code>double</code> to a <code>float</code> (or, with <code>double(x)</code>, to a <code>double</code>). It is the one conversion that crosses from fixed-point to floating point: <code>float(fixed(1)) / 4.0</code> is <code>0.25</code>. A decimal literal converts exactly, so <code>float(0.1)</code> is the nearest float to 0.1, not the nearest Q16.16 value.</p></div>
|
||
<div class="params"><h2>Parameters</h2><div class="param" id="param-x"><code class="pname">x</code><span class="pdesc">the number to convert</span></div></div>
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Convert {
|
||
entry {
|
||
let half = fixed(1) / 2
|
||
print(float(half) * 3.0) # 1.5
|
||
print(double(7) / 2) # 3.5
|
||
}
|
||
}</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> |