33 lines
No EOL
2.3 KiB
HTML
33 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>float_bits — Ludic</title>
|
||
<meta name="description" content="A float's IEEE bit pattern as an int, and back.">
|
||
<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_bits</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-builtin">function</span>
|
||
<h1 id="top">float_bits</h1>
|
||
</div>
|
||
<code class="sig">float_bits(x) -> int / float_from_bits(bits) -> float</code>
|
||
<div class="desc"><p><code>float_bits(x)</code> returns the 32 bits of a <code>float</code> as an <code>int</code>, and <code>float_from_bits(bits)</code> reads them back. <code>double_bits</code> / <code>double_from_bits</code> do the same for a <code>double</code> with a <code>long</code>. Use them where a float has to travel as raw data: a file format, a network packet, or a <code>words</code> buffer shared with code that still stores bit patterns.</p></div>
|
||
<div class="params"><h2>Parameters</h2><div class="param" id="param-x"><code class="pname">x</code><span class="pdesc">the float to encode (<code>float_bits</code>), or the bits to decode (<code>float_from_bits</code>)</span></div></div>
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Bits {
|
||
entry {
|
||
print(float_bits(1.0)) # 1065353216 (0x3F800000)
|
||
print(float_from_bits(0x40000000)) # 2.0
|
||
}
|
||
}</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> |