on 883cb21 help sign in
6054 lines 77 kB history raw
1+++
2title = "3b: Floating Point"
3weight = 22
4template = "doc.html"
5+++
7## `++fn`
9Float
11A mold for the floating-point arithmetic using the base of two, the formula is
12`(-1)^s * a * 2^e`.
14Produces either a float (`%f`), an infinity of other sign (`%i`),
15or not-a-number (`%n`). `s` refers to sign, the `flag`s `&` or `|`; `e` to
16exponent, a signed decimal; and `a` to the significand, an unsigned integer.
18#### Source
20```hoon
21++ fn
22 $% [%f s=? e=@s a=@u]
23 [%i s=?]
24 [%n ~]
25 ==
26```
28#### Examples
30```
31> *fn
32[%n ~]
34> (add:fl [%f & --33 2] [%f | --23 2])
35[%f s=%.y e=-79 a=10.374.452.512.267.829.421.849.019.032.797.184]
37> (add:fl [%i &] [%i &])
38[%i s=%.y]
40> (add:fl [%n ~] [%i |])
41[%n ~]
43> (sun:fl 961.193.554.848.514.048.973.893.027.381.506.219.443)
44[%f s=%.y e=--17 a=7.333.324.850.834.000.007.430.214.137.126.970]
45```
47---
49## `++dn`
51Decimal float
53A mold for the floating-point arithmetic using the base of 10; the formula is
54`(-1)^s * a *10^e`.
56Valid values are a float (`%d`), an infinity (`%i`), or a not-a-number (`%n`).
57`s` refers to sign, the `flag`s `&` or `|`; `e` to exponent, a signed decimal;
58and `a` to the significand, an unsigned integer.
60```hoon
61++ dn
62 $% [%d s=? e=@s a=@u]
63 [%i s=?]
64 [%n ~]
65 ==
66```
68#### Examples
70```
71> `dn`[%d & --0 17.163.091.968]
72[%d s=%.y e=--0 a=17.163.091.968]
74> `dn`[%i s=%.y]
75[%i s=%.y]
77> `dn`[%n ~]
78[%n ~]
79```
81---
83## `++rn`
85Parsed decimal float
87A mold for the floating-point arithmetic using the base of 10; the formula is
88`(-1)^s * a *10^e`.
90Produces either a parsed float (`%d`), infinity of either sign (`%i`), or
91not-a-number (`%n`).
93#### Source
95```hoon
96++ rn
97 $% [%d a=? b=[c=@ [d=@ e=@] f=? i=@]]
98 [%i a=?]
99 [%n ~]
100 ==
101```
103#### Examples
105```
106> `rn`[%d | [2 [3 4] | 17.163]]
107[%d a=%.n b=[c=2 [d=3 e=4] f=%.n i=17.163]]
108```
110---
112## `++fl`
114Arbitrary-precision floating-point
116Container arm for floating-point arithmetic functions.
118- Precision (`p`): number of bits in the significand; must be at least 2.
119 Default is 113.
120- Minimum exponent (`v`): minimum value of e. Default is -16.494.
121- Width (`w`): Max value of `e` minus min value of `e`. 0 is for fixed-point.
122 Default is 32.765.
123- Rounding mode (`r`): Possible modes are nearest (`%n`), up (`%u`),
124 down (`%d`), to zero (`%z`), and away from zero (`%a`). Default value is `%n`.
125- Behavior (`d`): return denormals (`%d`), flush denormals to zero (`%z`),
126 infinite exponent range (`%i`). Default value is `%d`.
128#### Source
130```hoon
131++ fl
132 =/ [[p=@u v=@s w=@u] r=$?(%n %u %d %z %a) d=$?(%d %f %i)]
133 [[113 -16.494 32.765] %n %d]
134 =>
135 ~% %cofl +> ~
136 |%
137```
139---
141### `^rou:fl`
143Round
145Rounds `a` to a the nearest float that can be represented with a 113-bit
146significand. There is no term to sign the significand, meaning that a positive
147sign will always be produced.
149#### Accepts
151`a` is a cell of a signed integer and an unsigned integer.
153#### Produces
155An `fn`.
157#### Source
159```hoon
160++ rou
161 |= [a=[e=@s a=@u]] ^- fn (rau a &)
162```
164#### Examples
166```
167> =a 10.161.487.211.429.486.882.397.572.894.294.017.777
168> (^rou:fl [--12 a])
169[%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
171> (^rou:fl [--12 (add a 1)])
172[%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
174> (^rou:fl [--12 (add a 300)])
175[%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
177> (^rou:fl [--12 (add a 1.000)])
178[%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.003]
179```
181---
183### `++rau:fl`
185Various roundings
187Rounds `a` based on what the state of of `r` in the core contained in `fl`. `t`
188is a sticky bit that represents a value less than ULP(a) = 2^(e.a) when passed
189to `lug:fl`.
191#### Accepts
193`a` is a cell of a signed integer and an unsigned integer.
195`t` is a `flag`.
197#### Produces
199An `fn`.
201#### Source
203```hoon
204++ rau
205 |= [a=[e=@s a=@u] t=?] ^- fn
206 ?- r
207 %z (lug %fl a t) %d (lug %fl a t)
208 %a (lug %ce a t) %u (lug %ce a t)
209 %n (lug %ne a t)
210 ==
211```
213#### Examples
215```
216> (rau:fl [-18 342.602.577] &)
217[%f s=%.y e=-102 a=6.626.897.619.228.945.634.459.505.846.648.832]
218```
220#### Discussion
222See [`lug:fl`](#lugfl) for possible rounding operations.
224---
226### `^add:fl`
228Add
230Produces the sum of `a` and `b`. `e` is used to choose between an exact result
231(any-sized significand) or a rounded result (113-bit significand).
233There is no term to sign the significands, so a positive sign will always be
234produced.
236#### Accepts
238`a` is an `fn`.
240`b` is an `fn`
242`e` is a `flag`.
244#### Produces
246An `fn`.
248#### Source
250```hoon
251++ add
252 |= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn
253 =+ q=(dif:si e.a e.b)
254 |- ?. (syn:si q) $(b a, a b, q +(q))
255 ?: e
256 [%f & e.b (^add (lsh [0 (abs:si q)] a.a) a.b)]
257 =+ [ma=(met 0 a.a) mb=(met 0 a.b)]
258 =+ ^= w %+ dif:si e.a %- sun:si
259 ?: (gth prc ma) (^sub prc ma) 0
260 =+ ^= x %+ sum:si e.b (sun:si mb)
261 ?: =((cmp:si w x) --1)
262 ?- r
263 %z (lug %fl a &) %d (lug %fl a &)
264 %a (lug %lg a &) %u (lug %lg a &)
265 %n (lug %na a &)
266 ==
267 (rou [e.b (^add (lsh [0 (abs:si q)] a.a) a.b)])
268```
270#### Examples
272```
273> (^add:fl [--33 2.718] [--23 11] %.y)
274[%f s=%.y e=--23 a=2.783.243]
276> (^add:fl [--33 2.718] [--23 11] %.n)
277[%f s=%.y e=-68 a=6.890.975.897.521.519.304.902.126.405.156.864]
278```
280---
282### `^sub:fl`
284Subtract
286Produces the difference of `a` minus `b.` `e` is used to choose between an exact
287result (any-sized significand) or a rounded result (113-bit significand).
289#### Accepts
291`a` is a cell of a signed integer and an unsigned integer.
293`b` is a cell of a signed integer and an unsigned integer.
295`e` is a `flag`.
297#### Produces
299An `fn`.
301#### Source
303```hoon
304++ sub
305 |= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn
306 =+ q=(dif:si e.a e.b)
307 |- ?. (syn:si q)
308 (fli $(b a, a b, q +(q), r swr))
309 =+ [ma=(met 0 a.a) mb=(met 0 a.b)]
310 =+ ^= w %+ dif:si e.a %- sun:si
311 ?: (gth prc ma) (^sub prc ma) 0
312 =+ ^= x %+ sum:si e.b (sun:si +(mb))
313 ?: &(!e =((cmp:si w x) --1))
314 ?- r
315 %z (lug %sm a &) %d (lug %sm a &)
316 %a (lug %ce a &) %u (lug %ce a &)
317 %n (lug %nt a &)
318 ==
319 =+ j=(lsh [0 (abs:si q)] a.a)
320 |- ?. (gte j a.b)
321 (fli $(a.b j, j a.b, r swr))
322 =+ i=(^sub j a.b)
323 ?~ i [%f & zer]
324 ?: e [%f & e.b i] (rou [e.b i])
325```
327#### Examples
329```
330> (^sub:fl [--33 2.718] [--23 11] %.y)
331[%f s=%.y e=--23 a=2.783.221]
333> (^sub:fl [--33 2.718] [--63 11] %.y)
334[%f s=%.n e=--33 a=11.811.157.346]
335```
337---
339### `^mul:fl`
341Multiply
343Produces the product of `a` multiplied by `b`. There is no term to sign the
344significands, so a positive sign will always be produced.
346#### Accepts
348`a` is a cell of a signed integer and an unsigned integer.
350`b` is a cell of a signed integer and an unsigned integer.
352#### Produces
354An `fn`.
356#### Source
358```hoon
359++ mul
360 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- fn
361 (rou (sum:si e.a e.b) (^mul a.a a.b))
362```
364#### Examples
366```
367> (^mul:fl [--3 2.718] [--23 11])
368[%f s=%.y e=-72 a=9.475.054.411.405.900.661.487.108.108.582.912]
369```
371---
373### `^div:fl`
375Divide
377Produces the quotient of `a` divided by `b`. There is no term to sign the
378significands, so a positive sign will always be produced.
380#### Accepts
382`a` is a cell of a signed integer and an unsigned integer.
384`b` is a cell of a signed integer and an unsigned integer.
386#### Produces
388An `fn`.
390#### Source
392```hoon
393++ div
394 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- fn
395 =+ [ma=(met 0 a.a) mb=(met 0 a.b)]
396 =+ v=(dif:si (sun:si ma) (sun:si +((^add mb prc))))
397 =. a ?: (syn:si v) a
398 a(e (sum:si v e.a), a (lsh [0 (abs:si v)] a.a))
399 =+ [j=(dif:si e.a e.b) q=(dvr a.a a.b)]
400 (rau [j p.q] =(q.q 0))
401```
403#### Examples
405```
406> (^div:fl [--13 2.718] [--23 11])
407[%f s=%.y e=-115 a=10.023.198.055.040.952.765.870.659.817.343.907]
408```
410---
412### `^sqt:fl`
414Square root
416Produces the square root of `a`.
418#### Accepts
420`a` is a cell of a signed integer and an unsigned integer.
422#### Produces
424An `fn`.
426#### Source
428```hoon
429++ sqt
430 |= [a=[e=@s a=@u]] ^- fn
431 =. a
432 =+ [w=(met 0 a.a) x=(^mul +(prc) 2)]
433 =+ ?:((^lth w x) (^sub x w) 0)
434 =+ ?: =((dis - 1) (dis (abs:si e.a) 1)) -
435 (^add - 1)
436 a(e (dif:si e.a (sun:si -)), a (lsh [0 -] a.a))
437 =+ [y=(^sqt a.a) z=(fra:si e.a --2)]
438 (rau [z p.y] =(q.y 0))
439```
441#### Examples
443```
444> (^sqt:fl [-18 342.602.577])
445[%f s=%.y e=-107 a=5.865.903.143.604.945.574.132.671.852.050.553]
446```
448---
450### `^lth:fl`
452Less than
454Tests if `a` is less than `b`.
456#### Accepts
458`a` is a cell of a signed integer and an unsigned integer.
460`b` is a cell of a signed integer and an unsigned integer.
462#### Produces
464An `flag`.
466#### Source
468```hoon
469++ lth
470 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ?
471 ?: =(e.a e.b) (^lth a.a a.b)
472 =+ c=(cmp:si (ibl a) (ibl b))
473 ?: =(c -1) & ?: =(c --1) |
474 ?: =((cmp:si e.a e.b) -1)
475 (^lth (rsh [0 (abs:si (dif:si e.a e.b))] a.a) a.b)
476 (^lth (lsh [0 (abs:si (dif:si e.a e.b))] a.a) a.b)
477```
479#### Examples
481```
482> (^lth:fl [-4 684] [--0 35])
483%.n
485> (^lth:fl [-4 684] [--0 90])
486%.y
487```
489---
491### `^equ:fl`
493Equals
495Tests if `a` is equal to `b`.
497#### Accepts
499`a` is a cell of a signed integer and an unsigned integer.
501`b` is a cell of a signed integer and an unsigned integer.
503#### Produces
505A `flag`.
507#### Source
509```hoon
510++ equ
511 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ?
512 ?. =((ibl a) (ibl b)) |
513 ?: =((cmp:si e.a e.b) -1)
514 =((lsh [0 (abs:si (dif:si e.a e.b))] a.b) a.a)
515 =((lsh [0 (abs:si (dif:si e.a e.b))] a.a) a.b)
516```
518#### Examples
520```
521> (^equ:fl [-4 480] [-0 50])
522%.n
524> (^equ:fl [-4 480] [-0 30])
525%.y
526```
528---
530### `++ibl:fl`
532Integer binary logarithm
534Produces the lowest power to which the number 2 must be raised to obtain `a` or
535greater.
537#### Accepts
539`a` is a cell of a signed integer and an unsigned integer.
541#### Produces
543A signed integer.
545#### Source
547```hoon
548++ ibl
549 |= [a=[e=@s a=@u]] ^- @s
550 (sum:si (sun:si (dec (met 0 a.a))) e.a)
551```
553#### Examples
555```
556> (ibl:fl [-18 342.602.577])
557--10
558```
560---
562### `++uni:fl`
564Change representation to odd
566Produces another representation of the floating point `a` where the significand
567is odd. Every floating-point number has a unique representation of this kind. If
568the significand of `a` is already odd, nothing changes.
570#### Accepts
572`a` is a cell of a signed integer and an unsigned integer.
574#### Produces
576A cell of a signed integer and an unsigned integer.
578#### Source
580```hoon
581++ uni
582 |= [a=[e=@s a=@u]]
583 |- ?: =((end 0 a.a) 1) a
584 $(a.a (rsh 0 a.a), e.a (sum:si e.a --1))
585```
587#### Examples
589```
590> (uni:fl [-8 342.602.578])
591[e=-7 a=171.301.289]
593> (uni:fl [-8 342.602.577])
594[e=-8 a=342.602.577]
595```
597---
599### `++xpd:fl`
601Expand
603Produces the fully precise form of `a`, or the denormalized form of `a`.
605#### Accepts
607`a` is a cell of a signed integer and an unsigned integer.
609#### Produces
611A cell of a signed integer and an unsigned integer.
613#### Sources
615```hoon
616++ xpd
617 |= [a=[e=@s a=@u]]
618 =+ ma=(met 0 a.a)
619 ?: (gte ma prc) a
620 =+ ?: =(den %i) (^sub prc ma)
621 =+ ^= q
622 =+ w=(dif:si e.a emn)
623 ?: (syn:si w) (abs:si w) 0
624 (min q (^sub prc ma))
625 a(e (dif:si e.a (sun:si -)), a (lsh [0 -] a.a))
626```
628#### Examples
630```
631> (xpd:fl [--3 12])
632[e=-106 a=7.788.445.287.802.241.442.795.744.493.830.144]
634> (xpd:fl [-8 342.602.577])
635[e=-92 a=6.626.897.619.228.945.634.459.505.846.648.832]
637> (xpd:fl [-92 6.626.897.619.228.945.634.459.505.846.648.832])
638[e=-92 a=6.626.897.619.228.945.634.459.505.846.648.832]
639```
641---
643### `++lug:fl`
645Central rounding mechanism
647Performs various rounding operations on `a`. An operation is chosen based on the
648value selected for `t`. `s` is a sticky bit that represents a value less than
649ULP(a) = 2^(e.a)
651Possible rounding operations:
653- Floor (`%fl`)
654- Ceiling (`%ce`)
655- Smaller (`%sm`)
656- Larger (`%lg`)
657- Nearest (`%ne`) -- Rounds ties away from 0 if the number is even, rounds
658 toward 0 if the number is odd.
660#### Accepts
662`t` is one of the following: `%fl`, `%ce`, `%sm`, `%lg`, `%ne`, `%na`, or `%nt`.
664`a` is a cell of a signed integer and an unsigned integer.
666`s` is a flag.
668#### Produces
670An `fn`.
672#### Source
674```hoon
675++ lug
676 ~/ %lug
677 |= [t=$?(%fl %ce %sm %lg %ne %na %nt) a=[e=@s a=@u] s=?] ^- fn
678 ?< =(a.a 0)
679 =-
680 ?. =(den %f) - :: flush denormals
681 ?. ?=([%f *] -) -
682 ?: =((met 0 ->+>) prc) - [%f & zer]
683 ::
684 =+ m=(met 0 a.a)
685 ?> |(s (gth m prc)) :: require precision
686 =+ ^= q %+ max
687 ?: (gth m prc) (^sub m prc) 0 :: reduce precision
688 %- abs:si ?: =(den %i) --0 :: enforce min. exp
689 ?: =((cmp:si e.a emn) -1) (dif:si emn e.a) --0
690 =^ b a :- (end [0 q] a.a)
691 a(e (sum:si e.a (sun:si q)), a (rsh [0 q] a.a))
692 ::
693 ?~ a.a
694 ?< =(den %i)
695 ?- t
696 %fl [%f & zer]
697 %sm [%f & zer]
698 %ce [%f & spd]
699 %lg [%f & spd]
700 %ne ?: s [%f & ?:((lte b (bex (dec q))) zer spd)]
701 [%f & ?:((^lth b (bex (dec q))) zer spd)]
702 %nt ?: s [%f & ?:((lte b (bex (dec q))) zer spd)]
703 [%f & ?:((^lth b (bex (dec q))) zer spd)]
704 %na [%f & ?:((^lth b (bex (dec q))) zer spd)]
705 ==
706 ::
707 =. a (xpd a)
708 ::
709 =. a
710 ?- t
711 %fl a
712 %lg a(a +(a.a))
713 %sm ?. &(=(b 0) s) a
714 ?: &(=(e.a emn) !=(den %i)) a(a (dec a.a))
715 =+ y=(dec (^mul a.a 2))
716 ?. (lte (met 0 y) prc) a(a (dec a.a))
717 [(dif:si e.a --1) y]
718 %ce ?: &(=(b 0) s) a a(a +(a.a))
719 %ne ?~ b a
720 =+ y=(bex (dec q))
721 ?: &(=(b y) s) :: round halfs to even
722 ?~ (dis a.a 1) a a(a +(a.a))
723 ?: (^lth b y) a a(a +(a.a))
724 %na ?~ b a
725 =+ y=(bex (dec q))
726 ?: (^lth b y) a a(a +(a.a))
727 %nt ?~ b a
728 =+ y=(bex (dec q))
729 ?: =(b y) ?: s a a(a +(a.a))
730 ?: (^lth b y) a a(a +(a.a))
731 ==
732 ::
733 =. a ?. =((met 0 a.a) +(prc)) a
734 a(a (rsh 0 a.a), e (sum:si e.a --1))
735 ?~ a.a [%f & zer]
736 ::
737 ?: =(den %i) [%f & a]
738 ?: =((cmp:si emx e.a) -1) [%i &] [%f & a] :: enforce max. exp
739```
741---
743### `^drg:fl`
745Get printable decimal
747Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
748accurate results for rounded floats.
750#### Accepts
752`a` is a cell of a signed integer and an unsigned integer.
754#### Produces
756A cell of a signed integer and an unsigned integer.
758#### Source
760```hoon
761++ drg :: dragon4; get
762 ~/ %drg :: printable decimal;
763 |= [a=[e=@s a=@u]] ^- [@s @u] :: guaranteed accurate
764 ?< =(a.a 0) :: for rounded floats
765 =. a (xpd a)
766 =+ r=(lsh [0 ?:((syn:si e.a) (abs:si e.a) 0)] a.a)
767 =+ s=(lsh [0 ?.((syn:si e.a) (abs:si e.a) 0)] 1)
768 =+ mn=(lsh [0 ?:((syn:si e.a) (abs:si e.a) 0)] 1)
769 =+ mp=mn
770 => ?.
771 ?& =(a.a (bex (dec prc))) :: if next smallest
772 |(!=(e.a emn) =(den %i)) :: float is half ULP,
773 == :: tighten lower bound
774 .
775 %= .
776 mp (lsh 0 mp)
777 r (lsh 0 r)
778 s (lsh 0 s)
779 ==
780 =+ [k=--0 q=(^div (^add s 9) 10)]
781 |- ?: (^lth r q)
782 %= $
783 k (dif:si k --1)
784 r (^mul r 10)
785 mn (^mul mn 10)
786 mp (^mul mp 10)
787 ==
788 |- ?: (gte (^add (^mul r 2) mp) (^mul s 2))
789 $(s (^mul s 10), k (sum:si k --1))
790 =+ [u=0 o=0]
791 |- :: r/s+o = a*10^-k
792 =+ v=(dvr (^mul r 10) s)
793 => %= .
794 k (dif:si k --1)
795 u p.v
796 r q.v
797 mn (^mul mn 10)
798 mp (^mul mp 10)
799 ==
800 =+ l=(^lth (^mul r 2) mn) :: in lower bound
801 =+ ^= h :: in upper bound
802 ?| (^lth (^mul s 2) mp)
803 (gth (^mul r 2) (^sub (^mul s 2) mp))
804 ==
805 ?: &(!l !h)
806 $(o (^add (^mul o 10) u))
807 =+ q=&(h |(!l (gth (^mul r 2) s)))
808 =. o (^add (^mul o 10) ?:(q +(u) u))
809 [k o]
810```
812#### Examples
814```
815> (sun:fl 218.116)
816[%f s=%.y e=-95 a=8.640.464.947.480.640.129.276.716.135.743.488]
817> (^drg:fl [e=-95 a=8.640.464.947.480.640.129.276.716.135.743.488])
818[--0 218.116]
820> (sun:fl 102.057.673.128.349)
821[%f s=%.y e=-66 a=7.530.527.107.827.833.883.675.587.233.447.936]
822> (^drg:fl [e=-66 a=7.530.527.107.827.833.883.675.587.233.447.936])
823[--0 102.057.673.128.349]
824```
826---
828### `^toj:fl`
830Round to integer
832Rounds float `a` to the nearest decimal float with an exponent of 0.
834#### Accepts
836`a` is a cell of a signed integer and an unsigned integer.
838#### Produces
840An `fn`.
842#### Source
844```hoon
845++ toj
846 |= [a=[e=@s a=@u]] ^- fn
847 ?. =((cmp:si e.a --0) -1) [%f & a]
848 =+ x=(abs:si e.a)
849 =+ y=(rsh [0 x] a.a)
850 ?: |(=(r %d) =(r %z)) [%f & --0 y]
851 =+ z=(end [0 x] a.a)
852 ?: |(=(r %u) =(r %a)) [%f & --0 ?~(z y +(y))]
853 =+ i=(bex (dec x))
854 ?: &(=(z i) =((dis y 1) 0)) [%f & --0 y]
855 ?: (^lth z i) [%f & --0 y] [%f & --0 +(y)]
856```
858#### Examples
860```
861> (^toj:fl [-11 7.530.107.827.833.587])
862[%f s=%.y e=--0 a=3.676.810.462.809]
864> (^toj:fl [-11 7.530.107.827.833.589])
865[%f s=%.y e=--0 a=3.676.810.462.809]
866```
868---
870### `++ned:fl`
872Require float
874Produces `a` if `a` is a is of floating-point representation. If `a` is another
875case of `fn`, such as infinity or not-a-number, a crash is produced.
877#### Accepts
879`a` is an `fn`.
881#### Produces
883A cell of a signed integer and an unsigned integer.
885#### Source
887```hoon
888++ ned
889 |= [a=fn] ^- [%f s=? e=@s a=@u]
890 ?: ?=([%f *] a) a
891 ~_ leaf+"need-float"
892 !!
893```
895#### Examples
897```
898> (ned:fl [%f s=%.y e=-11 a=7.530.107.827.833.587])
899[%f s=%.y e=-11 a=7.530.107.827.833.587]
901> (ned:fl [%n ~])
902! need-float
903! exit
905> (ned:fl [%i |])
906! need-float
907! exit
908```
910---
912### `++shf:fl`
914Shift power
916Multiplies `a` by 2 to the `b` power without rounding. This results in shifting
917the exponent term by `b`.
919#### Accepts
921`a` is an `fn`.
923`b` is a signed integer.
925#### Produces
927An `fn`.
929#### Source
931```hoon
932++ shf
933 |= [a=fn b=@s]
934 ?: |(?=([%n *] a) ?=([%i *] a)) a
935 a(e (sum:si e.a b))
936```
938#### Examples
940```
941> (shf:fl [[%f & -2 7] --2])
942[%f s=%.y e=--0 a=7]
944> (shf:fl [[%f & -2 7] -2])
945[%f s=%.y e=-4 a=7]
947> (shf:fl [%f & -11 7.530.107.827.833.587] --5)
948[%f s=%.y e=-6 a=7.530.107.827.833.587]
949```
951---
953### `++fli:fl`
955Flip sign
957Produces `a` with its signed changed from positive to negative, or vice versa.
959#### Accepts
961`a` is an `fn`.
963#### Produces
965An `fn`.
967#### Source
969```hoon
970++ fli
971 |= [a=fn] ^- fn
972 ?-(-.a %f a(s !s.a), %i a(s !s.a), %n a)
973```
975#### Examples
977```
978> (fli:fl [%f %.y -2 7])
979[%f s=%.n e=-2 a=7]
981> (fli:fl [%f %.n --2 30.617])
982[%f s=%.y e=--2 a=30.617]
984> (fli:fl [%f | --2 30.617])
985[%f s=%.y e=--2 a=30.617]
986```
988---
990### `++swr:fl`
992Switch rounding
994Switches the rounding mode of `r:fl`.
996#### Source
998```hoon
999++ swr ?+(r r %d %u, %u %d)
1000```
1002#### Examples
1004```
1005> r:fl
1007> swr:fl
1010> =new-fl fl :: new fl core with changed state
1011> =new-fl new-fl(r %u)
1012> swr:new-fl
1014```
1016---
1018### `++prc:fl`
1020Force precision of 2 or greater
1022Produces `p`, the core's precision, if `p` is greater than or equal to 2.
1023Otherwise, a crash is produced.
1025#### Source
1027```hoon
1028++ prc ?>((gth p 1) p)
1029```
1031#### Examples
1033```
1034> prc:fl
1035113
1037> =new-fl fl
1038> =new-fl new-fl(p 1)
1039> prc:new-fl
1040! exit
1042> =new-fl new-fl(p 2)
1043> prc:new-fl
1045```
1047---
1049### `++den:fl`
1051Behavior
1053Produces `d:fl`. Denormalizes if `d:fl` is `%d`. Flushes denormals to zero if
1054`d:fl` is `%f`.
1056- Denormalizes if `d:fl` is `%d`.
1057- Flushes denormals to zero if `d:fl` is `%f`.
1058- Infinite exponent range if `%d` is `%i`.
1060The default value of `d` is `%d`.
1062#### Source
1064```hoon
1065++ den d
1066```
1068#### Examples
1070```
1071> den:fl
1074> =new-fl fl
1075> =new-fl new-fl(d %f)
1076> den:new-fl
1078```
1080---
1082### `++emn:fl`
1084Minimum exponent
1086Produces `v:fl`, the minimum exponent. The default minimum exponent is -16.494.
1088#### Source
1090```hoon
1091++ emn v
1092```
1094#### Examples
1096```
1097> emn:fl
1098-16.494
1099```
1101---
1103### `++emx:fl`
1105Maximum exponent
1107Returns the maximum exponent of `fl`. The default maximum exponent is --16.271.
1109#### Source
1111```hoon
1112++ emx (sum:si emn (sun:si w))
1113```
1115#### Examples
1117```
1118> emx:fl
1119--16.271
1121> `@u`emx:fl
112232.542
1123```
1125---
1127### `++spd:fl`
1129Smallest denormal
1131Produces the smallest possible denormalized float.
1133#### Source
1135```hoon
1136++ spd [e=emn a=1]
1137```
1139#### Examples
1141```
1142> spd:fl
1143[e=-16.494 a=1]
1144```
1146---
1148### `++spn:fl`
1150Smallest normal
1152Produces the smallest representable normal float.
1154#### Source
1156```hoon
1157++ spn [e=emn a=(bex (dec prc))]
1158```
1160#### Examples
1162```
1163> spn:fl
1164[e=-16.494 a=5.192.296.858.534.827.628.530.496.329.220.096]
1165```
1167---
1169### `++lfn:fl`
1171Largest normal
1173Produces the largest representable normal float.
1175#### Source
1177```hoon
1178++ lfn [e=emx a=(fil 0 prc 1)]
1179```
1181#### Examples
1183```
1184> lfn:fl
1185[e=--16.271 a=10.384.593.717.069.655.257.060.992.658.440.191]
1186```
1188---
1190### `++lfe:fl`
1192Maximum
1194Produces the sum of `emx:fl` plus `prc:fl`.
1196#### Source
1198```hoon
1199++ lfe (sum:si emx (sun:si prc))
1200```
1202#### Examples
1204```
1205> lfe:fl
1206--16.384
1207```
1209---
1211### `++zer:fl`
1213Zero
1215Produces zero represented as a float.
1217#### Source
1219```hoon
1220++ zer [e=--0 a=0]
1221```
1223#### Examples
1225```
1226> zer:fl
1227[e=--0 a=0]
1228```
1230---
1232### `++rou:fl`
1234Round
1236Rounds `a`. The way in which `a` is rounded depends on the value of `r:fl`.
1238#### Accepts
1240`a` is an `fn`.
1242#### Produes
1244An `fn`.
1246#### Source
1248```hoon
1249++ rou
1250 |= [a=fn] ^- fn
1251 ?. ?=([%f *] a) a
1252 ?~ a.a [%f s.a zer]
1253 ?: s.a (^rou +>.a)
1254 =.(r swr (fli (^rou +>.a)))
1255```
1257#### Examples
1259```
1260> =a 10.161.487.211.429.486.882.397.572.894.294.017.777
1261> (rou:fl [%f & --12 a])
1262[%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
1264> (rou:fl [%f & --12 (add a 1)])
1265[%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
1267> (rou:fl [%f & --12 (add a 300)])
1268[%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
1270> (rou:fl [%f & --12 (add a 1.000)])
1271[%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.003]
1272```
1274---
1276### `++syn:fl`
1278Get sign
1280Produces the sign of `a`.
1282#### Accepts
1284`a` is an `fn`.
1286#### Produes
1288An `fn`.
1290#### Source
1292```hoon
1293++ syn
1294 |= [a=fn] ^- ?
1295 ?-(-.a %f s.a, %i s.a, %n &)
1296```
1298#### Examples
1300```
1301> (syn:fl (sun:fl 106))
1302%.y
1304> (syn:fl [%f | --0 106])
1305%.n
1306```
1308---
1310### `++abs:fl`
1312Absolute value
1314Produces the absolute value of `a`.
1316#### Accepts
1318`a` is an `fn`.
1320#### Produes
1322An `fn`.
1324#### Sources
1326```hoon
1327++ abs
1328 |= [a=fn] ^- fn
1329 ?: ?=([%f *] a) [%f & e.a a.a]
1330 ?: ?=([%i *] a) [%i &] [%n ~]
1331```
1333#### Examples
1335```
1336> (abs:fl [%f | --0 106])
1337[%f s=%.y e=--0 a=106]
1339> (abs:fl [%f & --0 106])
1340[%f s=%.y e=--0 a=106]
1341```
1343---
1345### `++add:fl`
1347Add
1349Produces the sum of `a` plus `b`.
1351#### Accepts
1353`a` is an `fn`.
1355`b` is an `fn`.
1357#### Produces
1359An `fn`.
1361#### Source
1363```hoon
1364++ add
1365 |= [a=fn b=fn] ^- fn
1366 ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
1367 ?: |(?=([%i *] a) ?=([%i *] b))
1368 ?: &(?=([%i *] a) ?=([%i *] b))
1369 ?: =(a b) a [%n ~]
1370 ?: ?=([%i *] a) a b
1371 ?: |(=(a.a 0) =(a.b 0))
1372 ?. &(=(a.a 0) =(a.b 0)) %- rou ?~(a.a b a)
1373 [%f ?:(=(r %d) &(s.a s.b) |(s.a s.b)) zer]
1374 %- |= [a=fn]
1375 ?. ?=([%f *] a) a
1376 ?. =(a.a 0) a
1377 [%f !=(r %d) zer]
1378 ?: =(s.a s.b)
1379 ?: s.a (^add +>.a +>.b |)
1380 =.(r swr (fli (^add +>.a +>.b |)))
1381 ?: s.a (^sub +>.a +>.b |)
1382 (^sub +>.b +>.a |)
1383```
1385#### Examples
1387```
1388> (add:fl [%f & --0 106] [%f | --3 55])
1389[%f s=%.n e=-104 a=6.774.324.807.619.657.921.598.381.929.529.344]
1390```
1392---
1394### `++ead:fl`
1396Exact add
1398Produces the exact sum of `a` plus `b`.
1400#### Accepts
1402`a` is an `fn`.
1404`b` is an `fn`.
1406#### Produces
1408An `fn`.
1410#### Source
1412```hoon
1413++ ead
1414 |= [a=fn b=fn] ^- fn
1415 ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
1416 ?: |(?=([%i *] a) ?=([%i *] b))
1417 ?: &(?=([%i *] a) ?=([%i *] b))
1418 ?: =(a b) a [%n ~]
1419 ?: ?=([%i *] a) a b
1420 ?: |(=(a.a 0) =(a.b 0))
1421 ?. &(=(a.a 0) =(a.b 0)) ?~(a.a b a)
1422 [%f ?:(=(r %d) &(s.a s.b) |(s.a s.b)) zer]
1423 %- |= [a=fn]
1424 ?. ?=([%f *] a) a
1425 ?. =(a.a 0) a
1426 [%f !=(r %d) zer]
1427 ?: =(s.a s.b)
1428 ?: s.a (^add +>.a +>.b &)
1429 (fli (^add +>.a +>.b &))
1430 ?: s.a (^sub +>.a +>.b &)
1431 (^sub +>.b +>.a &)
1432```
1434#### Examples
1436```
1437> (ead:fl [%f & --0 106] [%f | --3 55])
1438[%f s=%.n e=--0 a=334]
1439```
1441---
1443### `++sub:fl`
1445Subtract
1447Produces the difference of `a` minus `b`.
1449#### Accepts
1451`a` is an `fn`.
1453`b` is an `fn`.
1455#### Produces
1457An `fn`.
1459#### Source
1461```hoon
1462++ sub
1463 |= [a=fn b=fn] ^- fn (add a (fli b))
1464```
1466#### Examples
1468```
1469> (sub:fl [%f & --13 2.718] [%f & --23 11])
1470[%f s=%.n e=-86 a=5.416.671.014.775.224.232.595.412.796.571.648]
1471```
1473---
1475### `++mul:fl`
1477Multiply
1479Produces the product of `a` multiplied by `b`.
1481#### Accepts
1483`a` is an `fn`.
1485`b` is an `fn`.
1487#### Produces
1489An `fn`.
1491#### Source
1493```hoon
1494++ mul
1495 |= [a=fn b=fn] ^- fn
1496 ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
1497 ?: ?=([%i *] a)
1498 ?: ?=([%i *] b)
1499 [%i =(s.a s.b)]
1500 ?: =(a.b 0) [%n ~] [%i =(s.a s.b)]
1501 ?: ?=([%i *] b)
1502 ?: =(a.a 0) [%n ~] [%i =(s.a s.b)]
1503 ?: |(=(a.a 0) =(a.b 0)) [%f =(s.a s.b) zer]
1504 ?: =(s.a s.b) (^mul +>.a +>.b)
1505 =.(r swr (fli (^mul +>.a +>.b)))
1506```
1508---
1510### `++emu:fl`
1512Exact multiply
1514Produces the exact product of `a` multiplied by `b`.
1516#### Accepts
1518`a` is an `fn`.
1520`b` is an `fn`.
1522#### Produces
1524An `fn`.
1526#### Examples
1528```hoon
1529++ emu
1530 |= [a=fn b=fn] ^- fn
1531 ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
1532 ?: ?=([%i *] a)
1533 ?: ?=([%i *] b)
1534 [%i =(s.a s.b)]
1535 ?: =(a.b 0) [%n ~] [%i =(s.a s.b)]
1536 ?: ?=([%i *] b)
1537 ?: =(a.a 0) [%n ~] [%i =(s.a s.b)]
1538 ?: |(=(a.a 0) =(a.b 0)) [%f =(s.a s.b) zer]
1539 [%f =(s.a s.b) (sum:si e.a e.b) (^^mul a.a a.b)]
1540```
1542---
1544### `++div:fl`
1546Divide
1548Produces the quotient of `a` divided by `b`.
1550#### Accepts
1552`a` is an `fn`.
1554`b` is an `fn`.
1556#### Produces
1558An `fn`.
1560#### Source
1562```hoon
1563++ div
1564 |= [a=fn b=fn] ^- fn
1565 ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
1566 ?: ?=([%i *] a)
1567 ?: ?=([%i *] b) [%n ~] [%i =(s.a s.b)]
1568 ?: ?=([%i *] b) [%f =(s.a s.b) zer]
1569 ?: =(a.a 0) ?: =(a.b 0) [%n ~] [%f =(s.a s.b) zer]
1570 ?: =(a.b 0) [%i =(s.a s.b)]
1571 ?: =(s.a s.b) (^div +>.a +>.b)
1572 =.(r swr (fli (^div +>.a +>.b)))
1573```
1575---
1577### `++fma:fl`
1579Fused multiply-add
1581Produces the sum of `c` plus the product of `a` multiplied by `b`;
1582`(a * b) + c`.
1584#### Accepts
1586`a` is an `fn`.
1588`b` is an `fn`.
1590`c` is an `fn`.
1592#### Produces
1594An `fn`.
1596#### Source
1598```hoon
1599++ fma
1600 |= [a=fn b=fn c=fn] ^- fn
1601 (add (emu a b) c)
1602```
1604#### Examples
1606```
1607> (fma:fl [%f & --13 2.718] [%f & --23 11] [%f & --13 2.718])
1608[%f s=%.y e=-62 a=9.475.054.514.089.037.465.004.673.635.188.736]=
1609```
1611---
1613### `++sqt:fl`
1615Square root
1617Produces the square root of `a`.
1619#### Accepts
1621`a` is an `fn`.
1623#### Produces
1625An `fn`.
1627#### Source
1629```hoon
1630++ sqt
1631 |= [a=fn] ^- fn
1632 ?: ?=([%n *] a) [%n ~]
1633 ?: ?=([%i *] a) ?:(s.a a [%n ~])
1634 ?~ a.a [%f s.a zer]
1635 ?: s.a (^sqt +>.a) [%n ~]
1636```
1638#### Examples
1640```
1641> (sqt:fl [%f s=%.y e=-18 a=342.602.577])
1642[%f s=%.y e=-107 a=5.865.903.143.604.945.574.132.671.852.050.553]
1643```
1645---
1647### `++inv:fl`
1649Inverse
1651Produces the inverse of `a` by dividing `1` by `a`.
1653#### Accepts
1655`a` is an `fn`.
1657#### Produces
1659An `fn`.
1661#### Source
1663```hoon
1664++ inv
1665 |= [a=fn] ^- fn
1666 (div [%f & --0 1] a)
1667```
1669#### Examples
1671```
1672> (inv:fl [%f s=%.y e=--0 a=10])
1673[%f s=%.y e=-116 a=8.307.674.973.655.724.205.648.794.126.752.154]
1674> (drg:fl [%f s=%.y e=-116 a=8.307.674.973.655.724.205.648.794.126.752.154])
1675[%d s=%.y e=-1 a=1]
1677> (inv:fl [%f s=%.y e=--1 a=10])
1678[%f s=%.y e=-117 a=8.307.674.973.655.724.205.648.794.126.752.154]
1679> (drg:fl [%f s=%.y e=-117 a=8.307.674.973.655.724.205.648.794.126.752.154])
1680[%d s=%.y e=-2 a=5]
1682> (inv:fl [%f s=%.y e=--2 a=10])
1683[%f s=%.y e=-118 a=8.307.674.973.655.724.205.648.794.126.752.154]
1684> (drg:fl [%f s=%.y e=-118 a=8.307.674.973.655.724.205.648.794.126.752.154])
1685[%d s=%.y e=-3 a=25]
1686```
1688---
1690### `++sun:fl`
1692Signed integer to float
1694Produces `a` in floating-point representation.
1696#### Accepts
1698`a` is an unsigned integer.
1700#### Produces
1702An `fn`.
1704#### Source
1706```hoon
1707++ sun
1708 |= [a=@u] ^- fn
1709 (rou [%f & --0 a])
1710```
1712#### Examples
1714```
1715> (sun:fl 0)
1716[%f s=%.y e=--0 a=0]
1718> (sun:fl 5.048.729)
1719[%f s=%.y e=-90 a=6.250.023.776.601.238.669.911.180.544.311.296]
1721> (sun:fl -100)
1722! exit
1723```
1725---
1727### `++san:fl`
1729Signed integer to float
1731Produces the floating-point representation of `a`, an unsigned integer.
1733#### Accepts
1735`a` is an unsigned integer.
1737#### Produces
1739An `fn`.
1741#### Source
1743```hoon
1744++ san
1745 |= [a=@s] ^- fn
1746 =+ b=(old:si a)
1747 (rou [%f -.b --0 +.b])
1748```
1750#### Examples
1752```
1753> (san:fl --100)
1754[%f s=%.y e=-106 a=8.112.963.841.460.668.169.578.900.514.406.400]
1756> (san:fl -100)
1757[%f s=%.n e=-106 a=8.112.963.841.460.668.169.578.900.514.406.400]
1758```
1760---
1762### `++lth:fl`
1764Less than
1766Tests if `a` is less than `b`. Returns `~` in the event of `a` or `b` being a
1767NaN (`[%n ~]`).
1769#### Accepts
1771`a` is an `fn`.
1773`b` is an `fn`.
1775#### Produces
1777A `unit` of `flag`.
1779#### Source
1781```hoon
1782++ lth
1783 |= [a=fn b=fn] ^- (unit ?)
1784 ?: |(?=([%n *] a) ?=([%n *] b)) ~ :- ~
1785 ?: =(a b) |
1786 ?: ?=([%i *] a) !s.a ?: ?=([%i *] b) s.b
1787 ?: |(=(a.a 0) =(a.b 0))
1788 ?: &(=(a.a 0) =(a.b 0)) |
1789 ?: =(a.a 0) s.b !s.a
1790 ?: !=(s.a s.b) s.b
1791 ?: s.a (^lth +>.a +>.b) (^lth +>.b +>.a)
1792```
1794#### Examples
1796```
1797> (lth:fl (sun:fl 116) (sun:fl 4.820))
1798[~ u=%.y]
1800> (lth:fl (sun:fl 218.116) (sun:fl 4.820))
1801[~ u=%.n]
1803> (lth:fl (sun:fl 218.116) [%n ~])
1805```
1807---
1809### `++lte:fl`
1811Less than or equal
1813Tests whether `a` is less than or equal to `b`. Returns `~` in the event of `a`
1814or `b` being a NaN (`[%n ~]`).
1816#### Accepts
1818`a` is an `fn`.
1820`b` is an `fn`.
1822#### Produces
1824A `unit` of `flag`.
1826#### Source
1828```hoon
1829++ lte
1830 |= [a=fn b=fn] ^- (unit ?)
1831 %+ bind (lth b a) |= a=? !a
1832```
1834#### Examples
1836```
1837> (lte:fl (sun:fl 102) [%f %.y -5 973.655.724])
1838[~ u=%.y]
1840> (lte:fl (sun:fl 102) [%f %.y -24 973.655.724])
1841[~ u=%.n]
1843> (lte:fl [%f %.y --2 25] (sun:fl 100))
1844[~ u=%.y]
1846> (lte:fl [%f %.y --2 25] [%f %.y --3 2])
1847[~ u=%.n]
1849> (lte:fl [%f %.y --2 25] [%n ~])
1851```
1853---
1855### `++equ:fl`
1857Equals
1859Tests if `a` is equal to `b`. Returns `~` in the event of `a` or `b` being a NaN
1860(`[%n ~]`).
1862#### Accepts
1864`a` is an `fn`.
1866`b` is an `fn`.
1868#### Produces
1870An `unit` of `flag`.
1872#### Source
1874```hoon
1875++ equ
1876 |= [a=fn b=fn] ^- (unit ?)
1877 ?: |(?=([%n *] a) ?=([%n *] b)) ~ :- ~
1878 ?: =(a b) &
1879 ?: |(?=([%i *] a) ?=([%i *] b)) |
1880 ?: |(=(a.a 0) =(a.b 0))
1881 ?: &(=(a.a 0) =(a.b 0)) & |
1882 ?: |(=(e.a e.b) !=(s.a s.b)) |
1883 (^equ +>.a +>.b)
1884```
1886#### Examples
1888```
1889> (equ:fl [%f %.y --2 25] (sun:fl 100))
1890[~ u=%.y]
1892> (equ:fl [%f %.y --2 25] (sun:fl 101))
1893[~ u=%.n]
1894```
1896---
1898### `++gte:fl`
1900Greater or equal than
1902Tests whether `a` is greater than or equal to `b`. Returns `~` in the event of
1903`a` or `b` being a NaN (`[%n ~]`).
1905#### Accepts
1907`a` is an `fn`.
1909`b` is an `fn`.
1911#### Produces
1913An `unit` of `flag`.
1915#### Source
1917```hoon
1918++ gte
1919 |= [a=fn b=fn] ^- (unit ?) (lte b a)
1920```
1922#### Examples
1924```
1925> (gte:fl [%f %.y --2 25] (sun:fl 100))
1926[~ u=%.y]
1928> (gth:fl [%f %.y --6 73.989] [%f %.y --5 919.599])
1929[~ u=%.n]
1931> (gth:fl [%f %.y --6 73.989] [%n ~])
1933```
1935---
1937### `++gth:fl`
1939Greater than
1941Tests whether `a` is greater than `b`. Returns `~` in the event of `a` or `b`
1942being a NaN (`[%n ~]`).
1944#### Accepts
1946`a` is an `fn`.
1948`b` is an `fn`.
1950#### Produces
1952An `unit` of `flag`.
1954#### Source
1956```hoon
1957++ gth
1958 |= [a=fn b=fn] ^- (unit ?) (lth b a)
1959```
1961#### Examples
1963```
1964> (gth:fl [%f %.y --2 25] (sun:fl 100))
1965[~ u=%.n]
1967> (gth:fl [%f %.y --6 73.989] [%f %.y --5 119.599])
1968[~ u=%.y]
1969```
1971---
1973### `++drg:fl`
1975Float to decimal
1977Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
1978accurate results for rounded floats.
1980#### Accepts
1982`a` is an `fn`.
1984#### Produces
1986A `dn`.
1988#### Source
1990```hoon
1991++ drg
1992 |= [a=fn] ^- dn
1993 ?: ?=([%n *] a) [%n ~]
1994 ?: ?=([%i *] a) [%i s.a]
1995 ?~ a.a [%d s.a --0 0]
1996 [%d s.a (^drg +>.a)]
1997```
1999#### Examples
2001```
2002> (drg:fl [%f | --6 73.989])
2003[%d s=%.n e=--0 a=4.735.296]
2004```
2006---
2008### `++grd:fl`
2010Decimal to float
2012Converts decimal `a` to `fn`.
2014#### Accepts
2016`a` is a `dn`.
2018#### Produces
2020An `fn`.
2022#### Source
2024```hoon
2025++ grd
2026 |= [a=dn] ^- fn
2027 ?: ?=([%n *] a) [%n ~]
2028 ?: ?=([%i *] a) [%i s.a]
2029 => .(r %n)
2030 =+ q=(abs:si e.a)
2031 ?: (syn:si e.a)
2032 (mul [%f s.a --0 a.a] [%f & e.a (pow 5 q)])
2033 (div [%f s.a --0 a.a] [%f & (sun:si q) (pow 5 q)])
2034```
2036#### Examples
2038```
2039> (grd:fl [%d s=%.n e=--0 a=73.989])
2040[%f s=%.n e=-96 a=5.862.012.516.267.904.074.208.723.341.410.304]
2042> (grd:fl [%d s=%.n e=--0 a=100])
2043[%f s=%.n e=-106 a=8.112.963.841.460.668.169.578.900.514.406.400]
2044```
2046---
2048### `++toi:fl`
2050Round to signed integer
2052Rounds `a` to the nearest signed integer.
2054#### Accepts
2056`a` is an `fn`.
2058#### Produces
2060A `unit` of `@s`.
2062#### Source
2064```hoon
2065++ toi
2066 |= [a=fn] ^- (unit @s)
2067 =+ b=(toj a)
2068 ?. ?=([%f *] b) ~ :- ~
2069 =+ c=(^^mul (bex (abs:si e.b)) a.b)
2070 (new:si s.b c)
2071```
2073#### Examples
2075```
2076> (toi:fl [%f s=%.y e=-78 a=8.112.963.841.460.668.169.578.900.514.406.400])
2077[~ u=--26.843.545.600]
2078```
2080---
2082### `++toj:fl`
2084Round to integer fn
2086Rounds `a` to the nearest decimal integer.
2088#### Accepts
2090`a` is an `fn`.
2092#### Produces
2094A `unit` of `@s`.
2096#### Source
2098```hoon
2099++ toj
2100 |= [a=fn] ^- fn
2101 ?. ?=([%f *] a) a
2102 ?~ a.a [%f s.a zer]
2103 ?: s.a (^toj +>.a)
2104 =.(r swr (fli (^toj +>.a)))
2105```
2107#### Examples
2109```
2110> (toj:fl [%f s=%.y e=-78 a=8.112.963.841.460.668.169.578.900.514.406.400])
2111[%f s=%.y e=--0 a=26.843.545.600]
2113> (toj:fl [%f s=%.y e=-78 a=8.112.963.841.460.668.169.578.900.514])
2114[%f s=%.y e=--0 a=26.844]
2116> (toj:fl [%f s=%.y e=-78 a=8.112.963.841.460])
2117[%f s=%.y e=--0 a=0]
2119> (toj:fl [%f s=%.y e=-9 a=9.002])
2120[%f s=%.y e=--0 a=16]
2121```
2123---
2125## `++ff`
2127IEEE-754 Formatting
2129Container core for IEEE-754 formatting operations.
2131- `w` is width: The number of bits in the exponent field.
2132- `p` is precision: The number of bits in the significand field.
2133- `w` is bias: Added to exponent when storing.
2134- `r` is rounding mode: Possible modes are nearest (`%n`), up (`%u`),
2135 down (`%d`), to zero (`%z`), and away from zero (`%a`). Default value is `%a`.
2137#### Source
2139```hoon
2140++ ff
2141 |_ [[w=@u p=@u b=@s] r=$?(%n %u %d %z %a)]
2142```
2144#### Examples
2146```
2147> =ffcore ~(. ff [8 8 0] %n)
2148> ffcore
2149<24.ltg {{{@ud @ud @ud} r/$n} <54.tyv 119.wim 31.ohr 1.jmk $143>}>
2150```
2152---
2154#### Discussion
2156`++ff` has no use outside of the functionality provided to other cores: `++rd`,
2157`++rs`, `++rq`, and `++rh`. It's not intended to be used directly; it's just
2158meant to power those cores.
2160---
2162### `++sb:ff`
2164Sign bit
2166Produces the sign bit of `++ff`.
2168#### Source
2170```hoon
2171++ sb (bex (^add w p))
2172```
2174#### Examples
2176```
2177> sb:ff
2179```
2181---
2183### `++me:ff`
2185Minimum exponent
2187Produces the minimum possible exponent of `ff`.
2189#### Source
2191```hoon
2192++ me (dif:si (dif:si --1 b) (sun:si p))
2193```
2195#### Examples
2197```
2198> me:ff
2199--1
2200```
2202---
2204### `++pa:ff`
2206Initialize `fl`
2208Instantiates the core `fl`, giving values to its samples based on the
2209configuration of the `ff` core.
2211#### Source
2213```hoon
2214++ pa
2215 %*(. fl p +(p), v me, w (^sub (bex w) 3), d %d, r r)
2216```
2218#### Examples
2220```
2221> ~(pa ff [11 52 --1.023] %n)
2222< 23.qzd
2223 28.btz
2224 { {{p/@ v/@s w/@} r/?($n $u $a $d $z) d/$d}
2225 <54.tyv 119.wim 31.ohr 1.jmk $143>
2228```
2230#### Discussion
2232`++pa` exists exclusively for internal use of `++ff`, and `++ff` exists for
2233internal use in other cores.
2235---
2237### `++sea:ff`
2239`@r` to `fn`
2241Converts `a` from `@r` to `fn`.
2243#### Accepts
2245`a` is a `@r`, an IEEE float.
2247#### Produces
2249A `unit` of `@s`.
2251#### Source
2253```hoon
2254++ sea
2255 |= [a=@r] ^- fn
2256 =+ [f=(cut 0 [0 p] a) e=(cut 0 [p w] a)]
2257 =+ s=(sig a)
2258 ?: =(e 0)
2259 ?: =(f 0) [%f s --0 0] [%f s me f]
2260 ?: =(e (fil 0 w 1))
2261 ?: =(f 0) [%i s] [%n ~]
2262 =+ q=:(sum:si (sun:si e) me -1)
2263 =+ r=(^add f (bex p))
2264 [%f s q r]
2265```
2267#### Examples
2269```
2270> (sea:ff `@r`0x8)
2271[%f s=%.y e=--0 a=0]
2272```
2274---
2276### `++bit:ff`
2278`fn` to `@r`, rounding
2280Converts `a` from `fn` to `@r` and applies rounding.
2282#### Accepts
2284`a` is an `fn`.
2286#### Produces
2288A `@r`.
2290#### Source
2292```hoon
2293++ bit |= [a=fn] (bif (rou:pa a))
2294```
2296#### Examples
2298```
2299> (bit:ma:rd [%f | -6 202])
23000xc009400000000000
2301```
2303---
2305### `++bif:ff`
2307`fn` to `@r`, no rounding
2309Converts `a` from `fn` to `@r`. No rounding is applied.
2311#### Accepts
2313`a` is a `@r`, an IEEE float.
2315#### Produces
2317A `flag`.
2319#### Source
2321```hoon
2322++ bif
2323 |= [a=fn] ^- @r
2324 ?: ?=([%i *] a)
2325 =+ q=(lsh [0 p] (fil 0 w 1))
2326 ?: s.a q (^add q sb)
2327 ?: ?=([%n *] a) (lsh [0 (dec p)] (fil 0 +(w) 1))
2328 ?~ a.a ?: s.a `@r`0 sb
2329 =+ ma=(met 0 a.a)
2330 ?. =(ma +(p))
2331 ?> =(e.a me)
2332 ?> (^lth ma +(p))
2333 ?: s.a `@r`a.a (^add a.a sb)
2334 =+ q=(sum:si (dif:si e.a me) --1)
2335 =+ r=(^add (lsh [0 p] (abs:si q)) (end [0 p] a.a))
2336 ?: s.a r (^add r sb)
2337```
2339#### Examples
2341```
2342> (bif:ma:rd *fn)
23430x7ff8000000000000
2344```
2346---
2348### `++sig:ff`
2350Get sign
2352Produces the sign of `a`.
2354#### Accepts
2356`a` is a `@r`, an IEEE float.
2358#### Produces
2360A `flag`.
2362#### Source
2364```hoon
2365++ sig
2366 |= [a=@r] ^- ?
2367 =(0 (cut 0 [(^add p w) 1] a))
2368```
2370#### Examples
2372```
2373> (sig:ff `@r`5)
2374%.n
2375```
2377---
2379### `++exp:ff`
2381Get exponent
2383Produces the exponent of `a`.
2385#### Accepts
2387`a` is a `@r`, an IEEE float.
2389#### Produces
2391A signed integer.
2393#### Source
2395```hoon
2396++ exp
2397 |= [a=@r] ^- @s
2398 (dif:si (sun:si (cut 0 [p w] a)) b)
2399```
2401#### Examples
2403```
2404> (exp:ff `@r`5)
2405--0
2406```
2408---
2410### `++add:ff`
2412Add
2414Produces the sum of `a` plus `b`.
2416#### Accepts
2418`a` is a `@r`, an IEEE float.
2420`b` is a `@r`, an IEEE float.
2422#### Produces
2424A `@r`, an IEEE float.
2426#### Source
2428```hoon
2429++ add
2430 |= [a=@r b=@r]
2431 (bif (add:pa (sea a) (sea b)))
2432```
2434#### Examples
2436```
2437> (add:ma:rd `@r`5 `@r`11)
24380x10
2439```
2441---
2443### `++sub:ff`
2445Sub
2447Produces the sum of `a` plus `b`.
2449#### Accepts
2451`a` is a `@r`, an IEEE float.
2453`b` is a `@r`, an IEEE float.
2455#### Produces
2457A `@r`, an IEEE float.
2459#### Source
2461```hoon
2462++ sub
2463 |= [a=@r b=@r]
2464 (bif (sub:pa (sea a) (sea b)))
2465```
2467#### Examples
2469```
2470> (sub:ma:rd `@r`5 `@r`11)
24710x8000000000000006
2472```
2474---
2476### `++mul:ff`
2478Multiply
2480Produces the product of `a` multiplied by `b`.
2482#### Accepts
2484`a` is a `@r`, an IEEE float.
2486`b` is a `@r`, an IEEE float.
2488#### Produces
2490A `@r`, an IEEE float.
2492#### Multiply
2494```hoon
2495++ mul
2496 |= [a=@r b=@r]
2497 (bif (mul:pa (sea a) (sea b)))
2498```
2500#### Examples
2502```
2503> (mul:ma:rd `@r`11 `@r`2)
25040x0
2505```
2507---
2509### `++div:ff`
2511Divide
2513Produces the quotient of `a` divided by `b`.
2515#### Accepts
2517`a` is a `@r`, an IEEE float.
2519`b` is a `@r`, an IEEE float.
2521#### Produces
2523A `@r`, an IEEE float.
2525#### Source
2527```hoon
2528++ div
2529 |= [a=@r b=@r]
2530 (bif (div:pa (sea a) (sea b)))
2531```
2533#### Examples
2535```
2536> (div:ma:rd `@r`175 `@r`26)
25370x401aec4ec4ec4ec4
2538```
2540---
2542### `++fma:ff`
2544Fused multiply-add
2546Produces the sum of `c` plus the product of `a` multiplied by `b`;
2547`(a * b) + c`.
2549#### Accepts
2551`a` is a `@r`, an IEEE float.
2553`b` is a `@r`, an IEEE float.
2555`c` is a `@r`, an IEEE float.
2557#### Produces
2559A `@r`, an IEEE float.
2561#### Source
2563```hoon
2564++ fma
2565 |= [a=@r b=@r c=@r]
2566 (bif (fma:pa (sea a) (sea b) (sea c)))
2567```
2569#### Examples
2571```
2572> (fma:ma:rd `@r`175 `@r`26 `@r`100)
25730x64
2574```
2576---
2578### `++sqt:ff`
2580Square root
2582Produces the square root of `a`.
2584#### Accepts
2586`a` is a `@r`, an IEEE float.
2588#### Produces
2590A `@r`, an IEEE float.
2592#### Source
2594```hoon
2595++ sqt
2596 |= [a=@r]
2597 (bif (sqt:pa (sea a)))
2598```
2600#### Examples
2602```
2603> (sqt:ma:rd `@r`175)
26040x1e9a751f9447b724
2605```
2607---
2609### `++lth:ff`
2611Less than
2613Tests whether `a` is less than `b`.
2615#### Accepts
2617`a` is a `@r`, an IEEE float.
2619`b` is a `@r`, an IEEE float.
2621#### Produces
2623A `flag`.
2625#### Source
2627```hoon
2628++ lth
2629 |= [a=@r b=@r] (fall (lth:pa (sea a) (sea b)) |)
2630```
2632#### Examples
2634```
2635> (lth:ma:rd `@rd`1 `@rd`2)
2636%.y
2638> (lth:ma:rd `@rd`10 `@rd`2)
2639%.n
2640```
2642---
2644### `++lte:ff`
2646Less than or equal to
2648Tests whether `a` is less than or equal to `b`.
2650#### Accepts
2652`a` is a `@r`, an IEEE float.
2654`b` is a `@r`, an IEEE float.
2656#### Produces
2658A `flag`.
2660#### Source
2662```hoon
2663++ lte
2664 |= [a=@r b=@r] (fall (lte:pa (sea a) (sea b)) |)
2665```
2667#### Examples
2669```
2670> (lte:ma:rd `@rd`10 `@rd`2)
2671%.n
2673> (lte:ma:rd `@rd`10 `@rd`10)
2674%.y
2675```
2677---
2679### `++equ:ff`
2681Equals
2683Tests whether `a` is equal to `b`.
2685#### Accepts
2687`a` is a `@r`, an IEEE float.
2689`b` is a `@r`, an IEEE float.
2691#### Produces
2693A `flag`.
2695#### Source
2697```hoon
2698++ equ
2699 |= [a=@r b=@r] (fall (equ:pa (sea a) (sea b)) |)
2700```
2702#### Examples
2704```
2705> (equ:ma:rd `@rd`10 `@rd`2)
2706%.n
2708> (equ:ma:rd `@rd`10 `@rd`10)
2709%.y
2710```
2712---
2714### `++gte:ff`
2716Greater or equal than
2718Tests whether `a` is greater than or equal to `b`.
2720#### Accepts
2722`a` is a `@r`, an IEEE float.
2724`b` is a `@r`, an IEEE float.
2726#### Produces
2728A `flag`.
2730#### Source
2732```hoon
2733++ gte
2734 |= [a=@r b=@r] (fall (gte:pa (sea a) (sea b)) |)
2735```
2737#### Examples
2739```
2740> (gte:ma:rd `@rd`10 `@rd`10)
2741%.y
2743> (gte:ma:rd `@rd`10 `@rd`11)
2744%.n
2745```
2747---
2749### `++gth:ff`
2751Greater than
2753Tests whether `a` is greater than or equal to `b`.
2755#### Accepts
2757`a` is a `@r`, an IEEE float.
2759`b` is a `@r`, an IEEE float.
2761#### Produces
2763A `flag`.
2765#### Source
2767```hoon
2768++ gth
2769 |= [a=@r b=@r] (fall (gth:pa (sea a) (sea b)) |)
2770```
2772#### Examples
2774```
2775> (gth:ma:rd `@rd`10 `@rd`10)
2776%.n
2778> (gth:ma:rd `@rd`10 `@rd`9)
2779%.y
2780```
2782---
2784### `++sun:ff`
2786Unsigned integer to `@r`
2788Converts `a` from an unsigned integer (`@u`) to `@r`.
2790#### Accepts
2792`a` is `@u`, unsigned integer.
2794#### Produces
2796A `@r`, an IEEE float.
2798#### Source
2800```hoon
2801++ sun
2802 |= [a=@u] (bit [%f & --0 a])
2803```
2805#### Examples
2807```
2808> (sun:ma:rd 658.149.282)
28090x41c39d47d1000000
2810```
2812---
2814### `++san:ff`
2816Signed integer to `@r`
2818Converts `a` from a signed integer to `@r`.
2820#### Accepts
2822`a` is `@s`, an unsigned integer
2824#### Produces
2826A `@r`, an IEEE float.
2828#### Source
2830```hoon
2831++ san
2832 |= [a=@s] (bit [%f (syn:si a) --0 (abs:si a)])
2833```
2835#### Examples
2837```
2838> (san:ma:rd --10)
28390x4024000000000000
2840```
2842---
2844### `++toi:ff`
2846Round to integer
2848Rounds `a` to the nearest signed integer.
2850#### Accepts
2852`a` is a `@r`, an IEEE float.
2854#### Produces
2856A `flag` of `@s`.
2858#### Source
2860```hoon
2861++ toi
2862 |= [a=@r] (toi:pa (sea a))
2863```
2865#### Examples
2867```
2868> (toi:ma:rd `@r`0x4af)
2869[~ u=--0]
2870```
2872---
2874### `++drg:ff`
2876`@r` to decimal float
2878Converts `a` from `@r` to `dn` using the Dragon4 algorithm.
2880#### Accepts
2882`a` is a `@r`, an IEEE float.
2884#### Produces
2886A `dn`.
2888#### Source
2890```hoon
2891++ drg
2892 |= [a=@r] (drg:pa (sea a))
2893```
2895#### Examples
2897```
2898> (drg:ma:rd `@r`0x41c0)
2899[%d s=%.y e=-323 a=8.316]
2901> (drg:ma:rd (sun:ma:rd 658.149.282))
2902[%d s=%.y e=--0 a=658.149.282]
2903```
2905---
2907### `++grd:ff`
2909Decimal float to `@r`
2911Converts `a` from `dn` to `@r`.
2913#### Accepts
2915`a` is a `dn`.
2917#### Produces
2919A `@r`, an IEEE float.
2921#### Source
2923```hoon
2924++ grd
2925 |= [a=dn] (bif (grd:pa a))
2926```
2928#### Examples
2930```
2931> (grd:ma:rd [%d s=%.y e=--0 a=658.149.282])
29320x41c39d47d1000000
2933```
2935---
2937## `++rlyd`
2939Prep `@rd` for print
2941Converts `a` from a double-precision binary float to decimal64.
2943#### Accepts
2945`a` is a `@rd`, a double-precision float.
2947#### Produces
2949A `dn`.
2951#### Source
2953```hoon
2954++ rlyd |= a=@rd ^- dn (drg:rd a)
2955```
2957#### Examples
2959```
2960> (rlyd .~2.4703e-320)
2961[%d s=%.y e=-324 a=24.703]
2962```
2964---
2966## `++rlys`
2968Prep @rs for print
2970Converts `a` from a single-precision binary float to decimal32.
2972#### Accepts
2974`a` is a `@rs`, a single-precision float.
2976#### Produces
2978A `dn`.
2980#### Source
2982```hoon
2983++ rlys |= a=@rs ^- dn (drg:rs a)
2984```
2986#### Examples
2988```
2989> (rlys .1.681557e-39)
2990[%d s=%.y e=-45 a=1.681.557]
2991```
2993---
2995## `++rlyh`
2997Prep `@rh` for print
2999Converts `a` from a half-precision binary float to decimal16.
3001#### Accepts
3003`a` is a `@rh`, a half-precision float.
3005#### Produces
3007A `dn`.
3009#### Source
3011```hoon
3012++ rlyh |= a=@rh ^- dn (drg:rh a)
3013```
3015#### Examples
3017```
3018> (rlyh .~~3e1)
3019[%d s=%.y e=--1 a=3]
3020```
3022---
3024## `++rlyq`
3026Prep `@rq` for print
3028Converts `a` from a quad-precision binary float to decimal128.
3030#### Accepts
3032`a` is a `@rq`, a quad-precision float.
3034#### Produces
3036A `dn`.
3038#### Source
3040```hoon
3041++ rlyq |= a=@rq ^- dn (drg:rq a)
3042```
3044#### Examples
3046```
3047> (rlyq .~~~2.2628017865927756787440310766086816e-4343)
3048[%d s=%.y e=-4.377 a=22.628.017.865.927.756.787.440.310.766.086.816]
3049```
3051---
3053## `++ryld`
3055Finish parsing `@rd`
3057Converts `a` from a decimal float to a double-precision binary float.
3059#### Accepts
3061`a` is a `dn`.
3063#### Produces
3065A a `@rd`, a double-precision float.
3067#### Source
3069```hoon
3070++ ryld |= a=dn ^- @rd (grd:rd a)
3071```
3073#### Examples
3075```
3076> (ryld [%d s=%.y e=-324 a=24.703])
3077.~2.4703e-320
3078```
3080---
3082## `++ryls`
3084Finish parsing `@rs`
3086Converts `a` from a decimal float to a single-precision binary float.
3088#### Accepts
3090`a` is a `dn`.
3092#### Produces
3094A a `@rs`, a single-precision float.
3096#### Source
3098```hoon
3099++ ryls |= a=dn ^- @rs (grd:rs a)
3100```
3102#### Examples
3104```
3105> (ryls [%d s=%.y e=-324 a=24.703])
3108> (ryls [%d s=%.y e=-32 a=24.703])
3109.2.4703e-28
3110```
3112---
3114## `++rylh`
3116Finish parsing `@rh`
3118Converts `a` from a decimal float to a half-precision binary float.
3120#### Accepts
3122`a` is a `dn`.
3124#### Produces
3126A a `@rh`, a half-precision float.
3128#### Source
3130```hoon
3131++ rylh |= a=dn ^- @rh (grd:rh a)
3132```
3134#### Examples
3136```
3137> (rylh [%d s=%.y e=--1 a=703])
3138.~~7.032e3
3140> (rylh [%d s=%.y e=--3 a=56])
3141.~~5.6e4
3143> (rylh [%d s=%.y e=--4 a=56])
3144.~~inf
3145```
3147---
3149## `++rylq`
3151Finish parsing `@rq`
3153Converts `a` from a decimal float to a quad-precision binary float.
3155#### Accepts
3157`a` is a `dn`.
3159#### Produces
3161A a `@rq`, a quad-precision float.
3163#### Source
3165```hoon
3166++ rylq |= a=dn ^- @rq (grd:rq a)
3167```
3169#### Examples
3171```
3172> (rylq [%d s=%.y e=-324 a=24.703])
3173.~~~2.4703e-320
3174```
3176---
3178## `++rd`
3180Double-precision fp
3182A container core for operations related to double-precision binary floats.
3184`++rd` has four rounding modes: round to nearest (`$n`), round up (`$u`), round
3185down (`$d`), and round to zero (`$z`).
3187#### Source
3189```hoon
3190++ rd
3191 ^|
3192 ~% %rd +> ~
3193 |_ r=$?(%n %u %d %z)
3194```
3196---
3198### `++ma:rd`
3200Initialize `ff`
3202Instantiates the core `ff`, giving values to its samples based on the
3203configuration of the `rd` core.
3205#### Source
3207```hoon
3208++ ma
3209 %*(. ff w 11, p 52, b --1.023, r r)
3210```
3212#### Examples
3214```
3215> ~(ma rd %n)
3216< 24.ltg
3217 {{{w/@ud p/@ud b/@sd} r/?($n $u $d $z)} <54.tyv 119.wim 31.ohr 1.jmk $143>}
3219```
3221---
3223### `++sea:rd`
3225`@rd` to `fn`
3227Converts `a` from a double-precision binary float to `fn`.
3229#### Source
3231```hoon
3232++ sea
3233 |= [a=@rd] (sea:ma a)
3234```
3236#### Examples
3238```
3239> (sea:rd .~4.94066e-319)
3240[%f s=%.y e=-1.074 a=100.000]
3241```
3243---
3245### `++bit:rd`
3247`fn` to `@rd`
3249Converts `a` from `fn` to a double-precision binary float.
3251#### Accepts
3253`a` is an `fn`.
3255#### Produces
3257A `@rd`, a double-precision float.
3259#### Source
3261```hoon
3262++ bit
3263 |= [a=fn] ^- @rd (bit:ma a)
3264```
3266#### Examples
3268```
3269> (bit:rd [%f s=%.y e=-1.074 a=100.000])
3270.~4.94066e-319
3271```
3273---
3275### `++add:rd`
3277Add
3279Produces the sum of `a` plus `b`.
3281#### Accepts
3283`a` is a `@rd`, a double-precision float.
3285`b` is a `@rd`, a double-precision float.
3287#### Produces
3289A `@rd`.
3291#### Source
3293```hoon
3294++ add ~/ %add
3295 |= [a=@rd b=@rd] ^- @rd
3296 ~_ leaf+"rd-fail"
3297 (add:ma a b)
3298```
3300#### Examples
3302```
3303> (add:rd .~3.94066e12 .~9.2846e11)
3304.~4.86912e12
3305```
3307---
3309### `++sub:rd`
3311Subtract
3313Produces the difference of `a` minus `b`.
3315#### Accepts
3317`a` is a `@rd`, a double-precision float.
3319`b` is a `@rd`, a double-precision float.
3321#### Produces
3323A `@rd`.
3325#### Source
3327```hoon
3328++ sub ~/ %sub
3329 |= [a=@rd b=@rd] ^- @rd
3330 ~_ leaf+"rd-fail"
3331 (sub:ma a b)
3332```
3334#### Examples
3336```
3337> (sub:rd .~7.94069e2 .~1.2846e3)
3338.~-4.9053099999999995e2
3339```
3341---
3343### `++mul:rd`
3345Multiply
3347Produces the product of `a` times `b`.
3349#### Accepts
3351`a` is a `@rd`, a double-precision float.
3353`b` is a `@rd`, a double-precision float.
3355#### Produces
3357A `@rd`.
3359#### Source
3361```hoon
3362++ mul ~/ %mul
3363 |= [a=@rd b=@rd] ^- @rd
3364 ~_ leaf+"rd-fail"
3365 (mul:ma a b)
3366```
3368#### Examples
3370```
3371> (mul:rd .~7.94069e2 .~1.2246e3)
3372.~9.724168973999998e5
3373```
3375---
3377### `++div:rd`
3379Divide
3381Produces the quotient of `a` divided by `b`.
3383#### Accepts
3385`a` is a `@rd`, a double-precision float.
3387`b` is a `@rd`.
3389#### Produces
3391A `@rd`.
3393#### Source
3395```hoon
3396++ div ~/ %div
3397 |= [a=@rd b=@rd] ^- @rd
3398 ~_ leaf+"rd-fail"
3399 (div:ma a b)
3400```
3402#### Examples
3404```
3405> (div:rd .~7.94099e2 .~1.2246e3)
3406.~6.484558223093255e-1
3407```
3409---
3411### `++fma:rd`
3413Fused multiply-add
3415Produces the sum of `c` plus the product of `a` multiplied by `b`;
3416`(a * b) + c`.
3418#### Accepts
3420`a` is a `@rd`, an IEEE float.
3422`b` is a `@rd`.
3424`c` is a `@rd`.
3426#### Produces
3428A `@rd`.
3430#### Source
3432```hoon
3433++ fma ~/ %fma
3434 |= [a=@rd b=@rd c=@rd] ^- @rd
3435 ~_ leaf+"rd-fail"
3436 (fma:ma a b c)
3437```
3439#### Examples
3441```
3442> (fma:rd .~7.94099e2 .~1.2246e3 .~3.94066e3)
3443.~9.763942954e5
3444```
3446---
3448### `++sqt:rd`
3450Square root
3452Produces the square root of `a`.
3454#### Accepts
3456`a` is a `@rd`, a double-precision float.
3458#### Produces
3460A `@rd`.
3462#### Source
3464```hoon
3465++ sqt ~/ %sqt
3466 |= [a=@rd] ^- @rd ~_ leaf+"rd-fail"
3467 (sqt:ma a)
3468```
3470#### Examples
3472```
3473> (sqt:rd .~3.94066e3)
3474.~6.2774676422901614e1
3475```
3477---
3479### `++lth:rd`
3481Less than
3483Test whether `a` is less than `b`.
3485#### Accepts
3487`a` is a `@rd`, a double-precision float.
3489`b` is a `@rd`, a double-precision float.
3491#### Produces
3493A `@rd`.
3495#### Source
3497```hoon
3498++ lth ~/ %lth
3499 |= [a=@rd b=@rd]
3500 ~_ leaf+"rd-fail"
3501 (lth:ma a b)
3502```
3504#### Examples
3506```
3507> (lth:rd .~7.94099e2 .~1.2246e3)
3508%.y
3510> (lth:rd .~7.94099e2 .~1.2246e2)
3511%.n
3513> (lth:rd .~1.2246e2 .~1.2246e2)
3514%.n
3515```
3517---
3519### `++lte:rd`
3521Less than or equal
3523Test whether `a` is less than or equal to `b`.
3525#### Accepts
3527`a` is a `@rd`, a double-precision float.
3529`b` is a `@rd`, a double-precision float.
3531#### Produces
3533A `@rd`.
3535#### Source
3537```hoon
3538++ lte ~/ %lte
3539 |= [a=@rd b=@rd]
3540 ~_ leaf+"rd-fail"
3541 (lte:ma a b)
3542```
3544#### Examples
3546```
3547> (lte:rd .~7.94099e2 .~1.2246e3)
3548%.y
3550> (lte:rd .~7.94099e2 .~1.2246e2)
3551%.n
3553> (lte:rd .~1.2246e2 .~1.2246e2)
3554%.y
3555```
3557---
3559### `++equ:rd`
3561Equals
3563Test whether `a` is equal to `b`.
3565#### Accepts
3567`a` is a `@rd`, a double-precision float.
3569`b` is a `@rd`, a double-precision float.
3571#### Produces
3573A `@rd`.
3575#### Source
3577```hoon
3578++ equ ~/ %equ
3579 |= [a=@rd b=@rd]
3580 ~_ leaf+"rd-fail"
3581 (equ:ma a b)
3582```
3584#### Examples
3586```
3587> (equ:rd .~7.94099e2 .~1.2246e3)
3588%.n
3590> (equ:rd .~7.94099e2 .~1.2246e2)
3591%.n
3593> (equ:rd .~1.2246e2 .~1.2246e2)
3594%.y
3595```
3597---
3599### `++gte:rd`
3601Greater than or equal
3603Test whether `a` is greater than or equal to `b`.
3605#### Accepts
3607`a` is a `@rd`, a double-precision float.
3609`b` is a `@rd`, a double-precision float.
3611#### Produces
3613A `@rd`.
3615#### Source
3617```hoon
3618++ gte ~/ %gte
3619 |= [a=@rd b=@rd]
3620 ~_ leaf+"rd-fail"
3621 (gte:ma a b)
3622```
3624#### Examples
3626```
3627> (gte:rd .~7.94099e2 .~1.2246e3)
3628%.n
3630> (gte:rd .~7.94099e2 .~1.2246e2)
3631%.y
3633> (gte:rd .~1.2246e2 .~1.2246e2)
3634%.y
3635```
3637---
3639### `++gth:rd`
3641Greater than
3643Test whether `a` is greater `b`.
3645#### Accepts
3647`a` is a `@rd`, a double-precision float.
3649`b` is a `@rd`, a double-precision float.
3651#### Produces
3653A `@rd`.
3655#### Source
3657```hoon
3658++ gth ~/ %gth
3659 |= [a=@rd b=@rd]
3660 ~_ leaf+"rd-fail"
3661 (gth:ma a b)
3662```
3664#### Examples
3666```
3667> (gth:rd .~7.94099e2 .~1.2246e3)
3668%.n
3670> (gth:rd .~7.94099e2 .~1.2246e2)
3671%.y
3673> (gth:rd .~1.2246e2 .~1.2246e2)
3674%.n
3675```
3677---
3679### `++sun:rd`
3681Unsigned integer to `@rd`
3683Converts an unsigned integer `a` to `@rd`.
3685#### Accepts
3687`a` is a `@u`, an unsigned integer.
3689#### Produces
3691A `@rd`.
3693#### Source
3695```hoon
3696++ sun |= [a=@u] ^- @rd (sun:ma a)
3697```
3699#### Examples
3701```
3702> (sun:rd 511)
3703.~5.11e2
3704```
3706---
3708### `++san:rd`
3710Signed integer to `@rd`
3712Converts a signed integer `a` to `@rd`.
3714#### Accepts
3716`a` is a `@s`, a signed integer.
3718#### Produces
3720A `@rd`.
3722#### Source
3724```hoon
3725++ san |= [a=@s] ^- @rd (san:ma a)
3726```
3728#### Examples
3730```
3731> (san:rd -511)
3732.~-5.11e2
3733```
3735---
3737### `++sig:rd`
3739Get sign
3741Produces the sign of `a`.
3743#### Accepts
3745`a` is a `@rd`
3747#### Produces
3749A `flag`.
3751#### Source
3753```hoon
3754++ sig |= [a=@rd] ^- ? (sig:ma a)
3755```
3757#### Examples
3759```
3760> (sig:rd .~1.2246e3)
3761%.y
3762```
3764---
3766### `++exp:rd`
3768Get exponent
3770Produces the exponent of `a`.
3772#### Accepts
3774`a` is a `@rd`
3776#### Produces
3778A `@s`.
3780#### Source
3782```hoon
3783++ exp |= [a=@rd] ^- @s (exp:ma a)
3784```
3786#### Examples
3788```
3789> (exp:rd .~1.2246e3)
3790--10
3791```
3793---
3795### `++toi:rd`
3797Round to integer
3799Rounds `a` to the nearest integer.
3801#### Accepts
3803`a` is a `@rd`
3805#### Produces
3807A `unit` of `@s`.
3809#### Source
3811```hoon
3812++ toi |= [a=@rd] ^- (unit @s) (toi:ma a)
3813```
3815#### Examples
3817```
3818> (toi:rd .~1.2246e3)
3819[~ u=--1.224]
3820```
3822---
3824### `++drg:rd`
3826`@rd` to decimal float
3828Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
3829accurate results for rounded floats.
3831#### Accepts
3833`a` is a `@rd`
3835#### Produces
3837A `dn`.
3839#### Source
3841```hoon
3842++ drg |= [a=@rd] ^- dn (drg:ma a)
3843```
3845#### Examples
3847```
3848> (drg:rd .~1.2246e3)
3849[%d s=%.y e=-1 a=12.246]
3850```
3852---
3854### `++grd:rd`
3856Decimal float to `@rd`
3858Converts `a` from decimal float to `@rd`.
3860#### Accepts
3862`a` is a `@dn`
3864#### Produces
3866A `@rd`.
3868#### Source
3870```hoon
3871++ grd |= [a=dn] ^- @rd (grd:ma a)
3872```
3874#### Examples
3876```
3877> (grd:rd [%d s=%.y e=-1 a=12.246])
3878.~1.2246e3
3879```
3881---
3883## `++rs`
3885Single-precision fp
3887A container core for operations related to single-precision binary floats.
3889`++rs` has four rounding modes: round to nearest (`$n`), round up (`$u`), round
3890down (`$d`), and round to zero (`$z`).
3892#### Source
3894```hoon
3895++ rs
3896 ~% %rs +> ~
3897 ^|
3898 |_ r=$?(%n %u %d %z)
3899```
3901---
3903### `++ma:rs`
3905Initialize `ff`
3907Instantiates the core `ff`, giving values to its samples based on the
3908configuration of the `rs` core.
3910#### Source
3912```hoon
3913++ ma
3914 %*(. ff w 8, p 23, b --127, r r)
3915```
3917#### Examples
3919```
3920> ~(ma rs %n)
3921< 24.ltg
3922 {{{w/@ud p/@ud b/@sd} r/?($n $u $d $z)} <54.tyv 119.wim 31.ohr 1.jmk $143>}
3924```
3926---
3928### `++sea:rs`
3930`@rs` to `fn`
3932Converts `a` from `@rs` to `fn`.
3934#### Accepts
3936`a` is a `@rs`, an single-precision float.
3938#### Produces
3940An `fn`.
3942#### Source
3944```hoon
3945++ sea
3946 |= [a=@rs] (sea:ma a)
3947```
3949#### Examples
3951```
3952> (sea:rs .1.4e-43)
3953[%f s=%.y e=-149 a=100]
3954```
3956---
3958### `++bit:rs`
3960`fn` to `@rs`
3962Converts `a` from `fn` to `@rs`.
3964#### Accepts
3966`a` is an `fn`.
3968#### Produces
3970A `@rs`, a single-precision float.
3972#### Source
3974```hoon
3975++ bit
3976 |= [a=fn] ^- @rs (bit:ma a)
3977```
3979#### Examples
3981```
3982> (bit:rs [%f & -2 1.000])
3983.2.5e2
3984```
3986---
3988### `++add:rs`
3990Add
3992Produces the sum of `a` plus `b`.
3994#### Accepts
3996`a` is a `@rs`, a single-precision float.
3998`b` is a `@rs`.
4000#### Produces
4002A `@rs`.
4004#### Source
4006```hoon
4007++ add ~/ %add
4008 |= [a=@rs b=@rs] ^- @rs
4009 ~_ leaf+"rs-fail"
4010 (add:ma a b)
4011```
4013#### Examples
4015```
4016> (add:rs .2.5e1 .2.5e2)
4017.2.75e2
4018```
4020---
4022### `++sub:rs`
4024Subtract
4026Subtracts `a` from `b`.
4028#### Accepts
4030`a` is a `@rs`.
4032`b` is a `@rs`.
4034#### Source
4036```hoon
4037++ sub ~/ %sub
4038 |= [a=@rs b=@rs] ^- @rs
4039 ~_ leaf+"rs-fail"
4040 (sub:ma a b)
4041```
4043#### Examples
4045```
4046> (sub:rs .2.5e1 .2.5e2)
4047.-2.25e2
4048```
4050---
4052### `++mul:rs`
4054Multiply
4056Produces the product of `a` multiplied by `b`.
4058#### Accepts
4060`a` is a `@rs`, a single-precision float.
4062`b` is a `@rs`.
4064#### Produces
4066A `@rs`.
4068#### Source
4070```hoon
4071++ mul ~/ %mul
4072 |= [a=@rs b=@rs] ^- @rs
4073 ~_ leaf+"rs-fail"
4074 (mul:ma a b)
4075```
4077#### Examples
4079```
4080> (mul:rs .2.5e1 .2.5e2)
4081.6.25e3
4082```
4084---
4086### `++div:rs`
4088Divide
4090Produces the quotient of `a` divided by `b`.
4092#### Accepts
4094`a` is a `@rs`, a single-precision float.
4096`b` is a `@rs`.
4098#### Produces
4100A `@rs`.
4102#### Source
4104```hoon
4105++ div ~/ %div
4106 |= [a=@rs b=@rs] ^- @rs
4107 ~_ leaf+"rs-fail"
4108 (div:ma a b)
4109```
4111#### Examples
4113```
4114> (div:rs .4.5e1 .2.2e2)
4115.2.0454545e-1
4116```
4118---
4120### `++fma:rs`
4122Fused multiply-add
4124Produces the sum of `c` plus the product of `a` multiplied by `b`;
4125`(a * b) + c`.
4127#### Accepts
4129`a` is a `@rs`, a single-precision float.
4131`b` is a `@rs`.
4133`c` is a `@rs`.
4135#### Produces
4137A `@rs`.
4139#### Source
4141```hoon
4142++ fma ~/ %fma
4143 |= [a=@rs b=@rs c=@rs] ^- @rs
4144 ~_ leaf+"rs-fail"
4145 (fma:ma a b c)
4146```
4148#### Examples
4150```
4151> (fma:rs .2.5e1 .2.5e2 .8.2e1)
4152.6.332e3
4153```
4155---
4157### `++sqt:rs`
4159Square root
4161Produces the square root of `a`.
4163#### Accepts
4165`a` is a `@rs`, a single-precision float.
4167#### Produces
4169A `@rs`.
4171#### Source
4173```hoon
4174++ sqt ~/ %sqt
4175 |= [a=@rs] ^- @rs
4176 ~_ leaf+"rs-fail"
4177 (sqt:ma a)
4178```
4180#### Examples
4182```
4183> (sqt:rs .2.5e2)
4184.1.5811388e1
4185```
4187---
4189### `++lth:rs`
4191Less than
4193Test whether `a` is less than `b`.
4195#### Accepts
4197`a` is a `@rs`, a single-precision float.
4199`b` is a `@rs`.
4201#### Produces
4203A `@rs`.
4205#### Source
4207```hoon
4208++ lth ~/ %lth
4209 |= [a=@rs b=@rs]
4210 ~_ leaf+"rs-fail"
4211 (lth:ma a b)
4212```
4214#### Examples
4216```
4217> (lth:rs .9.9e1 .1.1e2)
4218%.y
4220> (lth:rs .9.9e1 .9.9e1)
4221%.n
4222```
4224---
4226### `++lte:rs`
4228Less than or equal
4230Test whether `a` is less than or equal to `b`.
4232#### Accepts
4234`a` is a `@rs`, a single-precision float.
4236`b` is a `@rs`.
4238#### Produces
4240A `@rs`.
4242#### Source
4244```hoon
4245++ lte ~/ %lte
4246 |= [a=@rs b=@rs]
4247 ~_ leaf+"rs-fail"
4248 (lte:ma a b)
4249```
4251#### Examples
4253```
4254> (lte:rs .9.9e1 .1.1e2)
4255%.y
4257> (lte:rs .9.9e1 .9.9e1)
4258%.y
4259```
4261---
4263### `++equ:rs`
4265Equals
4267Test whether `a` is equal to `b`.
4269#### Accepts
4271`a` is a `@rs`, a single-precision float.
4273`b` is a `@rs`.
4275#### Produces
4277A `@rs`.
4279#### Source
4281```hoon
4282++ equ ~/ %equ
4283 |= [a=@rs b=@rs]
4284 ~_ leaf+"rs-fail"
4285 (equ:ma a b)
4286```
4288#### Examples
4290```
4291> (equ:rs .9.9e1 .1.1e2)
4292%.n
4294> (equ:rs .9.9e1 .9.9e1)
4295%.y
4296```
4298---
4300### `++gte:rs`
4302Greater than or equal
4304Test whether `a` is greater than or equal to `b`.
4306#### Accepts
4308`a` is a `@rs`, a single-precision float.
4310`b` is a `@rs`.
4312#### Produces
4314A `@rs`.
4316#### Source
4318```hoon
4319++ gte ~/ %gte
4320 |= [a=@rs b=@rs]
4321 ~_ leaf+"rs-fail"
4322 (gte:ma a b)
4323```
4325#### Examples
4327```
4328> (gte:rs .9.9e1 .9.9e1)
4329%.y
4331> (gte:rs .9.9e1 .9.2e2)
4332%.n
4333```
4335---
4337### `++gth:rs`
4339Greater than
4341Test whether `a` is greater than `b`.
4343#### Accepts
4345`a` is a `@rs`, a single-precision float.
4347`b` is a `@rs`.
4349#### Produces
4351A `@rs`.
4353#### Source
4355```hoon
4356++ gth ~/ %gth
4357 |= [a=@rs b=@rs]
4358 ~_ leaf+"rs-fail"
4359 (gth:ma a b)
4360```
4362#### Examples
4364```
4365> (gth:rs .9.9e1 .9.2e2)
4366%.n
4368> (gth:rs .9.9e1 .9.9e1)
4369%.n
4371> (gth:rs .9.9e1 .1.9e1)
4372%.y
4373```
4375---
4377### `++sun:rs`
4379Unsigned integer to `@rs`
4381Converts `a` from an unsigned integer to `@rs`.
4383#### Accepts
4385`a` is an unsigned integer.
4387#### Produces
4389A `@rs`.
4391#### Source
4393```hoon
4394++ sun |= [a=@u] ^- @rs (sun:ma a)
4395```
4397#### Examples
4399```
4400> (sun:rs 343)
4401.3.43e2
4402```
4404---
4406### `++san:rs`
4408Signed integer to `@rs`'
4410Converts `a` from an unsigned integer to `@rs`.
4412#### Accepts
4414`a` is a signed integer.
4416#### Produces
4418A `@rs`.
4420#### Source
4422```hoon
4423++ san |= [a=@s] ^- @rs (san:ma a)
4424```
4426#### Examples
4428```
4429> (san:rs -343)
4430.-3.43e2'
4431```
4433---
4435### `++sig:rs`
4437Get sign
4439Produces the sign of `a`.
4441#### Accepts
4443`a` is a `@rs`.
4445#### Produces
4447A `flag`.
4449#### Source
4451```hoon
4452++ sig |= [a=@rs] ^- ? (sig:ma a)
4453```
4455#### Examples
4457```
4458> (sig:rs .3.43e2)
4459%.y
4461> (sig:rs .-3.43e2)
4462%.n
4463```
4465---
4467### `++exp:rs`
4469Get exponent
4471Produces the exponent of `a`.
4473#### Accepts
4475`a` is a `@rs`.
4477#### Produces
4479A signed integer.
4481#### Source
4483```hoon
4484++ exp |= [a=@rs] ^- @s (exp:ma a)
4485```
4487#### Examples
4489```
4490> (exp:rs .-3.43e2)
4491--8
4492```
4494---
4496### `++toi:rs`
4498Round to integer
4500Rounds `a` to the nearest integer.
4502#### Accepts
4504`a` is a `@rs`.
4506#### Produces
4508A `unit` of `@s`.
4510#### Source
4512```hoon
4513++ toi |= [a=@rs] ^- (unit @s) (toi:ma a)
4514```
4516#### Examples
4518```
4519> (toi:rs .-3.43e2)
4520[~ u=-343]
4521```
4523---
4525### `++drg:rs`
4527`@rs` to decimal float
4529Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
4530accurate results for rounded floats.
4532#### Accepts
4534`a` is a `@rs`
4536#### Produces
4538A `dn`.
4540#### Source
4542```hoon
4543++ drg |= [a=@rs] ^- dn (drg:ma a)
4544```
4546#### Examples
4548```
4549> (drg:rs .-3.43e2)
4550[%d s=%.n e=--0 a=343]
4551```
4553---
4555### `++grd:rs`
4557Decimal float to `@rs`
4559Converts `a` from `dn` to `@rs`.
4561#### Accepts
4563`a` is a `dn`.
4565#### Produces
4567A `@rs`.
4569#### Source
4571```hoon
4572++ grd |= [a=dn] ^- @rs (grd:ma a)
4573```
4575#### Examples
4577```
4578> (grd:rs [%d s=%.n e=--0 a=343])
4579.-3.43e2
4580```
4582---
4584## `++rq`
4586Quadruple-precision fp
4588A container core for operations related to quadruple-precision binary floats.
4590`++rq` has four rounding modes: round to nearest (`%n`), round up (`%u`), round
4591down (`%d`), and round to zero (`%z`).
4593#### Source
4595```hoon
4596++ rq
4597 ~% %rq +> ~
4598 ^|
4599 |_ r=$?(%n %u %d %z)
4600```
4602### `++ma:rq`
4604Initialize `ff`
4606Instantiates the core `ff`, giving values to its samples based on the
4607configuration of the `rq` core.
4609#### Source
4611```hoon
4612++ ma
4613 %*(. ff w 15, p 112, b --16.383, r r)
4614```
4616---
4618### `++sea:rq`
4620`@rq` to `fn`
4622Converts `a` from `@rq` to `fn`.
4624#### Accepts
4626`a` is a `@rq`, a quad-precision float.
4628#### Produces
4630An `fn`.
4632#### Source
4634```hoon
4635++ sea
4636 |= [a=@rq] (sea:ma a)
4637```
4639#### Examples
4641```
4642> (sea:rq .~~~1.05102e5)
4643[%f s=%.y e=-96 a=8.327.038.336.574.210.409.756.656.268.214.272]
4644```
4646---
4648### `++bit:rq`
4650`fn` to `@rq`
4652Converts `a` from `fn` to `@rq`.
4654#### Accepts
4656`a` is an `fn`.
4658#### Produces
4660A `@rq`, a quad-precision float.
4662#### Source
4664```hoon
4665++ bit
4666 |= [a=fn] ^- @rq (bit:ma a)
4667```
4669#### Examples
4671```
4672> (bit:rq [%f s=%.y e=-96 a=8.327.038.336.574.210.409.756.656.268.214.272])
4673.~~~1.05102e5
4674```
4676---
4678### `++add:rq`
4680Add
4682Produces the sum of `a` plus `b`.
4684#### Accepts
4686`a` is a `@rq`, a quad-precision float.
4688`b` is a `@rq`.
4690#### Produces
4692A `@rq`.
4694#### Source
4696```hoon
4697++ add ~/ %add
4698 |= [a=@rq b=@rq] ^- @rq
4699 ~_ leaf+"rq-fail"
4700 (add:ma a b)
4701```
4703#### Examples
4705```
4706> (add:rq .~~~-1.821e5 .~~~1.05102e5)
4707.~~~-7.6998e4
4708```
4710---
4712### `++sub:rq`
4714Subtract
4716Produces the difference of `a` minus `b`.
4718#### Accepts
4720`a` is a `@rq`, a quad-precision float.
4722`b` is a `@rq`.
4724#### Produces
4726A `@rq`.
4728#### Source
4730```hoon
4731++ sub ~/ %sub
4732 |= [a=@rq b=@rq] ^- @rq
4733 ~_ leaf+"rq-fail"
4734 (sub:ma a b)
4735```
4737#### Examples
4739```
4740> (sub:rq .~~~1.821e5 .~~~1.05102e5)
4741.~~~7.6998e4
4743> (sub:rq .~~~1.821e5 .~~~-1.05102e5)
4744.~~~2.87202e5
4745```
4747---
4749### `++mul:rq`
4751Multiply
4753Produces the product of `a` times `b`.
4755#### Accepts
4757`a` is a `@rq`, a quad-precision float.
4759`b` is a `@rq`.
4761#### Produces
4763A `@rq`.
4765#### Source
4767```hoon
4768++ mul ~/ %mul
4769 |= [a=@rq b=@rq] ^- @rq
4770 ~_ leaf+"rq-fail"
4771 (mul:ma a b)
4772```
4774#### Examples
4776```
4777> (mul:rq .~~~1.821e5 .~~~-1.05102e5)
4778.~~~-1.91390742e10
4779```
4781---
4783### `++div:rq`
4785Divide
4787Produces the product of `a` divided by `b`.
4789#### Accepts
4791`a` is a `@rq`, a quad-precision float.
4793`b` is a `@rq`.
4795#### Produces
4797A `@rq`.
4799#### Source
4801```hoon
4802++ div ~/ %div
4803 |= [a=@rq b=@rq] ^- @rq
4804 ~_ leaf+"rq-fail"
4805 (div:ma a b)
4806```
4808#### Examples
4810```
4811> (div:rq .~~~1.821e5 .~~~1.05102e3)
4812.~~~1.732602614602957127361991208540275e2
4813```
4815---
4817### `++fma:rq`
4819Fused multiply-add
4821Produces the sum of `c` plus the product of `a` multiplied by `b`;
4822`(a * b) + c`.
4824#### Accepts
4826`a` is a `@rq`, a quad-precision float.
4828`b` is a `@rq`.
4830`c` is a `@rq`.
4832#### Produces
4834A `@rq`.
4836#### Source
4838```hoon
4839++ fma ~/ %fma
4840 |= [a=@rq b=@rq c=@rq] ^- @rq
4841 ~_ leaf+"rq-fail"
4842 (fma:ma a b c)
4843```
4845#### Examples
4847```
4848> (fma:rq .~~~1.821e5 .~~~-1.05102e2 .~~~6.2044e7)
4849.~~~4.29049258e7
4850```
4852---
4854### `++sqt:rq`
4856Square root
4858Produces the square root of `a`.
4860#### Accepts
4862`a` is a `@rq`, a quad-precision float.
4864#### Produces
4866A `@rq`.
4868#### Source
4870```hoon
4871++ sqt ~/ %sqt
4872 |= [a=@rq] ^- @rq
4873 ~_ leaf+"rq-fail"
4874 (sqt:ma a)
4875```
4877#### Examples
4879```
4880> (sqt:rq .~~~6.2044e7)
4881.~~~7.876801381271461258959876570289002e3
4882```
4884---
4886### `++lth:rq`
4888Less than
4890Tests whether `a` is less than `b`.
4892#### Accepts
4894`a` is a `@rq`, a quad-precision float.
4896`b` is a `@rq`.
4898#### Produces
4900A `@rq`.
4902#### Source
4904```hoon
4905++ lth ~/ %lth
4906 |= [a=@rq b=@rq]
4907 ~_ leaf+"rq-fail"
4908 (lth:ma a b)
4909```
4911#### Examples
4913```
4914> (lth:rq .~~~1.2044e7 (mul:rq .~~~9.02e2 .~~~7.114e3))
4915%.n
4917> (lth:rq .~~~1.2044e7 (mul:rq .~~~9.02e3 .~~~7.114e3))
4918%.y
4919```
4921---
4923### `++lte:rq`
4925Less than or equal
4927Tests whether `a` is less than or equal to `b`.
4929#### Accepts
4931`a` is a `@rq`, a quad-precision float.
4933`b` is a `@rq`.
4935#### Produces
4937A `@rq`.
4939#### Source
4941```hoon
4942++ lte ~/ %lte
4943 |= [a=@rq b=@rq]
4944 ~_ leaf+"rq-fail"
4945 (lte:ma a b)
4946```
4948#### Examples
4950```
4951> (lte:rq .~~~1.2044e7 (mul:rq .~~~9.02e2 .~~~7.114e3))
4952%.n
4954> (lte:rq .~~~1.2044e7 (mul:rq .~~~9.02e3 .~~~7.114e3))
4955%.y
4957> (lte:rq .~~~1.2044e7 .~~~1.2044e7)
4958%.y
4959```
4961---
4963### `++equ:rq`
4965Equals
4967Tests whether `a` is equal to `b`.
4969#### Accepts
4971`a` is a `@rq`, a quad-precision float.
4973`b` is a `@rq`.
4975#### Produces
4977A `@rq`.
4979#### Source
4981```hoon
4982++ equ ~/ %equ
4983 |= [a=@rq b=@rq]
4984 ~_ leaf+"rq-fail"
4985 (equ:ma a b)
4986```
4988#### Examples
4990```
4991> (equ:rq .~~~1.2044e7 .~~~1.2044e7)
4992%.y
4994> (equ:rq .~~~2.2044e7 .~~~1.2044e7)
4995%.n
4996```
4998---
5000### `++gte:rq`
5002Greater than or equal
5004Tests whether `a` is greater than or equal to `b`.
5006#### Accepts
5008`a` is a `@rq`, a quad-precision float.
5010`b` is a `@rq`.
5012#### Produces
5014A `@rq`.
5016#### Source
5018```hoon
5019++ gte ~/ %gte
5020 |= [a=@rq b=@rq]
5021 ~_ leaf+"rq-fail"
5022 (gte:ma a b)
5023```
5025#### Examples
5027```
5028> (gte:rq .~~~1.2044e7 .~~~1.2044e7)
5029%.y
5031> (gte:rq .~~~2.2044e7 .~~~1.2044e7)
5032%.y
5034> (gte:rq .~~~1.2044e7 .~~~2.2044e7)
5035%.n
5036```
5038---
5040### `++gth:rq`
5042Tests whether `a` is greater than `b`.
5044#### Accepts
5046`a` is a `@rq`, a quad-precision float.
5048`b` is a `@rq`.
5050#### Produces
5052A `@rq`.
5054#### Source
5056```hoon
5057++ gth ~/ %gth
5058 |= [a=@rq b=@rq]
5059 ~_ leaf+"rq-fail"
5060 (gth:ma a b)
5061```
5063#### Examples
5065```
5066> (gth:rq .~~~1.2044e7 .~~~1.2044e7)
5067%.n
5069> (gth:rq .~~~2.2044e7 .~~~1.2044e7)
5070%.y
5072> (gth:rq .~~~1.2044e7 .~~~2.2044e7)
5073%.n
5074```
5076---
5078### `++sun:rq`
5080Unsigned integer to `@rq`
5082Converts `@` from an unsigned integer to `@rq`.
5084#### Accepts
5086`a` is a `@u`, an unsigned integer.
5088#### Produces
5090A `@rq`, a quad-precision float.
5092#### Source
5094```hoon
5095++ sun |= [a=@u] ^- @rq (sun:ma a)
5096```
5098#### Examples
5100```
5101> (sun:rq 205)
5102.~~~2.05e2
5103```
5105---
5107### `++san:rq`
5109Signed integer to `rq`
5111Converts `@` from a signed integer to `@rq`.
5113#### Accepts
5115`a` is a `@s`, a signed integer.
5117#### Produces
5119A `@rq`, a quad-precision float.
5121#### Source
5123```hoon
5124++ san |= [a=@s] ^- @rq (san:ma a)
5125```
5127#### Examples
5129```
5130> (san:rq -205)
5131.~~~-2.05e2
5132```
5134---
5136### `++sig:rq`
5138Get sign
5140Produces the sign of `a`.
5142#### Accepts
5144`a` is a `@rq`, a quad-precision float.
5146#### Produces
5148A `flag`.
5150#### Source
5152```hoon
5153++ sig |= [a=@rq] ^- ? (sig:ma a)
5154```
5156#### Examples
5158```
5159> (sig:rq .~~~-2.05e2)
5160%.n
5161```
5163---
5165### `++exp:rq`
5167Get exponent
5169Gets the exponent of `a`.
5171#### Accepts
5173`a` is a `@rq`, a quad-precision float.
5175#### Produces
5177A `@s`, a signed integer.
5179#### Source
5181```hoon
5182++ exp |= [a=@rq] ^- @s (exp:ma a)
5183```
5185#### Examples
5187```
5188> (exp:rq .~~~-2.05e2)
5189--7
5190```
5192---
5194### `++toi:rq`
5196Round to integer
5198Rounds `a` to the nearest integer.
5200#### Accepts
5202`a` is a `@rq`, a quad-precision float.
5204#### Produces
5206A `unit` of `@s`.
5208#### Source
5210```hoon
5211++ toi |= [a=@rq] ^- (unit @s) (toi:ma a)
5212```
5214#### Examples
5216```
5217> (toi:rq .~~~-2.085e2)
5218[~ u=-208]
5220> (toi:rq .~~~-2.08e2)
5221[~ u=-208]
5222```
5224---
5226### `++drg:rq`
5228`@rq` to decimal float
5230Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
5231accurate results for rounded floats.
5233#### Accepts
5235`a` is a `@rq`, a quad-precision float.
5237#### Produces
5239A `dn`.
5241#### Source
5243```hoon
5244++ drg |= [a=@rq] ^- dn (drg:ma a)
5245```
5247#### Examples
5249```
5250> (drg:rq .~~~-2.085e2)
5251[%d s=%.n e=-1 a=2.085]
5253> (drg:rq .~~~-2.08e2)
5254[%d s=%.n e=--0 a=208]
5255```
5257---
5259### `++grd:rq`
5261Decimal float to `@rq`
5263Converts `a` from `dn` to `@rq`.
5265#### Accepts
5267`a` is `dn`.
5269`a` is a `@rq`.
5271#### Produces
5273A `@rq`, a quad-precision float.
5275#### Source
5277```hoon
5278++ grd |= [a=dn] ^- @rq (grd:ma a)
5279```
5281#### Examples
5283```
5284> (grd:rq [%d s=%.n e=--0 a=343])
5285.~~~-3.43e2
5286```
5288---
5290## `++rh`
5292Half-precision fp
5294A container core for operations related to half-precision binary floats.
5296`++rh` has four rounding modes: round to nearest (`%n`), round up (`%u`), round
5297down (`%d`), and round to zero (`%z`).
5299#### Source
5301```hoon
5302++ rh
5303 ~% %rh +> ~
5304 ^|
5305 |_ r=$?(%n %u %d %z)
5306```
5308---
5310### `++ma:rh`
5312Initialize `ff`
5314Instantiates the core `ff`, giving values to its samples based on the
5315configuration of the `rh` core.
5317#### Source
5319```hoon
5320++ ma
5321 %*(. ff w 5, p 10, b --15, r r)
5322```
5324---
5326### `++sea:rh`
5328`@rh` to `fn`
5330Converts `a` from `@rh` to `fn`.
5332#### Accepts
5334`a` is a `@rh`, a half-precision float.
5336#### Produces
5338An `fn`.
5340#### Source
5342```hoon
5343++ sea
5344 |= [a=@rh] (sea:ma a)
5345```
5347#### Examples
5349```
5350> (sea:rh .~~1.22e-5)
5351[%f s=%.y e=-24 a=205]
5352```
5354---
5356### `++bit:rh`
5358`fn` to `@rh`
5360Converts `a` from `fn` to `@rh`.
5362#### Accepts
5364`a` is an `fn`.
5366#### Produces
5368A `@rh`, a half-precision float.
5370#### Source
5372```hoon
5373++ bit
5374 |= [a=fn] ^- @rh (bit:ma a)
5375```
5377#### Examples
5379```
5380> (bit:rh [%f s=%.y e=-24 a=205])
5381.~~1.22e-5
5382```
5384---
5386### `++add:rh`
5388Produces the sum of `a` plus `b`.
5390#### Accepts
5392`a` is a `@rh`, a half-precision float.
5394`b` is a `@rh`.
5396#### Produces
5398A `@rh`.
5400#### Source
5402```hoon
5403++ add ~/ %add
5404 |= [a=@rh b=@rh] ^- @rh
5405 ~_ leaf+"rh-fail"
5406 (add:ma a b)
5407```
5409#### Examples
5411```
5412> (add:rh .~~1.82e2 .~~1.02e2)
5413.~~2.84e2
5414```
5416---
5418### `++sub:rh`
5420Subtract
5422Produces the difference of `a` minus `b`.
5424#### Accepts
5426`a` is a `@rh`, a half-precision float.
5428`b` is a `@rh`.
5430#### Produces
5432A `@rh`.
5434#### Source
5436```hoon
5437++ sub ~/ %sub
5438 |= [a=@rh b=@rh] ^- @rh
5439 ~_ leaf+"rh-fail"
5440 (sub:ma a b)
5441```
5443#### Examples
5445```
5446> (sub:rh .~~1.821e2 .~~1.051e2)
5447.~~7.7e1
5449> (sub:rh .~~1.821e2 .~~6.051e2)
5450.~~-4.228e2
5451```
5453---
5455### `++mul:rh`
5457Multiply
5459Produces the product of `a` times `b`.
5461#### Accepts
5463`a` is a `@rh`, a quad-precision float.
5465`b` is a `@rh`.
5467#### Produces
5469A `@rh`.
5471#### Source
5473```hoon
5474++ mul ~/ %mul
5475 |= [a=@rh b=@rh] ^- @rh
5476 ~_ leaf+"rh-fail"
5477 (mul:ma a b)
5478```
5480#### Examples
5482```
5483> (mul:rh .~~1.821e1 .~~-1.05102e2)
5484.~~-1.913e3
5485```
5487---
5489### `++div:rh`
5491Divide
5493Produces the product of `a` divided by `b`.
5495#### Accepts
5497`a` is a `@rh`, a half-precision float.
5499`b` is a `@rh`.
5501#### Produces
5503A `@rh`.
5505#### Source
5507```hoon
5508++ div ~/ %div
5509 |= [a=@rh b=@rh] ^- @rh
5510 ~_ leaf+"rh-fail"
5511 (div:ma a b)
5512```
5514#### examples
5516```
5517> (div:rh .~~1.821e3 .~~1.05102e2)
5518.~~1.731e1
5519```
5521---
5523### `++fma:rh`
5525Fused multiply-add
5527Produces the sum of `c` plus the product of `a` multiplied by `b`;
5528`(a * b) + c`.
5530#### Accepts
5532`a` is a `@rh`, a half-precision float.
5534`b` is a `@rh`.
5536`c` is a `@rh`.
5538#### Produces
5540A `@rh`.
5542#### Source
5544```hoon
5545++ fma ~/ %fma
5546 |= [a=@rh b=@rh c=@rh] ^- @rh
5547 ~_ leaf+"rh-fail"
5548 (fma:ma a b c)
5549```
5551#### Examples
5553```
5554> (fma:rh .~~1.821e4 .~~-1.05102e2 .~~6.2044e3)
5555.~~-6.55e4
5556```
5558---
5560### `++sqt:rh`
5562Square root
5564Produces the square root of `a`.
5566#### Accepts
5568`a` is a `@rh`, a half-precision float.
5570#### Produces
5572A `@rh`.
5574#### Source
5576```hoon
5577++ sqt ~/ %sqt
5578 |= [a=@rh] ^- @rh
5579 ~_ leaf+"rh-fail"
5580 (sqt:ma a)
5581```
5583#### Example
5585```hoon
5586> (sqt:rh .~~6.24e4)
5587.~~2.498e2
5588```
5590---
5592### `++lth:rh`
5594Less than
5596Tests whether `a` is less than `b`.
5598#### Accepts
5600`a` is a `@rh`, a half-precision float.
5602`b` is a `@rh`.
5604#### Produces
5606A `@rh`.
5608#### Source
5610```hoon
5611++ lth ~/ %lth
5612 |= [a=@rh b=@rh]
5613 ~_ leaf+"rh-fail"
5614 (lth:ma a b)
5615```
5617#### Examples
5619```
5620> (lth:rh .~~1.2e5 (mul:rh .~~9.02e2 .~~7.114e2))
5621%.n
5623> (lth:rh .~~1.2e3 (mul:rh .~~9.02e1 .~~7.114e2))
5624%.y
5625```
5627---
5629### `++lte:rh`
5631Less than or equal
5633Tests whether `a` is less than or equal to `b`.
5635#### Accepts
5637`a` is a `@rh`, a half-precision float.
5639`b` is a `@rh`.
5641#### Produces
5643A `@rh`.
5645#### Source
5647```hoon
5648++ lte ~/ %lte
5649 |= [a=@rh b=@rh]
5650 ~_ leaf+"rh-fail"
5651 (lte:ma a b)
5652```
5654#### Examples
5656```
5657> (lte:rh .~~1.2e5 (mul:rh .~~9.02e2 .~~7.114e2))
5658%.n
5660> (lte:rh .~~1.2e3 (mul:rh .~~9.02e1 .~~7.114e2))
5661%.y
5663> (lte:rh .~~1.2e3 .~~1.2e3)
5664%.y
5665```
5667---
5669### `++equ:rh`
5671Equals
5673Tests whether `a` is equal to `b`.
5675#### Accepts
5677`a` is a `@rh`, a half-precision float.
5679`b` is a `@rh`.
5681#### Produces
5683A `@rh`.
5685#### Source
5687```hoon
5688++ equ ~/ %equ
5689 |= [a=@rh b=@rh]
5690 ~_ leaf+"rh-fail"
5691 (equ:ma a b)
5692```
5694#### Examples
5696```
5697> (equ:rh .~~1.24e4 .~~1.24e4)
5698%.y
5700> (equ:rh .~~2.24e4 .~~1.24e4)
5701%.n
5702```
5704---
5706### `++gte:rh`
5708Greater than or equal
5710Tests whether `a` is greater than or equal to `b`.
5712#### Accepts
5714`a` is a `@rh`, a half-precision float.
5716`b` is a `@rh`.
5718#### Produces
5720A `@rh`.
5722#### Source
5724```hoon
5725++ gte ~/ %gte
5726 |= [a=@rh b=@rh]
5727 ~_ leaf+"rh-fail"
5728 (gte:ma a b)
5729```
5731#### Examples
5733```
5734> (gte:rh .~~1.24e4 .~~1.24e4)
5735%.y
5737> (gte:rh .~~2.24e4 .~~1.24e4)
5738%.y
5740> (gte:rh .~~1.24e4 .~~2.24e4)
5741%.n
5742```
5744---
5746### `++gth:rh`
5748Tests whether `a` is greater than `b`.
5750#### Accepts
5752`a` is a `@rh`, a half-precision float.
5754`b` is a `@rh`.
5756#### Produces
5758A `@rh`.
5760#### Source
5762```hoon
5763++ gth ~/ %gth
5764 |= [a=@rh b=@rh]
5765 ~_ leaf+"rh-fail"
5766 (gth:ma a b)
5767```
5769#### Examples
5771```
5772> (gth:rh .~~1.24e4 .~~1.244e4)
5773%.n
5775> (gth:rh .~~2.24e4 .~~1.24e4)
5776%.y
5778> (gth:rh .~~1.24e4 .~~2.24e4)
5779%.n
5780```
5782---
5784### `++tos:rh`
5786`@rh` to `@rs`
5788Converts `@` from `@rh` to `@rs`.
5790#### Accepts
5792`a` is a `@rh`, a half-precision float.
5794#### Produces
5796A `@rs`, a single-precision float.
5798#### Source
5800```hoon
5801++ tos
5802 |= [a=@rh] (bit:rs (sea a))
5803```
5805#### Examples
5807```
5808> (tos:rh .~~2.5e2)
5809.2.5e2
5810```
5812---
5814### `++fos:rh`
5816`@rs` to `@rh`
5818Converts `@` from `@rs` to `@rh`.
5820#### Accepts
5822`a` is a `@rs`, a single-precision float.
5824#### Produces
5826A `@rh`, a half-precision float.
5828#### Source
5830```hoon
5831++ fos
5832 |= [a=@rs] (bit (sea:rs a))
5833```
5835#### Examples
5837```
5838> (fos:rh .2.5e2)
5839.~~2.5e2
5840```
5842---
5844### `++sun:rh`
5846Unsigned integer to `@rh`
5848Converts `@` from an unsigned integer to `@rh`.
5850#### Accepts
5852`a` is a `@u`, an unsigned integer.
5854#### Produces
5856A `@rh`, a half-precision float.
5858#### Source
5860```hoon
5861++ sun |= [a=@u] ^- @rh (sun:ma a)
5862```
5864#### Examples
5866```
5867> (sun:rh 205)
5868.~~2.05e2
5869```
5871---
5873### `++san:rh`
5875Signed integer to `@rh`
5877Converts `@` from a signed integer to `@rh`.
5879#### Accepts
5881`a` is a `@s`, a signed integer.
5883#### Produces
5885A `@rh`, a half-precision float.
5887#### Source
5889```hoon
5890++ san |= [a=@s] ^- @rh (san:ma a)
5891```
5893#### Examples
5895```
5896> (san:rh -205)
5897.~~-2.05e2
5898```
5900---
5902### `++sig:rh`
5904Get sign
5906Produces the sign of `a`.
5908#### Accepts
5910`a` is a `@rh`, a half-precision float.
5912#### Produces
5914A `flag`.
5916#### Source
5918```hoon
5919++ sig |= [a=@rh] ^- ? (sig:ma a)
5920```
5922#### Examples
5924```
5925> (sig:rh .~~-2.05e2)
5926%.n
5927```
5929---
5931### `++exp:rh`
5933Get exponent
5935Gets the exponent of `a`.
5937#### Accepts
5939`a` is a `@rh`, a half-precision float.
5941#### Produces
5943A `@s`, a signed integer.
5945#### Source
5947```hoon
5948++ exp |= [a=@rh] ^- @s (exp:ma a)
5949```
5951#### Examples
5953```
5954> (exp:rh .~~-2.05e2)
5955--7
5956```
5958---
5960### `++toi:rh`
5962Round to integer
5964Rounds `a` to the nearest integer.
5966#### Accepts
5968`a` is a `@rh`, a half-precision float.
5970#### Produces
5972A `unit` of `@s`.
5974#### Source
5976```hoon
5977++ toi |= [a=@rh] ^- (unit @s) (toi:ma a)
5978```
5980#### Examples
5982```
5983> (toi:rh .~~-2.085e2)
5984[~ u=-208]
5986> (toi:rh .~~-2.08e2)
5987[~ u=-208]
5988```
5990---
5992### `++drg:rh`
5994`@rh` to decimal float
5996Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
5997accurate results for rounded floats.
5999#### Accepts
6001`a` is a `@rh`, a half-precision float.
6003#### Produces
6005A `dn`.
6007#### Source
6009```hoon
6010++ drg |= [a=@rh] ^- dn (drg:ma a)
6011```
6013#### Examples
6015```
6016> (drg:rh .~~-2.085e2)
6017[%d s=%.n e=-1 a=2.085]
6019> (drg:rh .~~-2.08e2)
6020[%d s=%.n e=--0 a=208]
6021```
6023---
6025### `++grd:rh`
6027Decimal float to `@rh`
6029Converts `a` from `dn` to `@rh`.
6031#### Accepts
6033`a` is `dn`.
6035`a` is a `@rh`.
6037#### Produces
6039A `@rh`, a a half-precision float.
6041#### Source
6043```hoon
6044++ grd |= [a=dn] ^- @rh (grd:ma a)
6045```
6047#### Examples
6049```
6050> (grd:rh [%d s=%.n e=--0 a=343])
6051.~~-3.43e2
6052```
6054---