2021-01-21 13:40:28 +01:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
|
|
|
<title>.</title>
|
|
|
|
<style type="text/css">
|
|
|
|
|
|
|
|
* { color: #000; background: #fff; max-width: 700px; }
|
|
|
|
tt, pre { background: #dedede; color: #111; font-family: monospace;
|
|
|
|
white-space: pre; display: block; width: 100%; }
|
|
|
|
.indentedcode { margin-left: 2em; margin-right: 2em; }
|
|
|
|
.codeblock {
|
|
|
|
background: #dedede; color: #111; font-family: monospace;
|
|
|
|
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
|
|
|
padding: 7px;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.indentedlist { margin-left: 2em; color: #000; }
|
|
|
|
|
|
|
|
span { white-space: pre; }
|
|
|
|
.text { color: #000; white-space: pre; background: #dedede; }
|
|
|
|
.colon { color: #000; background: #dedede; }
|
|
|
|
.note { color: #000; background: #dedede; }
|
|
|
|
.str { color: #000; text-decoration: underline; background: #dedede; }
|
|
|
|
.num { color: #000; background: #dedede; font-weight: bold; font-style: italic; }
|
|
|
|
.fnum { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.ptr { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.fetch { color: #000; font-style: italic; background: #dedede; }
|
|
|
|
.store { color: #000; font-style: italic; background: #dedede; }
|
|
|
|
.char { color: #000; background: #dedede; }
|
|
|
|
.inst { color: #000; background: #dedede; }
|
|
|
|
.defer { color: #000; background: #dedede; }
|
|
|
|
.imm { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.prim { color: #000; font-weight: bolder; background: #dedede; }
|
|
|
|
|
|
|
|
.tt { white-space: pre; font-family: monospace; background: #dedede; }
|
|
|
|
|
|
|
|
.h1, .h2, .h3, .h4 { white-space: normal; }
|
|
|
|
.h1 { font-size: 125%; }
|
|
|
|
.h2 { font-size: 120%; }
|
|
|
|
.h3 { font-size: 115%; }
|
|
|
|
.h4 { font-size: 110%; }
|
|
|
|
.hr { display: block; height: 2px; background: #000000; }
|
|
|
|
</style>
|
|
|
|
</head><body>
|
2022-06-03 12:41:52 +02:00
|
|
|
<p><br/><br/>
|
2021-01-21 13:40:28 +01:00
|
|
|
Some RETRO systems include support for floating point numbers.
|
|
|
|
When present, this is built over the system <span class="tt">libm</span> using the
|
|
|
|
C <span class="tt">double</span> type.
|
|
|
|
<br/><br/>
|
|
|
|
Floating point values are typically 64 bit IEEE 754 double
|
|
|
|
precision (1 bit for the sign, 11 bits for the exponent, and
|
|
|
|
the remaining 52 bits for the value), i.e. 15 decimal digits
|
|
|
|
of precision.
|
|
|
|
<br/><br/>
|
2021-03-30 13:58:25 +02:00
|
|
|
<span class="h2">Sigil</span>
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
|
|
|
Floating point numbers start with a <span class="tt">.</span>
|
|
|
|
<br/><br/>
|
|
|
|
Examples:
|
|
|
|
<br/><br/>
|
|
|
|
Token Value
|
|
|
|
<tt class='indentedcode'>.1 1.0</tt>
|
|
|
|
<tt class='indentedcode'>.0.5 0.5</tt>
|
|
|
|
<tt class='indentedcode'>.-.4 -0.4</tt>
|
|
|
|
<tt class='indentedcode'>.1.3 1.3</tt>
|
|
|
|
<br/><br/>
|
|
|
|
<span class="h2">Namespace</span>
|
|
|
|
<br/><br/>
|
|
|
|
Floating point words are in the <span class="tt">f:</span> namespace. There is also
|
|
|
|
a related <span class="tt">e:</span> namespace for <strong>encoded values</strong>, which allows
|
|
|
|
storing of floats in standard memory.
|
|
|
|
<br/><br/>
|
|
|
|
<span class="h2">Operation</span>
|
|
|
|
<br/><br/>
|
|
|
|
Floating point values exist on a separate stack, and are bigger
|
|
|
|
than the standard memory cells, so can not be directly stored
|
|
|
|
and fetched from memory.
|
|
|
|
<br/><br/>
|
|
|
|
The floating point system also provides an alternate stack that
|
|
|
|
can be used to temporarily store values.
|
|
|
|
<br/><br/>
|
|
|
|
The following words exist for arranging values on the floating
|
|
|
|
point stack. These are direct analogs to the non-prefiexd words
|
|
|
|
for dealing with the data stack.
|
|
|
|
<br/><br/>
|
|
|
|
• <span class="tt">f:nip</span><br/>
|
|
|
|
• <span class="tt">f:over</span><br/>
|
|
|
|
• <span class="tt">f:depth</span><br/>
|
|
|
|
• <span class="tt">f:drop</span><br/>
|
|
|
|
• <span class="tt">f:drop-pair</span><br/>
|
|
|
|
• <span class="tt">f:dup</span><br/>
|
|
|
|
• <span class="tt">f:dup-pair</span><br/>
|
|
|
|
• <span class="tt">f:dump-stack</span><br/>
|
|
|
|
• <span class="tt">f:tuck</span><br/>
|
|
|
|
• <span class="tt">f:swap</span><br/>
|
|
|
|
• <span class="tt">f:rot</span><br/>
|
|
|
|
<br/><br/>
|
|
|
|
For the secondary floating point stack, the following words are
|
|
|
|
provided:
|
|
|
|
<br/><br/>
|
|
|
|
• <span class="tt">f:push</span><br/>
|
|
|
|
• <span class="tt">f:pop</span><br/>
|
|
|
|
• <span class="tt">f:adepth</span><br/>
|
|
|
|
• <span class="tt">f:dump-astack</span><br/>
|
|
|
|
<br/><br/>
|
|
|
|
<span class="h2">Constants</span>
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>| Name | Returns |</tt>
|
|
|
|
<tt class='indentedcode'>| -------- | ----------------- |</tt>
|
|
|
|
<tt class='indentedcode'>| `f:E` | Euler's number |</tt>
|
|
|
|
<tt class='indentedcode'>| `f:-INF` | Negative infinity |</tt>
|
|
|
|
<tt class='indentedcode'>| `f:INF` | Positive infinity |</tt>
|
|
|
|
<tt class='indentedcode'>| `f:NAN` | Not a Number |</tt>
|
|
|
|
<tt class='indentedcode'>| `f:PI` | PI |</tt>
|
|
|
|
<br/><br/>
|
|
|
|
<span class="h2">Comparisons</span>
|
|
|
|
<br/><br/>
|
|
|
|
The basic set of comparators are the same as those for
|
|
|
|
operating on integers. These are:
|
|
|
|
<br/><br/>
|
|
|
|
• <span class="tt">f:-eq?</span><br/>
|
|
|
|
• <span class="tt">f:between?</span><br/>
|
|
|
|
• <span class="tt">f:eq?</span><br/>
|
|
|
|
• <span class="tt">f:gt?</span><br/>
|
|
|
|
• <span class="tt">f:lt?</span><br/>
|
|
|
|
• <span class="tt">f:negative?</span><br/>
|
|
|
|
• <span class="tt">f:positive?</span><br/>
|
|
|
|
• <span class="tt">f:case</span><br/>
|
|
|
|
<br/><br/>
|
|
|
|
There are also a few additions for comparing to special values
|
|
|
|
like infinity and NaN.
|
|
|
|
<br/><br/>
|
|
|
|
• <span class="tt">f:-inf?</span><br/>
|
|
|
|
• <span class="tt">f:inf?</span><br/>
|
|
|
|
• <span class="tt">f:nan?</span><br/>
|
|
|
|
<br/><br/>
|
|
|
|
<br/><br/>
|
|
|
|
• <span class="tt">f:*</span><br/>
|
|
|
|
• <span class="tt">f:+</span><br/>
|
|
|
|
• <span class="tt">f:-</span><br/>
|
|
|
|
• <span class="tt">f:/</span><br/>
|
|
|
|
• <span class="tt">f:abs</span><br/>
|
|
|
|
• <span class="tt">f:floor</span><br/>
|
|
|
|
• <span class="tt">f:inc</span><br/>
|
|
|
|
• <span class="tt">f:limit</span><br/>
|
|
|
|
• <span class="tt">f:max</span><br/>
|
|
|
|
• <span class="tt">f:min</span><br/>
|
|
|
|
• <span class="tt">f:negate</span><br/>
|
|
|
|
• <span class="tt">f:power</span><br/>
|
|
|
|
• <span class="tt">f:ceiling</span><br/>
|
|
|
|
• <span class="tt">f:dec</span><br/>
|
|
|
|
• <span class="tt">f:log</span><br/>
|
|
|
|
• <span class="tt">f:sqrt</span><br/>
|
|
|
|
• <span class="tt">f:square</span><br/>
|
|
|
|
• <span class="tt">f:round</span><br/>
|
|
|
|
• <span class="tt">f:sign</span><br/>
|
|
|
|
• <span class="tt">f:signed-sqrt</span><br/>
|
|
|
|
• <span class="tt">f:signed-square</span><br/>
|
|
|
|
<br/><br/>
|
|
|
|
<span class="h2">Geometry</span>
|
|
|
|
<br/><br/>
|
|
|
|
RETRO provides a small number of words for doing geometric
|
|
|
|
related calculations.
|
|
|
|
<br/><br/>
|
|
|
|
| Word | Returns |
|
|
|
|
| -------- | ------------ |
|
|
|
|
| <span class="tt">f:acos</span> | arc cosine |
|
|
|
|
| <span class="tt">f:asin</span> | arc sine |
|
|
|
|
| <span class="tt">f:atan</span> | arc tangent |
|
|
|
|
| <span class="tt">f:cos</span> | cosine |
|
|
|
|
| <span class="tt">f:sin</span> | sine |
|
|
|
|
| <span class="tt">f:tan</span> | tangent |
|
|
|
|
<br/><br/>
|
|
|
|
<br/><br/>
|
|
|
|
By leveraging the encoded value functions, RETRO is able to
|
|
|
|
allow storage of floating point values in memory. This does
|
|
|
|
have a tradeoff in accuracy as the memory cells are considerably
|
|
|
|
smaller than a full floating point size.
|
|
|
|
<br/><br/>
|
|
|
|
You can use <span class="tt">f:fetch</span> to fetch a floating point value and
|
|
|
|
<span class="tt">f:store</span> to store one.
|
|
|
|
<br/><br/>
|
|
|
|
If you need more precision, try Kiyoshi Yoneda's FloatVar
|
|
|
|
example (<span class="tt">example/FloatVar.forth</span>), which includes words to
|
|
|
|
store and retrieve values using multiple cells.
|
|
|
|
<br/><br/>
|
|
|
|
• <span class="tt">f:to-number</span><br/>
|
|
|
|
• <span class="tt">f:to-string</span><br/>
|
|
|
|
<br/><br/>
|
|
|
|
<span class="h2">I/O</span>
|
|
|
|
<br/><br/>
|
|
|
|
The floating point vocabulary has a single I/O word, <span class="tt">f:put</span>,
|
|
|
|
for the display of floating point numbers.
|
|
|
|
<br/><br/>
|
|
|
|
<br/><br/>
|
|
|
|
RETRO provides a means of encoding and decoding floating point
|
|
|
|
values into standard integer cells. This is based on the paper
|
|
|
|
"Encoding floating point values to shorter integers" by Kiyoshi
|
|
|
|
Yoneda and Charles Childers.
|
|
|
|
<br/><br/>
|
|
|
|
• <span class="tt">f:E1</span><br/>
|
|
|
|
• <span class="tt">f:to-e</span><br/>
|
|
|
|
• <span class="tt">e:-INF</span><br/>
|
|
|
|
• <span class="tt">e:-inf?</span><br/>
|
|
|
|
• <span class="tt">e:INF</span><br/>
|
|
|
|
• <span class="tt">e:MAX</span><br/>
|
|
|
|
• <span class="tt">e:MIN</span><br/>
|
|
|
|
• <span class="tt">e:NAN</span><br/>
|
|
|
|
• <span class="tt">e:clip</span><br/>
|
|
|
|
• <span class="tt">e:inf?</span><br/>
|
|
|
|
• <span class="tt">e:max?</span><br/>
|
|
|
|
• <span class="tt">e:min?</span><br/>
|
|
|
|
• <span class="tt">e:n?</span><br/>
|
|
|
|
• <span class="tt">e:nan?</span><br/>
|
|
|
|
• <span class="tt">e:put</span><br/>
|
|
|
|
• <span class="tt">e:to-f</span><br/>
|
|
|
|
• <span class="tt">e:zero?</span><br/>
|
|
|
|
</p>
|
|
|
|
</body></html>
|