2title = "3b: Floating Point"
11A mold for the floating-point arithmetic using the base of two, the formula is
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.
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 &])
40> (add:fl [%n ~] [%i |])
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]
53A mold for the floating-point arithmetic using the base of 10; the formula is
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.
71> `dn`[%d & --0 17.163.091.968]
72[%d s=%.y e=--0 a=17.163.091.968]
87A mold for the floating-point arithmetic using the base of 10; the formula is
90Produces either a parsed float (`%d`), infinity of either sign (`%i`), or
97 $% [%d a=? b=[c=@ [d=@ e=@] f=? i=@]]
106> `rn`[%d | [2 [3 4] | 17.163]]
107[%d a=%.n b=[c=2 [d=3 e=4] f=%.n i=17.163]]
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.
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.
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`.
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]
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.
151`a` is a cell of a signed integer and an unsigned integer.
161 |= [a=[e=@s a=@u]] ^- fn (rau a &)
167> =a 10.161.487.211.429.486.882.397.572.894.294.017.777
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]
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
193`a` is a cell of a signed integer and an unsigned integer.
205 |= [a=[e=@s a=@u] t=?] ^- fn
207 %z (lug %fl a t) %d (lug %fl a t)
208 %a (lug %ce a t) %u (lug %ce a t)
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]
222See [`lug:fl`](#lugfl) for possible rounding operations.
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
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))
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)
263 %z (lug %fl a &) %d (lug %fl a &)
264 %a (lug %lg a &) %u (lug %lg a &)
267 (rou [e.b (^add (lsh [0 (abs:si q)] a.a) a.b)])
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]
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).
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.
305 |= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn
306 =+ q=(dif:si e.a e.b)
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))
315 %z (lug %sm a &) %d (lug %sm a &)
316 %a (lug %ce a &) %u (lug %ce a &)
319 =+ j=(lsh [0 (abs:si q)] a.a)
321 (fli $(a.b j, j a.b, r swr))
324 ?: e [%f & e.b i] (rou [e.b i])
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]
343Produces the product of `a` multiplied by `b`. There is no term to sign the
344significands, so a positive sign will always be produced.
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.
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))
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]
377Produces the quotient of `a` divided by `b`. There is no term to sign the
378significands, so a positive sign will always be produced.
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.
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))))
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))
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]
416Produces the square root of `a`.
420`a` is a cell of a signed integer and an unsigned integer.
430 |= [a=[e=@s a=@u]] ^- fn
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)) -
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))
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]
454Tests if `a` is less than `b`.
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.
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)
482> (^lth:fl [-4 684] [--0 35])
485> (^lth:fl [-4 684] [--0 90])
495Tests if `a` is equal to `b`.
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.
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)
521> (^equ:fl [-4 480] [-0 50])
524> (^equ:fl [-4 480] [-0 30])
532Integer binary logarithm
534Produces the lowest power to which the number 2 must be raised to obtain `a` or
539`a` is a cell of a signed integer and an unsigned integer.
549 |= [a=[e=@s a=@u]] ^- @s
550 (sum:si (sun:si (dec (met 0 a.a))) e.a)
556> (ibl:fl [-18 342.602.577])
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.
572`a` is a cell of a signed integer and an unsigned integer.
576A cell of a signed integer and an unsigned integer.
583 |- ?: =((end 0 a.a) 1) a
584 $(a.a (rsh 0 a.a), e.a (sum:si e.a --1))
590> (uni:fl [-8 342.602.578])
593> (uni:fl [-8 342.602.577])
603Produces the fully precise form of `a`, or the denormalized form of `a`.
607`a` is a cell of a signed integer and an unsigned integer.
611A cell of a signed integer and an unsigned integer.
620 =+ ?: =(den %i) (^sub prc ma)
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))
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]
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
651Possible rounding operations:
657- Nearest (`%ne`) -- Rounds ties away from 0 if the number is even, rounds
658 toward 0 if the number is odd.
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.
677 |= [t=$?(%fl %ce %sm %lg %ne %na %nt) a=[e=@s a=@u] s=?] ^- fn
680 ?. =(den %f) - :: flush denormals
682 ?: =((met 0 ->+>) prc) - [%f & zer]
685 ?> |(s (gth m prc)) :: require precision
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))
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)]
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))
718 %ce ?: &(=(b 0) s) a a(a +(a.a))
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))
726 ?: (^lth b y) a a(a +(a.a))
729 ?: =(b y) ?: s a a(a +(a.a))
730 ?: (^lth b y) a a(a +(a.a))
733 =. a ?. =((met 0 a.a) +(prc)) a
734 a(a (rsh 0 a.a), e (sum:si e.a --1))
737 ?: =(den %i) [%f & a]
738 ?: =((cmp:si emx e.a) -1) [%i &] [%f & a] :: enforce max. exp
747Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
748accurate results for rounded floats.
752`a` is a cell of a signed integer and an unsigned integer.
756A cell of a signed integer and an unsigned integer.
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
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)
771 ?& =(a.a (bex (dec prc))) :: if next smallest
772 |(!=(e.a emn) =(den %i)) :: float is half ULP,
773 == :: tighten lower bound
780 =+ [k=--0 q=(^div (^add s 9) 10)]
788 |- ?: (gte (^add (^mul r 2) mp) (^mul s 2))
789 $(s (^mul s 10), k (sum:si k --1))
791 |- :: r/s+o = a*10^-k
792 =+ v=(dvr (^mul r 10) s)
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))
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))
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])
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]
832Rounds float `a` to the nearest decimal float with an exponent of 0.
836`a` is a cell of a signed integer and an unsigned integer.
846 |= [a=[e=@s a=@u]] ^- fn
847 ?. =((cmp:si e.a --0) -1) [%f & a]
850 ?: |(=(r %d) =(r %z)) [%f & --0 y]
852 ?: |(=(r %u) =(r %a)) [%f & --0 ?~(z y +(y))]
854 ?: &(=(z i) =((dis y 1) 0)) [%f & --0 y]
855 ?: (^lth z i) [%f & --0 y] [%f & --0 +(y)]
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]
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.
883A cell of a signed integer and an unsigned integer.
889 |= [a=fn] ^- [%f s=? e=@s a=@u]
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]
916Multiplies `a` by 2 to the `b` power without rounding. This results in shifting
917the exponent term by `b`.
923`b` is a signed integer.
934 ?: |(?=([%n *] a) ?=([%i *] a)) a
941> (shf:fl [[%f & -2 7] --2])
944> (shf:fl [[%f & -2 7] -2])
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]
957Produces `a` with its signed changed from positive to negative, or vice versa.
972 ?-(-.a %f a(s !s.a), %i a(s !s.a), %n a)
978> (fli:fl [%f %.y -2 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]
994Switches the rounding mode of `r:fl`.
999++ swr ?+(r r %d %u, %u %d)
1010> =new-fl fl :: new fl core with changed state
1011> =new-fl new-fl(r %u)
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.
1028++ prc ?>((gth p 1) p)
1038> =new-fl new-fl(p 1)
1042> =new-fl new-fl(p 2)
1053Produces `d:fl`. Denormalizes if `d:fl` is `%d`. Flushes denormals to zero if
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`.
1075> =new-fl new-fl(d %f)
1086Produces `v:fl`, the minimum exponent. The default minimum exponent is -16.494.
1107Returns the maximum exponent of `fl`. The default maximum exponent is --16.271.
1112++ emx (sum:si emn (sun:si w))
1131Produces the smallest possible denormalized float.
1152Produces the smallest representable normal float.
1157++ spn [e=emn a=(bex (dec prc))]
1164[e=-16.494 a=5.192.296.858.534.827.628.530.496.329.220.096]
1173Produces the largest representable normal float.
1178++ lfn [e=emx a=(fil 0 prc 1)]
1185[e=--16.271 a=10.384.593.717.069.655.257.060.992.658.440.191]
1194Produces the sum of `emx:fl` plus `prc:fl`.
1199++ lfe (sum:si emx (sun:si prc))
1215Produces zero represented as a float.
1236Rounds `a`. The way in which `a` is rounded depends on the value of `r:fl`.
1254 =.(r swr (fli (^rou +>.a)))
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]
1280Produces the sign of `a`.
1295 ?-(-.a %f s.a, %i s.a, %n &)
1301> (syn:fl (sun:fl 106))
1304> (syn:fl [%f | --0 106])
1314Produces the absolute value of `a`.
1329 ?: ?=([%f *] a) [%f & e.a a.a]
1330 ?: ?=([%i *] a) [%i &] [%n ~]
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]
1349Produces the sum of `a` plus `b`.
1365 |= [a=fn b=fn] ^- fn
1366 ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
1367 ?: |(?=([%i *] a) ?=([%i *] b))
1368 ?: &(?=([%i *] a) ?=([%i *] 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]
1379 ?: s.a (^add +>.a +>.b |)
1380 =.(r swr (fli (^add +>.a +>.b |)))
1381 ?: s.a (^sub +>.a +>.b |)
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]
1398Produces the exact sum of `a` plus `b`.
1414 |= [a=fn b=fn] ^- fn
1415 ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
1416 ?: |(?=([%i *] a) ?=([%i *] b))
1417 ?: &(?=([%i *] a) ?=([%i *] 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]
1428 ?: s.a (^add +>.a +>.b &)
1429 (fli (^add +>.a +>.b &))
1430 ?: s.a (^sub +>.a +>.b &)
1437> (ead:fl [%f & --0 106] [%f | --3 55])
1438[%f s=%.n e=--0 a=334]
1447Produces the difference of `a` minus `b`.
1463 |= [a=fn b=fn] ^- fn (add a (fli b))
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]
1479Produces the product of `a` multiplied by `b`.
1495 |= [a=fn b=fn] ^- fn
1496 ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
1500 ?: =(a.b 0) [%n ~] [%i =(s.a s.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)))
1514Produces the exact product of `a` multiplied by `b`.
1530 |= [a=fn b=fn] ^- fn
1531 ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
1535 ?: =(a.b 0) [%n ~] [%i =(s.a s.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)]
1548Produces the quotient of `a` divided by `b`.
1564 |= [a=fn b=fn] ^- fn
1565 ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
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)))
1581Produces the sum of `c` plus the product of `a` multiplied by `b`;
1600 |= [a=fn b=fn c=fn] ^- fn
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]=
1617Produces the square root of `a`.
1632 ?: ?=([%n *] a) [%n ~]
1633 ?: ?=([%i *] a) ?:(s.a a [%n ~])
1635 ?: s.a (^sqt +>.a) [%n ~]
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]
1651Produces the inverse of `a` by dividing `1` by `a`.
1666 (div [%f & --0 1] a)
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])
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])
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])
1692Signed integer to float
1694Produces `a` in floating-point representation.
1698`a` is an unsigned integer.
1719[%f s=%.y e=-90 a=6.250.023.776.601.238.669.911.180.544.311.296]
1729Signed integer to float
1731Produces the floating-point representation of `a`, an unsigned integer.
1735`a` is an unsigned integer.
1747 (rou [%f -.b --0 +.b])
1754[%f s=%.y e=-106 a=8.112.963.841.460.668.169.578.900.514.406.400]
1757[%f s=%.n e=-106 a=8.112.963.841.460.668.169.578.900.514.406.400]
1766Tests if `a` is less than `b`. Returns `~` in the event of `a` or `b` being a
1783 |= [a=fn b=fn] ^- (unit ?)
1784 ?: |(?=([%n *] a) ?=([%n *] 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
1791 ?: s.a (^lth +>.a +>.b) (^lth +>.b +>.a)
1797> (lth:fl (sun:fl 116) (sun:fl 4.820))
1800> (lth:fl (sun:fl 218.116) (sun:fl 4.820))
1803> (lth:fl (sun:fl 218.116) [%n ~])
1813Tests whether `a` is less than or equal to `b`. Returns `~` in the event of `a`
1814or `b` being a NaN (`[%n ~]`).
1830 |= [a=fn b=fn] ^- (unit ?)
1831 %+ bind (lth b a) |= a=? !a
1837> (lte:fl (sun:fl 102) [%f %.y -5 973.655.724])
1840> (lte:fl (sun:fl 102) [%f %.y -24 973.655.724])
1843> (lte:fl [%f %.y --2 25] (sun:fl 100))
1846> (lte:fl [%f %.y --2 25] [%f %.y --3 2])
1849> (lte:fl [%f %.y --2 25] [%n ~])
1859Tests if `a` is equal to `b`. Returns `~` in the event of `a` or `b` being a NaN
1876 |= [a=fn b=fn] ^- (unit ?)
1877 ?: |(?=([%n *] a) ?=([%n *] 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)) |
1889> (equ:fl [%f %.y --2 25] (sun:fl 100))
1892> (equ:fl [%f %.y --2 25] (sun:fl 101))
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 ~]`).
1919 |= [a=fn b=fn] ^- (unit ?) (lte b a)
1925> (gte:fl [%f %.y --2 25] (sun:fl 100))
1928> (gth:fl [%f %.y --6 73.989] [%f %.y --5 919.599])
1931> (gth:fl [%f %.y --6 73.989] [%n ~])
1941Tests whether `a` is greater than `b`. Returns `~` in the event of `a` or `b`
1942being a NaN (`[%n ~]`).
1958 |= [a=fn b=fn] ^- (unit ?) (lth b a)
1964> (gth:fl [%f %.y --2 25] (sun:fl 100))
1967> (gth:fl [%f %.y --6 73.989] [%f %.y --5 119.599])
1977Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
1978accurate results for rounded floats.
1993 ?: ?=([%n *] a) [%n ~]
1994 ?: ?=([%i *] a) [%i s.a]
1995 ?~ a.a [%d s.a --0 0]
1996 [%d s.a (^drg +>.a)]
2002> (drg:fl [%f | --6 73.989])
2003[%d s=%.n e=--0 a=4.735.296]
2012Converts decimal `a` to `fn`.
2027 ?: ?=([%n *] a) [%n ~]
2028 ?: ?=([%i *] a) [%i s.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)])
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]
2050Round to signed integer
2052Rounds `a` to the nearest signed integer.
2066 |= [a=fn] ^- (unit @s)
2068 ?. ?=([%f *] b) ~ :- ~
2069 =+ c=(^^mul (bex (abs:si e.b)) a.b)
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]
2086Rounds `a` to the nearest decimal integer.
2104 =.(r swr (fli (^toj +>.a)))
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])
2119> (toj:fl [%f s=%.y e=-9 a=9.002])
2120[%f s=%.y e=--0 a=16]
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`.
2141 |_ [[w=@u p=@u b=@s] r=$?(%n %u %d %z %a)]
2147> =ffcore ~(. ff [8 8 0] %n)
2149<24.ltg {{{@ud @ud @ud} r/$n} <54.tyv 119.wim 31.ohr 1.jmk $143>}>
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.
2166Produces the sign bit of `++ff`.
2171++ sb (bex (^add w p))
2187Produces the minimum possible exponent of `ff`.
2192++ me (dif:si (dif:si --1 b) (sun:si p))
2208Instantiates the core `fl`, giving values to its samples based on the
2209configuration of the `ff` core.
2215 %*(. fl p +(p), v me, w (^sub (bex w) 3), d %d, r r)
2221> ~(pa ff [11 52 --1.023] %n)
2224 { {{p/@ v/@s w/@} r/?($n $u $a $d $z) d/$d}
2225 <54.tyv 119.wim 31.ohr 1.jmk $143>
2232`++pa` exists exclusively for internal use of `++ff`, and `++ff` exists for
2233internal use in other cores.
2241Converts `a` from `@r` to `fn`.
2245`a` is a `@r`, an IEEE float.
2256 =+ [f=(cut 0 [0 p] a) e=(cut 0 [p w] a)]
2259 ?: =(f 0) [%f s --0 0] [%f s me f]
2261 ?: =(f 0) [%i s] [%n ~]
2262 =+ q=:(sum:si (sun:si e) me -1)
2263 =+ r=(^add f (bex p))
2278`fn` to `@r`, rounding
2280Converts `a` from `fn` to `@r` and applies rounding.
2293++ bit |= [a=fn] (bif (rou:pa a))
2299> (bit:ma:rd [%f | -6 202])
2307`fn` to `@r`, no rounding
2309Converts `a` from `fn` to `@r`. No rounding is applied.
2313`a` is a `@r`, an IEEE float.
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
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)
2352Produces the sign of `a`.
2356`a` is a `@r`, an IEEE float.
2367 =(0 (cut 0 [(^add p w) 1] a))
2383Produces the exponent of `a`.
2387`a` is a `@r`, an IEEE float.
2398 (dif:si (sun:si (cut 0 [p w] a)) b)
2414Produces the sum of `a` plus `b`.
2418`a` is a `@r`, an IEEE float.
2420`b` is a `@r`, an IEEE float.
2424A `@r`, an IEEE float.
2431 (bif (add:pa (sea a) (sea b)))
2437> (add:ma:rd `@r`5 `@r`11)
2447Produces the sum of `a` plus `b`.
2451`a` is a `@r`, an IEEE float.
2453`b` is a `@r`, an IEEE float.
2457A `@r`, an IEEE float.
2464 (bif (sub:pa (sea a) (sea b)))
2470> (sub:ma:rd `@r`5 `@r`11)
2480Produces the product of `a` multiplied by `b`.
2484`a` is a `@r`, an IEEE float.
2486`b` is a `@r`, an IEEE float.
2490A `@r`, an IEEE float.
2497 (bif (mul:pa (sea a) (sea b)))
2503> (mul:ma:rd `@r`11 `@r`2)
2513Produces the quotient of `a` divided by `b`.
2517`a` is a `@r`, an IEEE float.
2519`b` is a `@r`, an IEEE float.
2523A `@r`, an IEEE float.
2530 (bif (div:pa (sea a) (sea b)))
2536> (div:ma:rd `@r`175 `@r`26)
2546Produces the sum of `c` plus the product of `a` multiplied by `b`;
2551`a` is a `@r`, an IEEE float.
2553`b` is a `@r`, an IEEE float.
2555`c` is a `@r`, an IEEE float.
2559A `@r`, an IEEE float.
2566 (bif (fma:pa (sea a) (sea b) (sea c)))
2572> (fma:ma:rd `@r`175 `@r`26 `@r`100)
2582Produces the square root of `a`.
2586`a` is a `@r`, an IEEE float.
2590A `@r`, an IEEE float.
2597 (bif (sqt:pa (sea a)))
2603> (sqt:ma:rd `@r`175)
2613Tests whether `a` is less than `b`.
2617`a` is a `@r`, an IEEE float.
2619`b` is a `@r`, an IEEE float.
2629 |= [a=@r b=@r] (fall (lth:pa (sea a) (sea b)) |)
2635> (lth:ma:rd `@rd`1 `@rd`2)
2638> (lth:ma:rd `@rd`10 `@rd`2)
2646Less than or equal to
2648Tests whether `a` is less than or equal to `b`.
2652`a` is a `@r`, an IEEE float.
2654`b` is a `@r`, an IEEE float.
2664 |= [a=@r b=@r] (fall (lte:pa (sea a) (sea b)) |)
2670> (lte:ma:rd `@rd`10 `@rd`2)
2673> (lte:ma:rd `@rd`10 `@rd`10)
2683Tests whether `a` is equal to `b`.
2687`a` is a `@r`, an IEEE float.
2689`b` is a `@r`, an IEEE float.
2699 |= [a=@r b=@r] (fall (equ:pa (sea a) (sea b)) |)
2705> (equ:ma:rd `@rd`10 `@rd`2)
2708> (equ:ma:rd `@rd`10 `@rd`10)
2716Greater or equal than
2718Tests whether `a` is greater than or equal to `b`.
2722`a` is a `@r`, an IEEE float.
2724`b` is a `@r`, an IEEE float.
2734 |= [a=@r b=@r] (fall (gte:pa (sea a) (sea b)) |)
2740> (gte:ma:rd `@rd`10 `@rd`10)
2743> (gte:ma:rd `@rd`10 `@rd`11)
2753Tests whether `a` is greater than or equal to `b`.
2757`a` is a `@r`, an IEEE float.
2759`b` is a `@r`, an IEEE float.
2769 |= [a=@r b=@r] (fall (gth:pa (sea a) (sea b)) |)
2775> (gth:ma:rd `@rd`10 `@rd`10)
2778> (gth:ma:rd `@rd`10 `@rd`9)
2786Unsigned integer to `@r`
2788Converts `a` from an unsigned integer (`@u`) to `@r`.
2792`a` is `@u`, unsigned integer.
2796A `@r`, an IEEE float.
2802 |= [a=@u] (bit [%f & --0 a])
2808> (sun:ma:rd 658.149.282)
2816Signed integer to `@r`
2818Converts `a` from a signed integer to `@r`.
2822`a` is `@s`, an unsigned integer
2826A `@r`, an IEEE float.
2832 |= [a=@s] (bit [%f (syn:si a) --0 (abs:si a)])
2848Rounds `a` to the nearest signed integer.
2852`a` is a `@r`, an IEEE float.
2862 |= [a=@r] (toi:pa (sea a))
2868> (toi:ma:rd `@r`0x4af)
2876`@r` to decimal float
2878Converts `a` from `@r` to `dn` using the Dragon4 algorithm.
2882`a` is a `@r`, an IEEE float.
2892 |= [a=@r] (drg:pa (sea a))
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]
2909Decimal float to `@r`
2911Converts `a` from `dn` to `@r`.
2919A `@r`, an IEEE float.
2925 |= [a=dn] (bif (grd:pa a))
2931> (grd:ma:rd [%d s=%.y e=--0 a=658.149.282])
2941Converts `a` from a double-precision binary float to decimal64.
2945`a` is a `@rd`, a double-precision float.
2954++ rlyd |= a=@rd ^- dn (drg:rd a)
2960> (rlyd .~2.4703e-320)
2961[%d s=%.y e=-324 a=24.703]
2970Converts `a` from a single-precision binary float to decimal32.
2974`a` is a `@rs`, a single-precision float.
2983++ rlys |= a=@rs ^- dn (drg:rs a)
2989> (rlys .1.681557e-39)
2990[%d s=%.y e=-45 a=1.681.557]
2999Converts `a` from a half-precision binary float to decimal16.
3003`a` is a `@rh`, a half-precision float.
3012++ rlyh |= a=@rh ^- dn (drg:rh a)
3028Converts `a` from a quad-precision binary float to decimal128.
3032`a` is a `@rq`, a quad-precision float.
3041++ rlyq |= a=@rq ^- dn (drg:rq a)
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]
3057Converts `a` from a decimal float to a double-precision binary float.
3065A a `@rd`, a double-precision float.
3070++ ryld |= a=dn ^- @rd (grd:rd a)
3076> (ryld [%d s=%.y e=-324 a=24.703])
3086Converts `a` from a decimal float to a single-precision binary float.
3094A a `@rs`, a single-precision float.
3099++ ryls |= a=dn ^- @rs (grd:rs a)
3105> (ryls [%d s=%.y e=-324 a=24.703])
3108> (ryls [%d s=%.y e=-32 a=24.703])
3118Converts `a` from a decimal float to a half-precision binary float.
3126A a `@rh`, a half-precision float.
3131++ rylh |= a=dn ^- @rh (grd:rh a)
3137> (rylh [%d s=%.y e=--1 a=703])
3140> (rylh [%d s=%.y e=--3 a=56])
3143> (rylh [%d s=%.y e=--4 a=56])
3153Converts `a` from a decimal float to a quad-precision binary float.
3161A a `@rq`, a quad-precision float.
3166++ rylq |= a=dn ^- @rq (grd:rq a)
3172> (rylq [%d s=%.y e=-324 a=24.703])
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`).
3193 |_ r=$?(%n %u %d %z)
3202Instantiates the core `ff`, giving values to its samples based on the
3203configuration of the `rd` core.
3209 %*(. ff w 11, p 52, b --1.023, r r)
3217 {{{w/@ud p/@ud b/@sd} r/?($n $u $d $z)} <54.tyv 119.wim 31.ohr 1.jmk $143>}
3227Converts `a` from a double-precision binary float to `fn`.
3233 |= [a=@rd] (sea:ma a)
3239> (sea:rd .~4.94066e-319)
3240[%f s=%.y e=-1.074 a=100.000]
3249Converts `a` from `fn` to a double-precision binary float.
3257A `@rd`, a double-precision float.
3263 |= [a=fn] ^- @rd (bit:ma a)
3269> (bit:rd [%f s=%.y e=-1.074 a=100.000])
3279Produces the sum of `a` plus `b`.
3283`a` is a `@rd`, a double-precision float.
3285`b` is a `@rd`, a double-precision float.
3295 |= [a=@rd b=@rd] ^- @rd
3303> (add:rd .~3.94066e12 .~9.2846e11)
3313Produces the difference of `a` minus `b`.
3317`a` is a `@rd`, a double-precision float.
3319`b` is a `@rd`, a double-precision float.
3329 |= [a=@rd b=@rd] ^- @rd
3337> (sub:rd .~7.94069e2 .~1.2846e3)
3338.~-4.9053099999999995e2
3347Produces the product of `a` times `b`.
3351`a` is a `@rd`, a double-precision float.
3353`b` is a `@rd`, a double-precision float.
3363 |= [a=@rd b=@rd] ^- @rd
3371> (mul:rd .~7.94069e2 .~1.2246e3)
3372.~9.724168973999998e5
3381Produces the quotient of `a` divided by `b`.
3385`a` is a `@rd`, a double-precision float.
3397 |= [a=@rd b=@rd] ^- @rd
3405> (div:rd .~7.94099e2 .~1.2246e3)
3406.~6.484558223093255e-1
3415Produces the sum of `c` plus the product of `a` multiplied by `b`;
3420`a` is a `@rd`, an IEEE float.
3434 |= [a=@rd b=@rd c=@rd] ^- @rd
3442> (fma:rd .~7.94099e2 .~1.2246e3 .~3.94066e3)
3452Produces the square root of `a`.
3456`a` is a `@rd`, a double-precision float.
3466 |= [a=@rd] ^- @rd ~_ leaf+"rd-fail"
3473> (sqt:rd .~3.94066e3)
3474.~6.2774676422901614e1
3483Test whether `a` is less than `b`.
3487`a` is a `@rd`, a double-precision float.
3489`b` is a `@rd`, a double-precision float.
3507> (lth:rd .~7.94099e2 .~1.2246e3)
3510> (lth:rd .~7.94099e2 .~1.2246e2)
3513> (lth:rd .~1.2246e2 .~1.2246e2)
3523Test whether `a` is less than or equal to `b`.
3527`a` is a `@rd`, a double-precision float.
3529`b` is a `@rd`, a double-precision float.
3547> (lte:rd .~7.94099e2 .~1.2246e3)
3550> (lte:rd .~7.94099e2 .~1.2246e2)
3553> (lte:rd .~1.2246e2 .~1.2246e2)
3563Test whether `a` is equal to `b`.
3567`a` is a `@rd`, a double-precision float.
3569`b` is a `@rd`, a double-precision float.
3587> (equ:rd .~7.94099e2 .~1.2246e3)
3590> (equ:rd .~7.94099e2 .~1.2246e2)
3593> (equ:rd .~1.2246e2 .~1.2246e2)
3601Greater than or equal
3603Test whether `a` is greater than or equal to `b`.
3607`a` is a `@rd`, a double-precision float.
3609`b` is a `@rd`, a double-precision float.
3627> (gte:rd .~7.94099e2 .~1.2246e3)
3630> (gte:rd .~7.94099e2 .~1.2246e2)
3633> (gte:rd .~1.2246e2 .~1.2246e2)
3643Test whether `a` is greater `b`.
3647`a` is a `@rd`, a double-precision float.
3649`b` is a `@rd`, a double-precision float.
3667> (gth:rd .~7.94099e2 .~1.2246e3)
3670> (gth:rd .~7.94099e2 .~1.2246e2)
3673> (gth:rd .~1.2246e2 .~1.2246e2)
3681Unsigned integer to `@rd`
3683Converts an unsigned integer `a` to `@rd`.
3687`a` is a `@u`, an unsigned integer.
3696++ sun |= [a=@u] ^- @rd (sun:ma a)
3710Signed integer to `@rd`
3712Converts a signed integer `a` to `@rd`.
3716`a` is a `@s`, a signed integer.
3725++ san |= [a=@s] ^- @rd (san:ma a)
3741Produces the sign of `a`.
3754++ sig |= [a=@rd] ^- ? (sig:ma a)
3760> (sig:rd .~1.2246e3)
3770Produces the exponent of `a`.
3783++ exp |= [a=@rd] ^- @s (exp:ma a)
3789> (exp:rd .~1.2246e3)
3799Rounds `a` to the nearest integer.
3812++ toi |= [a=@rd] ^- (unit @s) (toi:ma a)
3818> (toi:rd .~1.2246e3)
3826`@rd` to decimal float
3828Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
3829accurate results for rounded floats.
3842++ drg |= [a=@rd] ^- dn (drg:ma a)
3848> (drg:rd .~1.2246e3)
3849[%d s=%.y e=-1 a=12.246]
3856Decimal float to `@rd`
3858Converts `a` from decimal float to `@rd`.
3871++ grd |= [a=dn] ^- @rd (grd:ma a)
3877> (grd:rd [%d s=%.y e=-1 a=12.246])
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`).
3898 |_ r=$?(%n %u %d %z)
3907Instantiates the core `ff`, giving values to its samples based on the
3908configuration of the `rs` core.
3914 %*(. ff w 8, p 23, b --127, r r)
3922 {{{w/@ud p/@ud b/@sd} r/?($n $u $d $z)} <54.tyv 119.wim 31.ohr 1.jmk $143>}
3932Converts `a` from `@rs` to `fn`.
3936`a` is a `@rs`, an single-precision float.
3946 |= [a=@rs] (sea:ma a)
3953[%f s=%.y e=-149 a=100]
3962Converts `a` from `fn` to `@rs`.
3970A `@rs`, a single-precision float.
3976 |= [a=fn] ^- @rs (bit:ma a)
3982> (bit:rs [%f & -2 1.000])
3992Produces the sum of `a` plus `b`.
3996`a` is a `@rs`, a single-precision float.
4008 |= [a=@rs b=@rs] ^- @rs
4016> (add:rs .2.5e1 .2.5e2)
4026Subtracts `a` from `b`.
4038 |= [a=@rs b=@rs] ^- @rs
4046> (sub:rs .2.5e1 .2.5e2)
4056Produces the product of `a` multiplied by `b`.
4060`a` is a `@rs`, a single-precision float.
4072 |= [a=@rs b=@rs] ^- @rs
4080> (mul:rs .2.5e1 .2.5e2)
4090Produces the quotient of `a` divided by `b`.
4094`a` is a `@rs`, a single-precision float.
4106 |= [a=@rs b=@rs] ^- @rs
4114> (div:rs .4.5e1 .2.2e2)
4124Produces the sum of `c` plus the product of `a` multiplied by `b`;
4129`a` is a `@rs`, a single-precision float.
4143 |= [a=@rs b=@rs c=@rs] ^- @rs
4151> (fma:rs .2.5e1 .2.5e2 .8.2e1)
4161Produces the square root of `a`.
4165`a` is a `@rs`, a single-precision float.
4193Test whether `a` is less than `b`.
4197`a` is a `@rs`, a single-precision float.
4217> (lth:rs .9.9e1 .1.1e2)
4220> (lth:rs .9.9e1 .9.9e1)
4230Test whether `a` is less than or equal to `b`.
4234`a` is a `@rs`, a single-precision float.
4254> (lte:rs .9.9e1 .1.1e2)
4257> (lte:rs .9.9e1 .9.9e1)
4267Test whether `a` is equal to `b`.
4271`a` is a `@rs`, a single-precision float.
4291> (equ:rs .9.9e1 .1.1e2)
4294> (equ:rs .9.9e1 .9.9e1)
4302Greater than or equal
4304Test whether `a` is greater than or equal to `b`.
4308`a` is a `@rs`, a single-precision float.
4328> (gte:rs .9.9e1 .9.9e1)
4331> (gte:rs .9.9e1 .9.2e2)
4341Test whether `a` is greater than `b`.
4345`a` is a `@rs`, a single-precision float.
4365> (gth:rs .9.9e1 .9.2e2)
4368> (gth:rs .9.9e1 .9.9e1)
4371> (gth:rs .9.9e1 .1.9e1)
4379Unsigned integer to `@rs`
4381Converts `a` from an unsigned integer to `@rs`.
4385`a` is an unsigned integer.
4394++ sun |= [a=@u] ^- @rs (sun:ma a)
4408Signed integer to `@rs`'
4410Converts `a` from an unsigned integer to `@rs`.
4414`a` is a signed integer.
4423++ san |= [a=@s] ^- @rs (san:ma a)
4439Produces the sign of `a`.
4452++ sig |= [a=@rs] ^- ? (sig:ma a)
4471Produces the exponent of `a`.
4484++ exp |= [a=@rs] ^- @s (exp:ma a)
4500Rounds `a` to the nearest integer.
4513++ toi |= [a=@rs] ^- (unit @s) (toi:ma a)
4527`@rs` to decimal float
4529Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
4530accurate results for rounded floats.
4543++ drg |= [a=@rs] ^- dn (drg:ma a)
4550[%d s=%.n e=--0 a=343]
4557Decimal float to `@rs`
4559Converts `a` from `dn` to `@rs`.
4572++ grd |= [a=dn] ^- @rs (grd:ma a)
4578> (grd:rs [%d s=%.n e=--0 a=343])
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`).
4599 |_ r=$?(%n %u %d %z)
4606Instantiates the core `ff`, giving values to its samples based on the
4607configuration of the `rq` core.
4613 %*(. ff w 15, p 112, b --16.383, r r)
4622Converts `a` from `@rq` to `fn`.
4626`a` is a `@rq`, a quad-precision float.
4636 |= [a=@rq] (sea:ma a)
4642> (sea:rq .~~~1.05102e5)
4643[%f s=%.y e=-96 a=8.327.038.336.574.210.409.756.656.268.214.272]
4652Converts `a` from `fn` to `@rq`.
4660A `@rq`, a quad-precision float.
4666 |= [a=fn] ^- @rq (bit:ma a)
4672> (bit:rq [%f s=%.y e=-96 a=8.327.038.336.574.210.409.756.656.268.214.272])
4682Produces the sum of `a` plus `b`.
4686`a` is a `@rq`, a quad-precision float.
4698 |= [a=@rq b=@rq] ^- @rq
4706> (add:rq .~~~-1.821e5 .~~~1.05102e5)
4716Produces the difference of `a` minus `b`.
4720`a` is a `@rq`, a quad-precision float.
4732 |= [a=@rq b=@rq] ^- @rq
4740> (sub:rq .~~~1.821e5 .~~~1.05102e5)
4743> (sub:rq .~~~1.821e5 .~~~-1.05102e5)
4753Produces the product of `a` times `b`.
4757`a` is a `@rq`, a quad-precision float.
4769 |= [a=@rq b=@rq] ^- @rq
4777> (mul:rq .~~~1.821e5 .~~~-1.05102e5)
4787Produces the product of `a` divided by `b`.
4791`a` is a `@rq`, a quad-precision float.
4803 |= [a=@rq b=@rq] ^- @rq
4811> (div:rq .~~~1.821e5 .~~~1.05102e3)
4812.~~~1.732602614602957127361991208540275e2
4821Produces the sum of `c` plus the product of `a` multiplied by `b`;
4826`a` is a `@rq`, a quad-precision float.
4840 |= [a=@rq b=@rq c=@rq] ^- @rq
4848> (fma:rq .~~~1.821e5 .~~~-1.05102e2 .~~~6.2044e7)
4858Produces the square root of `a`.
4862`a` is a `@rq`, a quad-precision float.
4880> (sqt:rq .~~~6.2044e7)
4881.~~~7.876801381271461258959876570289002e3
4890Tests whether `a` is less than `b`.
4894`a` is a `@rq`, a quad-precision float.
4914> (lth:rq .~~~1.2044e7 (mul:rq .~~~9.02e2 .~~~7.114e3))
4917> (lth:rq .~~~1.2044e7 (mul:rq .~~~9.02e3 .~~~7.114e3))
4927Tests whether `a` is less than or equal to `b`.
4931`a` is a `@rq`, a quad-precision float.
4951> (lte:rq .~~~1.2044e7 (mul:rq .~~~9.02e2 .~~~7.114e3))
4954> (lte:rq .~~~1.2044e7 (mul:rq .~~~9.02e3 .~~~7.114e3))
4957> (lte:rq .~~~1.2044e7 .~~~1.2044e7)
4967Tests whether `a` is equal to `b`.
4971`a` is a `@rq`, a quad-precision float.
4991> (equ:rq .~~~1.2044e7 .~~~1.2044e7)
4994> (equ:rq .~~~2.2044e7 .~~~1.2044e7)
5002Greater than or equal
5004Tests whether `a` is greater than or equal to `b`.
5008`a` is a `@rq`, a quad-precision float.
5028> (gte:rq .~~~1.2044e7 .~~~1.2044e7)
5031> (gte:rq .~~~2.2044e7 .~~~1.2044e7)
5034> (gte:rq .~~~1.2044e7 .~~~2.2044e7)
5042Tests whether `a` is greater than `b`.
5046`a` is a `@rq`, a quad-precision float.
5066> (gth:rq .~~~1.2044e7 .~~~1.2044e7)
5069> (gth:rq .~~~2.2044e7 .~~~1.2044e7)
5072> (gth:rq .~~~1.2044e7 .~~~2.2044e7)
5080Unsigned integer to `@rq`
5082Converts `@` from an unsigned integer to `@rq`.
5086`a` is a `@u`, an unsigned integer.
5090A `@rq`, a quad-precision float.
5095++ sun |= [a=@u] ^- @rq (sun:ma a)
5109Signed integer to `rq`
5111Converts `@` from a signed integer to `@rq`.
5115`a` is a `@s`, a signed integer.
5119A `@rq`, a quad-precision float.
5124++ san |= [a=@s] ^- @rq (san:ma a)
5140Produces the sign of `a`.
5144`a` is a `@rq`, a quad-precision float.
5153++ sig |= [a=@rq] ^- ? (sig:ma a)
5159> (sig:rq .~~~-2.05e2)
5169Gets the exponent of `a`.
5173`a` is a `@rq`, a quad-precision float.
5177A `@s`, a signed integer.
5182++ exp |= [a=@rq] ^- @s (exp:ma a)
5188> (exp:rq .~~~-2.05e2)
5198Rounds `a` to the nearest integer.
5202`a` is a `@rq`, a quad-precision float.
5211++ toi |= [a=@rq] ^- (unit @s) (toi:ma a)
5217> (toi:rq .~~~-2.085e2)
5220> (toi:rq .~~~-2.08e2)
5228`@rq` to decimal float
5230Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
5231accurate results for rounded floats.
5235`a` is a `@rq`, a quad-precision float.
5244++ drg |= [a=@rq] ^- dn (drg:ma a)
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]
5261Decimal float to `@rq`
5263Converts `a` from `dn` to `@rq`.
5273A `@rq`, a quad-precision float.
5278++ grd |= [a=dn] ^- @rq (grd:ma a)
5284> (grd:rq [%d s=%.n e=--0 a=343])
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`).
5305 |_ r=$?(%n %u %d %z)
5314Instantiates the core `ff`, giving values to its samples based on the
5315configuration of the `rh` core.
5321 %*(. ff w 5, p 10, b --15, r r)
5330Converts `a` from `@rh` to `fn`.
5334`a` is a `@rh`, a half-precision float.
5344 |= [a=@rh] (sea:ma a)
5350> (sea:rh .~~1.22e-5)
5351[%f s=%.y e=-24 a=205]
5360Converts `a` from `fn` to `@rh`.
5368A `@rh`, a half-precision float.
5374 |= [a=fn] ^- @rh (bit:ma a)
5380> (bit:rh [%f s=%.y e=-24 a=205])
5388Produces the sum of `a` plus `b`.
5392`a` is a `@rh`, a half-precision float.
5404 |= [a=@rh b=@rh] ^- @rh
5412> (add:rh .~~1.82e2 .~~1.02e2)
5422Produces the difference of `a` minus `b`.
5426`a` is a `@rh`, a half-precision float.
5438 |= [a=@rh b=@rh] ^- @rh
5446> (sub:rh .~~1.821e2 .~~1.051e2)
5449> (sub:rh .~~1.821e2 .~~6.051e2)
5459Produces the product of `a` times `b`.
5463`a` is a `@rh`, a quad-precision float.
5475 |= [a=@rh b=@rh] ^- @rh
5483> (mul:rh .~~1.821e1 .~~-1.05102e2)
5493Produces the product of `a` divided by `b`.
5497`a` is a `@rh`, a half-precision float.
5509 |= [a=@rh b=@rh] ^- @rh
5517> (div:rh .~~1.821e3 .~~1.05102e2)
5527Produces the sum of `c` plus the product of `a` multiplied by `b`;
5532`a` is a `@rh`, a half-precision float.
5546 |= [a=@rh b=@rh c=@rh] ^- @rh
5554> (fma:rh .~~1.821e4 .~~-1.05102e2 .~~6.2044e3)
5564Produces the square root of `a`.
5568`a` is a `@rh`, a half-precision float.
5596Tests whether `a` is less than `b`.
5600`a` is a `@rh`, a half-precision float.
5620> (lth:rh .~~1.2e5 (mul:rh .~~9.02e2 .~~7.114e2))
5623> (lth:rh .~~1.2e3 (mul:rh .~~9.02e1 .~~7.114e2))
5633Tests whether `a` is less than or equal to `b`.
5637`a` is a `@rh`, a half-precision float.
5657> (lte:rh .~~1.2e5 (mul:rh .~~9.02e2 .~~7.114e2))
5660> (lte:rh .~~1.2e3 (mul:rh .~~9.02e1 .~~7.114e2))
5663> (lte:rh .~~1.2e3 .~~1.2e3)
5673Tests whether `a` is equal to `b`.
5677`a` is a `@rh`, a half-precision float.
5697> (equ:rh .~~1.24e4 .~~1.24e4)
5700> (equ:rh .~~2.24e4 .~~1.24e4)
5708Greater than or equal
5710Tests whether `a` is greater than or equal to `b`.
5714`a` is a `@rh`, a half-precision float.
5734> (gte:rh .~~1.24e4 .~~1.24e4)
5737> (gte:rh .~~2.24e4 .~~1.24e4)
5740> (gte:rh .~~1.24e4 .~~2.24e4)
5748Tests whether `a` is greater than `b`.
5752`a` is a `@rh`, a half-precision float.
5772> (gth:rh .~~1.24e4 .~~1.244e4)
5775> (gth:rh .~~2.24e4 .~~1.24e4)
5778> (gth:rh .~~1.24e4 .~~2.24e4)
5788Converts `@` from `@rh` to `@rs`.
5792`a` is a `@rh`, a half-precision float.
5796A `@rs`, a single-precision float.
5802 |= [a=@rh] (bit:rs (sea a))
5818Converts `@` from `@rs` to `@rh`.
5822`a` is a `@rs`, a single-precision float.
5826A `@rh`, a half-precision float.
5832 |= [a=@rs] (bit (sea:rs a))
5846Unsigned integer to `@rh`
5848Converts `@` from an unsigned integer to `@rh`.
5852`a` is a `@u`, an unsigned integer.
5856A `@rh`, a half-precision float.
5861++ sun |= [a=@u] ^- @rh (sun:ma a)
5875Signed integer to `@rh`
5877Converts `@` from a signed integer to `@rh`.
5881`a` is a `@s`, a signed integer.
5885A `@rh`, a half-precision float.
5890++ san |= [a=@s] ^- @rh (san:ma a)
5906Produces the sign of `a`.
5910`a` is a `@rh`, a half-precision float.
5919++ sig |= [a=@rh] ^- ? (sig:ma a)
5925> (sig:rh .~~-2.05e2)
5935Gets the exponent of `a`.
5939`a` is a `@rh`, a half-precision float.
5943A `@s`, a signed integer.
5948++ exp |= [a=@rh] ^- @s (exp:ma a)
5954> (exp:rh .~~-2.05e2)
5964Rounds `a` to the nearest integer.
5968`a` is a `@rh`, a half-precision float.
5977++ toi |= [a=@rh] ^- (unit @s) (toi:ma a)
5983> (toi:rh .~~-2.085e2)
5986> (toi:rh .~~-2.08e2)
5994`@rh` to decimal float
5996Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
5997accurate results for rounded floats.
6001`a` is a `@rh`, a half-precision float.
6010++ drg |= [a=@rh] ^- dn (drg:ma a)
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]
6027Decimal float to `@rh`
6029Converts `a` from `dn` to `@rh`.
6039A `@rh`, a a half-precision float.
6044++ grd |= [a=dn] ^- @rh (grd:ma a)
6050> (grd:rh [%d s=%.n e=--0 a=343])
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list