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
96 $% [$d a=? b=[c=@ [d=@ e=@] f=? i=@]]
105 > `rn`[%d | [2 [3 4] | 17.163]]
106 [%d a=%.n b=[c=2 [d=3 e=4] f=%.n i=17.163]]
113Arbitrary-precision floating-point
115Container arm for floating-point arithmetic functions.
117- Precision (`p`): number of bits in the significand; must be at least 2.
119- Minimum exponent (`v`): minimum value of e. Default is -16.494.
120- Width (`w`): Max value of `e` minus min value of `e`. 0 is for fixed-point.
122- Rounding mode (`r`): Possible modes are nearest (`$n`), up (`$u`),
123 down (`$d`), to zero (`$z`), and away from zero (`$a`). Default value is `%n`.
124- Behavior (`d`): return denormals (`$d`), flush denormals to zero (`$z`),
125 infinite exponent range (`$i`). Default value is `%d`.
131 =+ ^- [[p=@u v=@s w=@u] r=$?($n $u $d $z $a) d=$?($d $f $i)]
132 [[113 -16.494 32.765] %n %d]
144Rounds `a` to a the nearest float that can be represented with a 113-bit
145significand. There is no term to sign the significand, meaning that a positive
146sign will always be produced.
150`a` is a cell of a signed integer and an unsigned integer.
160 |= [a=[e=@s a=@u]] ^- fn (rau a &)
166 > =a 10.161.487.211.429.486.882.397.572.894.294.017.777
168 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
170 > (^rou:fl [--12 (add a 1)])
171 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
173 > (^rou:fl [--12 (add a 300)])
174 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
176 > (^rou:fl [--12 (add a 1.000)])
177 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.003]
186Rounds `a` based on what the state of of `r` in the core contained in `fl`. `t`
187is a sticky bit that represents a value less than ULP(a) = 2^(e.a) when passed
192`a` is a cell of a signed integer and an unsigned integer.
204 |= [a=[e=@s a=@u] t=?] ^- fn
206 $z (lug %fl a t) $d (lug %fl a t)
207 $a (lug %ce a t) $u (lug %ce a t)
215 > (rau:fl [-18 342.602.577] &)
216 [%f s=%.y e=-102 a=6.626.897.619.228.945.634.459.505.846.648.832]
221See `lug:fl` for possible rounding operations.
229Produces the sum of `a` and `b`. `e` is used to choose between an exact result
230(any-sized significand) or a rounded result (113-bit significand).
232There is no term to sign the significands, so a positive sign will always be
251 |= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn
252 =+ q=(dif:si e.a e.b)
253 |- ?. (syn:si q) $(b a, a b, q +(q)) :: a has larger exp
255 [%f & e.b (^add (lsh 0 (abs:si q) a.a) a.b)]
256 =+ [ma=(met 0 a.a) mb=(met 0 a.b)]
257 =+ ^= w %+ dif:si e.a %- sun:si :: expanded exp of a
258 ?: (gth prc ma) (^sub prc ma) 0
259 =+ ^= x %+ sum:si e.b (sun:si mb) :: highest exp for b
260 ?: =((cmp:si w x) --1) :: don't need to add
262 $z (lug %fl a &) $d (lug %fl a &)
263 $a (lug %lg a &) $u (lug %lg a &)
266 (rou [e.b (^add (lsh 0 (abs:si q) a.a) a.b)])
272 > (^add:fl [--33 2.718] [--23 11] %.y)
273 [%f s=%.y e=--23 a=2.783.243]
275 > (^add:fl [--33 2.718] [--23 11] %.n)
276 [%f s=%.y e=-68 a=6.890.975.897.521.519.304.902.126.405.156.864]
285Produces the difference of `a` minus `b.` `e` is used to choose between an exact
286result (any-sized significand) or a rounded result (113-bit significand).
290`a` is a cell of a signed integer and an unsigned integer.
292`b` is a cell of a signed integer and an unsigned integer.
304 |= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn
305 =+ q=(dif:si e.a e.b)
307 (fli $(b a, a b, q +(q), r swr))
308 =+ [ma=(met 0 a.a) mb=(met 0 a.b)]
309 =+ ^= w %+ dif:si e.a %- sun:si
310 ?: (gth prc ma) (^sub prc ma) 0
311 =+ ^= x %+ sum:si e.b (sun:si +(mb))
312 ?: &(!e =((cmp:si w x) --1))
314 $z (lug %sm a &) $d (lug %sm a &)
315 $a (lug %ce a &) $u (lug %ce a &)
318 =+ j=(lsh 0 (abs:si q) a.a)
320 (fli $(a.b j, j a.b, r swr))
323 ?: e [%f & e.b i] (rou [e.b i])
329 > (^sub:fl [--33 2.718] [--23 11] %.y)
330 [%f s=%.y e=--23 a=2.783.221]
332 > (^sub:fl [--33 2.718] [--63 11] %.y)
333 [%f s=%.n e=--33 a=11.811.157.346]
342Produces the product of `a` multiplied by `b`. There is no term to sign the
343significands, so a positive sign will always be produced.
347`a` is a cell of a signed integer and an unsigned integer.
349`b` is a cell of a signed integer and an unsigned integer.
359 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- fn
360 (rou (sum:si e.a e.b) (^mul a.a a.b))
366 > (^mul:fl [--3 2.718] [--23 11])
367 [%f s=%.y e=-72 a=9.475.054.411.405.900.661.487.108.108.582.912]
376Produces the quotient of `a` divided by `b`. There is no term to sign the
377significands, so a positive sign will always be produced.
381`a` is a cell of a signed integer and an unsigned integer.
383`b` is a cell of a signed integer and an unsigned integer.
393 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- fn
394 =+ [ma=(met 0 a.a) mb=(met 0 a.b)]
395 =+ v=(dif:si (sun:si ma) (sun:si +((^add mb prc))))
397 a(e (sum:si v e.a), a (lsh 0 (abs:si v) a.a))
398 =+ [j=(dif:si e.a e.b) q=(dvr a.a a.b)]
399 (rau [j p.q] =(q.q 0))
405 > (^div:fl [--13 2.718] [--23 11])
406 [%f s=%.y e=-115 a=10.023.198.055.040.952.765.870.659.817.343.907]
415Produces the square root of `a`.
419`a` is a cell of a signed integer and an unsigned integer.
429 |= [a=[e=@s a=@u]] ^- fn
431 =+ [w=(met 0 a.a) x=(^mul +(prc) 2)]
432 =+ ?:((^lth w x) (^sub x w) 0)
433 =+ ?: =((dis - 1) (dis (abs:si e.a) 1)) -
435 a(e (dif:si e.a (sun:si -)), a (lsh 0 - a.a))
436 =+ [y=(^sqt a.a) z=(fra:si e.a --2)]
437 (rau [z p.y] =(q.y 0))
443 > (^sqt:fl [-18 342.602.577])
444 [%f s=%.y e=-107 a=5.865.903.143.604.945.574.132.671.852.050.553]
453Tests if `a` is less than `b`.
457`a` is a cell of a signed integer and an unsigned integer.
459`b` is a cell of a signed integer and an unsigned integer.
469 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ?
470 ?: =(e.a e.b) (^lth a.a a.b)
471 =+ c=(cmp:si (ibl a) (ibl b))
472 ?: =(c -1) & ?: =(c --1) |
473 ?: =((cmp:si e.a e.b) -1)
474 (^lth (rsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b)
475 (^lth (lsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b)
481 > (^lth:fl [-4 684] [--0 35])
484 > (^lth:fl [-4 684] [--0 90])
494Tests if `a` is equal to `b`.
498`a` is a cell of a signed integer and an unsigned integer.
500`b` is a cell of a signed integer and an unsigned integer.
510 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ?
511 ?. =((ibl a) (ibl b)) |
512 ?: =((cmp:si e.a e.b) -1)
513 =((lsh 0 (abs:si (dif:si e.a e.b)) a.b) a.a)
514 =((lsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b)
520 > (^equ:fl [-4 480] [-0 50])
523 > (^equ:fl [-4 480] [-0 30])
531Integer binary logarithm
533Produces the lowest power to which the number 2 must be raised to obtain `a` or
538`a` is a cell of a signed integer and an unsigned integer.
548 |= [a=[e=@s a=@u]] ^- @s
549 (sum:si (sun:si (dec (met 0 a.a))) e.a)
555 > (ibl:fl [-18 342.602.577])
563Change representation to odd
565Produces another representation of the floating point `a` where the significand
566is odd. Every floating-point number has a unique representation of this kind. If
567the significand of `a` is already odd, nothing changes.
571`a` is a cell of a signed integer and an unsigned integer.
575A cell of a signed integer and an unsigned integer.
582 |- ?: =((end 0 1 a.a) 1) a
583 $(a.a (rsh 0 1 a.a), e.a (sum:si e.a --1))
589 > (uni:fl [-8 342.602.578])
592 > (uni:fl [-8 342.602.577])
602Produces the fully precise form of `a`, or the denormalized form of `a`.
606`a` is a cell of a signed integer and an unsigned integer.
610A cell of a signed integer and an unsigned integer.
619 =+ ?: =(den %i) (^sub prc ma)
621 =+ w=(dif:si e.a emn)
622 ?: (syn:si w) (abs:si w) 0
623 (min q (^sub prc ma))
624 a(e (dif:si e.a (sun:si -)), a (lsh 0 - a.a))
631 [e=-106 a=7.788.445.287.802.241.442.795.744.493.830.144]
633 > (xpd:fl [-8 342.602.577])
634 [e=-92 a=6.626.897.619.228.945.634.459.505.846.648.832]
636 > (xpd:fl [-92 6.626.897.619.228.945.634.459.505.846.648.832])
637 [e=-92 a=6.626.897.619.228.945.634.459.505.846.648.832]
644Central rounding mechanism
646Performs various rounding operations on `a`. An operation is chosen based on the
647value selected for `t`. `s` is a sticky bit that represents a value less than
650Possible rounding operations:
656- Nearest (`$ne`) -- Rounds ties away from 0 if the number is even, rounds
657 toward 0 if the number is odd.
661`t` is one of the following: `$fl`, `$ce`, `$sm`, `$lg`, `$ne`, `$na`, or `$nt`.
663`a` is a cell of a signed integer and an unsigned integer.
675 :: central rounding mechanism
676 :: can perform: floor, ceiling, smaller, larger,
677 :: nearest (round ties to: even, away from 0, toward 0)
678 :: s is sticky bit: represents a value less than ulp(a) = 2^(e.a)
682 |= [t=$?($fl $ce $sm $lg $ne $na $nt) a=[e=@s a=@u] s=?] ^- fn
685 ?. =(den %f) - :: flush denormals
687 ?: =((met 0 ->+>) prc) - [%f & zer]
690 ?> |(s (gth m prc)) :: require precision
692 ?: (gth m prc) (^sub m prc) 0 :: reduce precision
693 %- abs:si ?: =(den %i) --0 :: enforce min. exp
694 ?: =((cmp:si e.a emn) -1) (dif:si emn e.a) --0
695 =^ b a :- (end 0 q a.a)
696 a(e (sum:si e.a (sun:si q)), a (rsh 0 q a.a))
705 $ne ?: s [%f & ?:((lte b (bex (dec q))) zer spd)]
706 [%f & ?:((^lth b (bex (dec q))) zer spd)]
707 $nt ?: s [%f & ?:((lte b (bex (dec q))) zer spd)]
708 [%f & ?:((^lth b (bex (dec q))) zer spd)]
709 $na [%f & ?:((^lth b (bex (dec q))) zer spd)]
719 ?: &(=(e.a emn) !=(den %i)) a(a (dec a.a))
720 =+ y=(dec (^mul a.a 2))
721 ?. (lte (met 0 y) prc) a(a (dec a.a))
723 $ce ?: &(=(b 0) s) a a(a +(a.a))
726 ?: &(=(b y) s) :: round halfs to even
727 ?~ (dis a.a 1) a a(a +(a.a))
728 ?: (^lth b y) a a(a +(a.a))
731 ?: (^lth b y) a a(a +(a.a))
734 ?: =(b y) ?: s a a(a +(a.a))
735 ?: (^lth b y) a a(a +(a.a))
738 =. a ?. =((met 0 a.a) +(prc)) a
739 a(a (rsh 0 1 a.a), e (sum:si e.a --1))
742 ?: =(den %i) [%f & a]
743 ?: =((cmp:si emx e.a) -1) [%i &] [%f & a] :: enforce max. exp
753Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
754accurate results for rounded floats.
758`a` is a cell of a signed integer and an unsigned integer.
762A cell of a signed integer and an unsigned integer.
769 |= [a=[e=@s a=@u]] ^- [@s @u]
772 =+ r=(lsh 0 ?:((syn:si e.a) (abs:si e.a) 0) a.a)
773 =+ s=(lsh 0 ?.((syn:si e.a) (abs:si e.a) 0) 1)
774 =+ mn=(lsh 0 ?:((syn:si e.a) (abs:si e.a) 0) 1)
777 ?& =(a.a (bex (dec prc))) :: if next smallest
778 |(!=(e.a emn) =(den %i)) :: float is half ULP,
779 == :: tighten lower bound
786 =+ [k=--0 q=(^div (^add s 9) 10)]
794 |- ?: (gte (^add (^mul r 2) mp) (^mul s 2))
795 $(s (^mul s 10), k (sum:si k --1))
797 |- :: r/s+o = a*10^-k
798 =+ v=(dvr (^mul r 10) s)
806 =+ l=(^lth (^mul r 2) mn) :: in lower bound
807 =+ ^= h :: in upper bound
808 ?| (^lth (^mul s 2) mp)
809 (gth (^mul r 2) (^sub (^mul s 2) mp))
812 $(o (^add (^mul o 10) u))
813 =+ q=&(h |(!l (gth (^mul r 2) s)))
814 =. o (^add (^mul o 10) ?:(q +(u) u))
822 [%f s=%.y e=-95 a=8.640.464.947.480.640.129.276.716.135.743.488]
823 > (^drg:fl [e=-95 a=8.640.464.947.480.640.129.276.716.135.743.488])
826 > (sun:fl 102.057.673.128.349)
827 [%f s=%.y e=-66 a=7.530.527.107.827.833.883.675.587.233.447.936]
828 > (^drg:fl [e=-66 a=7.530.527.107.827.833.883.675.587.233.447.936])
829 [--0 102.057.673.128.349]
838Rounds float `a` to the nearest decimal float with an exponent of 0.
842`a` is a cell of a signed integer and an unsigned integer.
852 |= [a=[e=@s a=@u]] ^- fn
853 ?. =((cmp:si e.a --0) -1) [%f & a]
856 ?: |(=(r %d) =(r %z)) [%f & --0 y]
858 ?: |(=(r %u) =(r %a)) [%f & --0 ?~(z y +(y))]
860 ?: &(=(z i) =((dis y 1) 0)) [%f & --0 y]
861 ?: (^lth z i) [%f & --0 y] [%f & --0 +(y)]
867 > (^toj:fl [-11 7.530.107.827.833.587])
868 [%f s=%.y e=--0 a=3.676.810.462.809]
870 > (^toj:fl [-11 7.530.107.827.833.589])
871 [%f s=%.y e=--0 a=3.676.810.462.809]
880Produces `a` if `a` is a is of floating-point representation. If `a` is another
881case of `fn`, such as infinity or not-a-number, a crash is produced.
889A cell of a signed integer and an unsigned integer.
895 |= [a=fn] ^- [$f s=? e=@s a=@u]
904 > (ned:fl [%f s=%.y e=-11 a=7.530.107.827.833.587])
905 [%f s=%.y e=-11 a=7.530.107.827.833.587]
922Multiplies `a` by 2 to the `b` power without rounding. This results in shifting
923the exponent term by `b`.
929`b` is a signed integer.
940 ?: |(?=([$n *] a) ?=([$i *] a)) a
947 > (shf:fl [[%f & -2 7] --2])
950 > (shf:fl [[%f & -2 7] -2])
953 > (shf:fl [%f & -11 7.530.107.827.833.587] --5)
954 [%f s=%.y e=-6 a=7.530.107.827.833.587]
963Produces `a` with its signed changed from positive to negative, or vice versa.
978 ?-(-.a $f a(s !s.a), $i a(s !s.a), $n a)
984 > (fli:fl [%f %.y -2 7])
987 > (fli:fl [%f %.n --2 30.617])
988 [%f s=%.y e=--2 a=30.617]
990 > (fli:fl [%f | --2 30.617])
991 [%f s=%.y e=--2 a=30.617]
1000Switches the rounding mode of `r:fl`.
1005 ++ swr ?+(r r $d %u, $u %d)
1016 > =new-fl fl :: new fl core with changed state
1017 > =new-fl new-fl(r %u)
1026Force precision of 2 or greater
1028Produces `p`, the core's precision, if `p` is greater than or equal to 2.
1029Otherwise, a crash is produced.
1034 ++ prc ?>((gth p 1) p)
1044 > =new-fl new-fl(p 1)
1048 > =new-fl new-fl(p 2)
1059Produces `d:fl`. Denormalizes if `d:fl` is `%d`. Flushes denormals to zero if
1062- Denormalizes if `d:fl` is `%d`.
1063- Flushes denormals to zero if `d:fl` is `%f`.
1064- Infinite exponent range if `$d` is `$i`.
1066The default value of `d` is `%d`.
1081 > =new-fl new-fl(d %f)
1092Produces `v:fl`, the minimum exponent. The default minimum exponent is -16.494.
1113Returns the maximum exponent of `fl`. The default maximum exponent is --16.271.
1118 ++ emx (sum:si emn (sun:si w))
1137Produces the smallest possible denormalized float.
1158Produces the smallest representable normal float.
1163 ++ spn [e=emn a=(bex (dec prc))]
1170 [e=-16.494 a=5.192.296.858.534.827.628.530.496.329.220.096]
1179Produces the largest representable normal float.
1184 ++ lfn [e=emx a=(fil 0 prc 1)]
1191 [e=--16.271 a=10.384.593.717.069.655.257.060.992.658.440.191]
1200Produces the sum of `emx:fl` plus `prc:fl`.
1205 ++ lfe (sum:si emx (sun:si prc)) :: 2^lfe is > than all
1221Produces zero represented as a float.
1244Rounds `a`. The way in which `a` is rounded depends on the value of `r:fl`.
1262 =.(r swr (fli (^rou +>.a)))
1268 > =a 10.161.487.211.429.486.882.397.572.894.294.017.777
1269 > (rou:fl [%f & --12 a])
1270 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
1272 > (rou:fl [%f & --12 (add a 1)])
1273 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
1275 > (rou:fl [%f & --12 (add a 300)])
1276 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
1278 > (rou:fl [%f & --12 (add a 1.000)])
1279 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.003]
1288Produces the sign of `a`.
1303 ?-(-.a $f s.a, $i s.a, $n &)
1309 > (syn:fl (sun:fl 106))
1312 > (syn:fl [%f | --0 106])
1322Produces the absolute value of `a`.
1337 ?: ?=([$f *] a) [%f & e.a a.a]
1338 ?: ?=([$i *] a) [%i &] [%n ~]
1344 > (abs:fl [%f | --0 106])
1345 [%f s=%.y e=--0 a=106]
1347 > (abs:fl [%f & --0 106])
1348 [%f s=%.y e=--0 a=106]
1357Produces the sum of `a` plus `b`.
1373 |= [a=fn b=fn] ^- fn
1374 ?: |(?=([$n *] a) ?=([$n *] b)) [%n ~]
1375 ?: |(?=([$i *] a) ?=([$i *] b))
1376 ?: &(?=([$i *] a) ?=([$i *] b))
1379 ?: |(=(a.a 0) =(a.b 0))
1380 ?. &(=(a.a 0) =(a.b 0)) %- rou ?~(a.a b a)
1381 [%f ?:(=(r %d) &(s.a s.b) |(s.a s.b)) zer]
1387 ?: s.a (^add +>.a +>.b |)
1388 =.(r swr (fli (^add +>.a +>.b |)))
1389 ?: s.a (^sub +>.a +>.b |)
1396 > (add:fl [%f & --0 106] [%f | --3 55])
1397 [%f s=%.n e=-104 a=6.774.324.807.619.657.921.598.381.929.529.344]
1406Produces the exact sum of `a` plus `b`.
1422 |= [a=fn b=fn] ^- fn
1423 ?: |(?=([$n *] a) ?=([$n *] b)) [%n ~]
1424 ?: |(?=([$i *] a) ?=([$i *] b))
1425 ?: &(?=([$i *] a) ?=([$i *] b))
1428 ?: |(=(a.a 0) =(a.b 0))
1429 ?. &(=(a.a 0) =(a.b 0)) ?~(a.a b a)
1430 [%f ?:(=(r %d) &(s.a s.b) |(s.a s.b)) zer]
1436 ?: s.a (^add +>.a +>.b &)
1437 (fli (^add +>.a +>.b &))
1438 ?: s.a (^sub +>.a +>.b &)
1446 > (ead:fl [%f & --0 106] [%f | --3 55])
1447 [%f s=%.n e=--0 a=334]
1456Produces the difference of `a` minus `b`.
1472 |= [a=fn b=fn] ^- fn (add a (fli b))
1478 > (sub:fl [%f & --13 2.718] [%f & --23 11])
1479 [%f s=%.n e=-86 a=5.416.671.014.775.224.232.595.412.796.571.648]
1488Produces the product of `a` multiplied by `b`.
1504 |= [a=fn b=fn] ^- fn
1505 ?: |(?=([$n *] a) ?=([$n *] b)) [%n ~]
1509 ?: =(a.b 0) [%n ~] [%i =(s.a s.b)]
1511 ?: =(a.a 0) [%n ~] [%i =(s.a s.b)]
1512 ?: |(=(a.a 0) =(a.b 0)) [%f =(s.a s.b) zer]
1513 ?: =(s.a s.b) (^mul +>.a +>.b)
1514 =.(r swr (fli (^mul +>.a +>.b)))
1523Produces the exact product of `a` multiplied by `b`.
1539 |= [a=fn b=fn] ^- fn
1540 ?: |(?=([$n *] a) ?=([$n *] b)) [%n ~]
1544 ?: =(a.b 0) [%n ~] [%i =(s.a s.b)]
1546 ?: =(a.a 0) [%n ~] [%i =(s.a s.b)]
1547 ?: |(=(a.a 0) =(a.b 0)) [%f =(s.a s.b) zer]
1548 [%f =(s.a s.b) (sum:si e.a e.b) (^^mul a.a a.b)]
1557Produces the quotient of `a` divided by `b`.
1573 |= [a=fn b=fn] ^- fn
1574 ?: |(?=([$n *] a) ?=([$n *] b)) [%n ~]
1576 ?: ?=([$i *] b) [%n ~] [%i =(s.a s.b)]
1577 ?: ?=([$i *] b) [%f =(s.a s.b) zer]
1578 ?: =(a.a 0) ?: =(a.b 0) [%n ~] [%f =(s.a s.b) zer]
1579 ?: =(a.b 0) [%i =(s.a s.b)]
1580 ?: =(s.a s.b) (^div +>.a +>.b)
1581 =.(r swr (fli (^div +>.a +>.b)))
1590Produces the sum of `c` plus the product of `a` multiplied by `b`;
1609 |= [a=fn b=fn c=fn] ^- fn
1616 > (fma:fl [%f & --13 2.718] [%f & --23 11] [%f & --13 2.718])
1617 [%f s=%.y e=-62 a=9.475.054.514.089.037.465.004.673.635.188.736]=
1626Produces the square root of `a`.
1641 ?: ?=([$n *] a) [%n ~]
1642 ?: ?=([$i *] a) ?:(s.a a [%n ~])
1644 ?: s.a (^sqt +>.a) [%n ~]
1650 > (sqt:fl [%f s=%.y e=-18 a=342.602.577])
1651 [%f s=%.y e=-107 a=5.865.903.143.604.945.574.132.671.852.050.553]
1660Produces the inverse of `a` by dividing `1` by `a`.
1675 (div [%f & --0 1] a)
1681 > (inv:fl [%f s=%.y e=--0 a=10])
1682 [%f s=%.y e=-116 a=8.307.674.973.655.724.205.648.794.126.752.154]
1683 > (drg:fl [%f s=%.y e=-116 a=8.307.674.973.655.724.205.648.794.126.752.154])
1686 > (inv:fl [%f s=%.y e=--1 a=10])
1687 [%f s=%.y e=-117 a=8.307.674.973.655.724.205.648.794.126.752.154]
1688 > (drg:fl [%f s=%.y e=-117 a=8.307.674.973.655.724.205.648.794.126.752.154])
1691 > (inv:fl [%f s=%.y e=--2 a=10])
1692 [%f s=%.y e=-118 a=8.307.674.973.655.724.205.648.794.126.752.154]
1693 > (drg:fl [%f s=%.y e=-118 a=8.307.674.973.655.724.205.648.794.126.752.154])
1694 [%d s=%.y e=-3 a=25]
1701Signed integer to float
1703Produces `a` in floating-point representation.
1707`a` is an unsigned integer.
1725 [%f s=%.y e=--0 a=0]
1727 > (sun:fl 5.048.729)
1728 [%f s=%.y e=-90 a=6.250.023.776.601.238.669.911.180.544.311.296]
1738Signed integer to float
1740Produces the floating-point representation of `a`, an unsigned integer.
1744`a` is an unsigned integer.
1756 (rou [%f -.b --0 +.b])
1763 [%f s=%.y e=-106 a=8.112.963.841.460.668.169.578.900.514.406.400]
1766 [%f s=%.n e=-106 a=8.112.963.841.460.668.169.578.900.514.406.400]
1775Tests if `a` is less than `b`. Returns `~` in the event of `a` or `b` being a
1792 |= [a=fn b=fn] ^- (unit ?)
1793 ?: |(?=([$n *] a) ?=([$n *] b)) ~ :- ~
1795 ?: ?=([$i *] a) !s.a ?: ?=([$i *] b) s.b
1796 ?: |(=(a.a 0) =(a.b 0))
1797 ?: &(=(a.a 0) =(a.b 0)) |
1798 ?: =(a.a 0) s.b !s.a
1800 ?: s.a (^lth +>.a +>.b) (^lth +>.b +>.a)
1806 > (lth:fl (sun:fl 116) (sun:fl 4.820))
1809 > (lth:fl (sun:fl 218.116) (sun:fl 4.820))
1812 > (lth:fl (sun:fl 218.116) [%n ~])
1822Tests whether `a` is less than or equal to `b`. Returns `~` in the event of `a`
1823or `b` being a NaN (`[%n ~]`).
1839 |= [a=fn b=fn] ^- (unit ?)
1840 %+ bind (lth b a) |= a=? !a
1846 > (lte:fl (sun:fl 102) [%f %.y -5 973.655.724])
1849 > (lte:fl (sun:fl 102) [%f %.y -24 973.655.724])
1852 > (lte:fl [%f %.y --2 25] (sun:fl 100))
1855 > (lte:fl [%f %.y --2 25] [%f %.y --3 2])
1858 > (lte:fl [%f %.y --2 25] [%n ~])
1868Tests if `a` is equal to `b`. Returns `~` in the event of `a` or `b` being a NaN
1885 |= [a=fn b=fn] ^- (unit ?)
1886 ?: |(?=([$n *] a) ?=([$n *] b)) ~ :- ~
1888 ?: |(?=([$i *] a) ?=([$i *] b)) |
1889 ?: |(=(a.a 0) =(a.b 0))
1890 ?: &(=(a.a 0) =(a.b 0)) & |
1891 ?: |(=(e.a e.b) !=(s.a s.b)) |
1898 > (equ:fl [%f %.y --2 25] (sun:fl 100))
1901 > (equ:fl [%f %.y --2 25] (sun:fl 101))
1909Greater or equal than
1911Tests whether `a` is greater than or equal to `b`. Returns `~` in the event of
1912`a` or `b` being a NaN (`[%n ~]`).
1928 |= [a=fn b=fn] ^- (unit ?) (lte b a)
1934 > (gte:fl [%f %.y --2 25] (sun:fl 100))
1937 > (gth:fl [%f %.y --6 73.989] [%f %.y --5 919.599])
1940 > (gth:fl [%f %.y --6 73.989] [%n ~])
1950Tests whether `a` is greater than `b`. Returns `~` in the event of `a` or `b`
1951being a NaN (`[%n ~]`).
1967 |= [a=fn b=fn] ^- (unit ?) (lth b a)
1973 > (gth:fl [%f %.y --2 25] (sun:fl 100))
1976 > (gth:fl [%f %.y --6 73.989] [%f %.y --5 119.599])
1986Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
1987accurate results for rounded floats.
2002 ?: ?=([$n *] a) [%n ~]
2003 ?: ?=([$i *] a) [%i s.a]
2004 ?~ a.a [%d s.a --0 0]
2005 [%d s.a (^drg +>.a)]
2011 > (drg:fl [%f | --6 73.989])
2012 [%d s=%.n e=--0 a=4.735.296]
2021Converts decimal `a` to `fn`.
2036 ?: ?=([$n *] a) [%n ~]
2037 ?: ?=([$i *] a) [%i s.a]
2041 (mul [%f s.a --0 a.a] [%f & e.a (pow 5 q)])
2042 (div [%f s.a --0 a.a] [%f & (sun:si q) (pow 5 q)])
2048 > (grd:fl [%d s=%.n e=--0 a=73.989])
2049 [%f s=%.n e=-96 a=5.862.012.516.267.904.074.208.723.341.410.304]
2051 > (grd:fl [%d s=%.n e=--0 a=100])
2052 [%f s=%.n e=-106 a=8.112.963.841.460.668.169.578.900.514.406.400]
2059Round to signed integer
2061Rounds `a` to the nearest signed integer.
2075 |= [a=fn] ^- (unit @s)
2077 ?. ?=([$f *] b) ~ :- ~
2078 =+ c=(^^mul (bex (abs:si e.b)) a.b)
2085 > (toi:fl [%f s=%.y e=-78 a=8.112.963.841.460.668.169.578.900.514.406.400])
2086 [~ u=--26.843.545.600]
2095Rounds `a` to the nearest decimal integer.
2113 =.(r swr (fli (^toj +>.a)))
2120 > (toj:fl [%f s=%.y e=-78 a=8.112.963.841.460.668.169.578.900.514.406.400])
2121 [%f s=%.y e=--0 a=26.843.545.600]
2123 > (toj:fl [%f s=%.y e=-78 a=8.112.963.841.460.668.169.578.900.514])
2124 [%f s=%.y e=--0 a=26.844]
2126 > (toj:fl [%f s=%.y e=-78 a=8.112.963.841.460])
2127 [%f s=%.y e=--0 a=0]
2129 > (toj:fl [%f s=%.y e=-9 a=9.002])
2130 [%f s=%.y e=--0 a=16]
2139Container core for IEEE-754 formatting operations.
2141- `w` is width: The number of bits in the exponent field.
2142- `p` is precision: The number of bits in the significand field.
2143- `w` is bias: Added to exponent when storing.
2144- `r` is rounding mode: Possible modes are nearest (`$n`), up (`$u`),
2145 down (`$d`), to zero (`$z`), and away from zero (`$a`). Default value is `%a`.
2151 |_ [[w=@u p=@u b=@s] r=$?($n $u $d $z $a)]
2157 > =ffcore ~(. ff [8 8 0] %n)
2159 <24.ltg {{{@ud @ud @ud} r/$n} <54.tyv 119.wim 31.ohr 1.jmk $143>}>
2167`++ff` has no use outside of the functionality provided to other cores: `++rd`,
2168`++rs`, `++rq`, and `++rh`. It's not intended to be used directly; it's just
2169meant to power those cores.
2177Produces the sign bit of `++ff`.
2182 ++ sb (bex (^add w p))
2198Produces the minimum possible exponent of `ff`.
2203 ++ me (dif:si (dif:si --1 b) (sun:si p))
2219Instantiates the core `fl`, giving values to its samples based on the
2220configuration of the `ff` core.
2226 %*(. fl p +(p), v me, w (^sub (bex w) 3), d %d, r r)
2232 > ~(pa ff [11 52 --1.023] %n)
2235 { {{p/@ v/@s w/@} r/?($n $u $a $d $z) d/$d}
2236 <54.tyv 119.wim 31.ohr 1.jmk $143>
2243`++pa` exists exclusively for internal use of `++ff`, and `++ff` exists for
2244internal use in other cores.
2252Converts `a` from `@r` to `fn`.
2256`a` is a `@r`, an IEEE float.
2267 =+ [f=(cut 0 [0 p] a) e=(cut 0 [p w] a)]
2270 ?: =(f 0) [%f s --0 0] [%f s me f]
2272 ?: =(f 0) [%i s] [%n ~]
2273 =+ q=:(sum:si (sun:si e) me -1)
2274 =+ r=(^add f (bex p))
2282 [%f s=%.y e=--0 a=0]
2289`fn` to `@r`, rounding
2291Converts `a` from `fn` to `@r` and applies rounding.
2304 ++ bit |= [a=fn] (bif (rou:pa a))
2310 > (bit:ma:rd [%f | -6 202])
2318`fn` to `@r`, no rounding
2320Converts `a` from `fn` to `@r`. No rounding is applied.
2324`a` is a `@r`, an IEEE float.
2336 =+ q=(lsh 0 p (fil 0 w 1))
2337 ?: s.a q (^add q sb)
2338 ?: ?=([$n *] a) (lsh 0 (dec p) (fil 0 +(w) 1))
2339 ?~ a.a ?: s.a `@r`0 sb
2344 ?: s.a `@r`a.a (^add a.a sb)
2345 =+ q=(sum:si (dif:si e.a me) --1)
2346 =+ r=(^add (lsh 0 p (abs:si q)) (end 0 p a.a))
2347 ?: s.a r (^add r sb)
2363Produces the sign of `a`.
2367`a` is a `@r`, an IEEE float.
2378 =(0 (cut 0 [(^add p w) 1] a))
2394Produces the exponent of `a`.
2398`a` is a `@r`, an IEEE float.
2409 (dif:si (sun:si (cut 0 [p w] a)) b)
2425Produces the sum of `a` plus `b`.
2429`a` is a `@r`, an IEEE float.
2431`b` is a `@r`, an IEEE float.
2435A `@r`, an IEEE float.
2442 (bif (add:pa (sea a) (sea b)))
2448 > (add:ma:rd `@r`5 `@r`11)
2458Produces the sum of `a` plus `b`.
2462`a` is a `@r`, an IEEE float.
2464`b` is a `@r`, an IEEE float.
2468A `@r`, an IEEE float.
2475 (bif (sub:pa (sea a) (sea b)))
2481 > (sub:ma:rd `@r`5 `@r`11)
2491Produces the product of `a` multiplied by `b`.
2495`a` is a `@r`, an IEEE float.
2497`b` is a `@r`, an IEEE float.
2501A `@r`, an IEEE float.
2508 (bif (mul:pa (sea a) (sea b)))
2514 > (mul:ma:rd `@r`11 `@r`2)
2524Produces the quotient of `a` divided by `b`.
2528`a` is a `@r`, an IEEE float.
2530`b` is a `@r`, an IEEE float.
2534A `@r`, an IEEE float.
2541 (bif (div:pa (sea a) (sea b)))
2547 > (div:ma:rd `@r`175 `@r`26)
2557Produces the sum of `c` plus the product of `a` multiplied by `b`;
2562`a` is a `@r`, an IEEE float.
2564`b` is a `@r`, an IEEE float.
2566`c` is a `@r`, an IEEE float.
2570A `@r`, an IEEE float.
2577 (bif (fma:pa (sea a) (sea b) (sea c)))
2583 > (fma:ma:rd `@r`175 `@r`26 `@r`100)
2593Produces the square root of `a`.
2597`a` is a `@r`, an IEEE float.
2601A `@r`, an IEEE float.
2608 (bif (sqt:pa (sea a)))
2614 > (sqt:ma:rd `@r`175)
2624Tests whether `a` is less than `b`.
2628`a` is a `@r`, an IEEE float.
2630`b` is a `@r`, an IEEE float.
2640 |= [a=@r b=@r] (fall (lth:pa (sea a) (sea b)) |)
2646 > (lth:ma:rd `@rd`1 `@rd`2)
2649 > (lth:ma:rd `@rd`10 `@rd`2)
2657Less than or equal to
2659Tests whether `a` is less than or equal to `b`.
2663`a` is a `@r`, an IEEE float.
2665`b` is a `@r`, an IEEE float.
2675 |= [a=@r b=@r] (fall (lte:pa (sea a) (sea b)) |)
2681 > (lte:ma:rd `@rd`10 `@rd`2)
2684 > (lte:ma:rd `@rd`10 `@rd`10)
2694Tests whether `a` is equal to `b`.
2698`a` is a `@r`, an IEEE float.
2700`b` is a `@r`, an IEEE float.
2710 |= [a=@r b=@r] (fall (equ:pa (sea a) (sea b)) |)
2716 > (equ:ma:rd `@rd`10 `@rd`2)
2719 > (equ:ma:rd `@rd`10 `@rd`10)
2727Greater or equal than
2729Tests whether `a` is greater than or equal to `b`.
2733`a` is a `@r`, an IEEE float.
2735`b` is a `@r`, an IEEE float.
2745 |= [a=@r b=@r] (fall (gte:pa (sea a) (sea b)) |)
2751 > (gte:ma:rd `@rd`10 `@rd`10)
2754 > (gte:ma:rd `@rd`10 `@rd`11)
2764Tests whether `a` is greater than or equal to `b`.
2768`a` is a `@r`, an IEEE float.
2770`b` is a `@r`, an IEEE float.
2780 |= [a=@r b=@r] (fall (gth:pa (sea a) (sea b)) |)
2786 > (gth:ma:rd `@rd`10 `@rd`10)
2789 > (gth:ma:rd `@rd`10 `@rd`9)
2797Unsigned integer to `@r`
2799Converts `a` from an unsigned integer (`@u`) to `@r`.
2803`a` is `@u`, unsigned integer.
2807A `@r`, an IEEE float.
2813 |= [a=@u] (bit [%f & --0 a])
2819 > (sun:ma:rd 658.149.282)
2827Signed integer to `@r`
2829Converts `a` from a signed integer to `@r`.
2833`a` is `@s`, an unsigned integer
2837A `@r`, an IEEE float.
2843 |= [a=@s] (bit [%f (syn:si a) --0 (abs:si a)])
2859Rounds `a` to the nearest signed integer.
2863`a` is a `@r`, an IEEE float.
2873 |= [a=@r] (toi:pa (sea a))
2879 > (toi:ma:rd `@r`0x4af)
2887`@r` to decimal float
2889Converts `a` from `@r` to `dn` using the Dragon4 algorithm.
2893`a` is a `@r`, an IEEE float.
2903 |= [a=@r] (drg:pa (sea a))
2909 > (drg:ma:rd `@r`0x41c0)
2910 [%d s=%.y e=-323 a=8.316]
2912 > (drg:ma:rd (sun:ma:rd 658.149.282))
2913 [%d s=%.y e=--0 a=658.149.282]
2920Decimal float to `@r`
2922Converts `a` from `dn` to `@r`.
2930A `@r`, an IEEE float.
2936 |= [a=dn] (bif (grd:pa a))
2943 > (grd:ma:rd [%d s=%.y e=--0 a=658.149.282])
2953Converts `a` from a double-precision binary float to decimal64.
2957`a` is a `@rd`, a double-precision float.
2966 ++ rlyd |= a=@rd ^- dn (drg:rd a)
2972 > (rlyd .~2.4703e-320)
2973 [%d s=%.y e=-324 a=24.703]
2982Converts `a` from a single-precision binary float to decimal32.
2986`a` is a `@rs`, a single-precision float.
2995 ++ rlys |= a=@rs ^- dn (drg:rs a)
3001 > (rlys .1.681557e-39)
3002 [%d s=%.y e=-45 a=1.681.557]
3011Converts `a` from a half-precision binary float to decimal16.
3015`a` is a `@rh`, a half-precision float.
3024 ++ rlyh |= a=@rh ^- dn (drg:rh a)
3031 [%d s=%.y e=--1 a=3]
3040Converts `a` from a quad-precision binary float to decimal128.
3044`a` is a `@rq`, a quad-precision float.
3053 ++ rlyq |= a=@rq ^- dn (drg:rq a)
3059 > (rlyq .~~~2.2628017865927756787440310766086816e-4343)
3060 [%d s=%.y e=-4.377 a=22.628.017.865.927.756.787.440.310.766.086.816]
3069Converts `a` from a decimal float to a double-precision binary float.
3077A a `@rd`, a double-precision float.
3082 ++ ryld |= a=dn ^- @rd (grd:rd a)
3088 > (ryld [%d s=%.y e=-324 a=24.703])
3098Converts `a` from a decimal float to a single-precision binary float.
3106A a `@rs`, a single-precision float.
3111 ++ ryls |= a=dn ^- @rs (grd:rs a)
3117 > (ryls [%d s=%.y e=-324 a=24.703])
3120 > (ryls [%d s=%.y e=-32 a=24.703])
3130Converts `a` from a decimal float to a half-precision binary float.
3138A a `@rh`, a half-precision float.
3143 ++ rylh |= a=dn ^- @rh (grd:rh a)
3149 > (rylh [%d s=%.y e=--1 a=703])
3152 > (rylh [%d s=%.y e=--3 a=56])
3155 > (rylh [%d s=%.y e=--4 a=56])
3165Converts `a` from a decimal float to a quad-precision binary float.
3173A a `@rq`, a quad-precision float.
3178 ++ rylq |= a=dn ^- @rq (grd:rq a)
3184 > (rylq [%d s=%.y e=-324 a=24.703])
3194A container core for operations related to double-precision binary floats.
3196`++rd` has four rounding modes: round to nearest (`$n`), round up (`$u`), round
3197down (`$d`), and round to zero (`$z`).
3205 |_ r=$?($n $u $d $z)
3214Instantiates the core `ff`, giving values to its samples based on the
3215configuration of the `rd` core.
3221 %*(. ff w 11, p 52, b --1.023, r r)
3229 {{{w/@ud p/@ud b/@sd} r/?($n $u $d $z)} <54.tyv 119.wim 31.ohr 1.jmk $143>}
3239Converts `a` from a double-precision binary float to `fn`.
3243 |= [a=@rd] (sea:ma a)
3249 > (sea:rd .~4.94066e-319)
3250 [%f s=%.y e=-1.074 a=100.000]
3259Converts `a` from `fn` to a double-precision binary float.
3267A `@rd`, a double-precision float.
3273 |= [a=fn] ^- @rd (bit:ma a)
3279 > (bit:rd [%f s=%.y e=-1.074 a=100.000])
3289Produces the sum of `a` plus `b`.
3293`a` is a `@rd`, a double-precision float.
3295`b` is a `@rd`, a double-precision float.
3305 |= [a=@rd b=@rd] ^- @rd
3313 > (add:rd .~3.94066e12 .~9.2846e11)
3323Produces the difference of `a` minus `b`.
3327`a` is a `@rd`, a double-precision float.
3329`b` is a `@rd`, a double-precision float.
3339 |= [a=@rd b=@rd] ^- @rd
3347 > (sub:rd .~7.94069e2 .~1.2846e3)
3348 .~-4.9053099999999995e2
3357Produces the product of `a` times `b`.
3361`a` is a `@rd`, a double-precision float.
3363`b` is a `@rd`, a double-precision float.
3373 |= [a=@rd b=@rd] ^- @rd
3381 > (mul:rd .~7.94069e2 .~1.2246e3)
3382 .~9.724168973999998e5
3391Produces the quotient of `a` divided by `b`.
3395`a` is a `@rd`, a double-precision float.
3407 |= [a=@rd b=@rd] ^- @rd
3415 > (div:rd .~7.94099e2 .~1.2246e3)
3416 .~6.484558223093255e-1
3425Produces the sum of `c` plus the product of `a` multiplied by `b`;
3430`a` is a `@rd`, an IEEE float.
3446 |= [a=@rd b=@rd c=@rd] ^- @rd
3454 > (fma:rd .~7.94099e2 .~1.2246e3 .~3.94066e3)
3464Produces the square root of `a`.
3468`a` is a `@rd`, a double-precision float.
3478 |= [a=@rd] ^- @rd ~_ leaf+"rd-fail"
3485 > (sqt:rd .~3.94066e3)
3486 .~6.2774676422901614e1
3495Test whether `a` is less than `b`.
3499`a` is a `@rd`, a double-precision float.
3501`b` is a `@rd`, a double-precision float.
3519 > (lth:rd .~7.94099e2 .~1.2246e3)
3522 > (lth:rd .~7.94099e2 .~1.2246e2)
3525 > (lth:rd .~1.2246e2 .~1.2246e2)
3535Test whether `a` is less than or equal to `b`.
3539`a` is a `@rd`, a double-precision float.
3541`b` is a `@rd`, a double-precision float.
3550 ++ lte ~/ %lte :: less-equals
3559 > (lte:rd .~7.94099e2 .~1.2246e3)
3562 > (lte:rd .~7.94099e2 .~1.2246e2)
3565 > (lte:rd .~1.2246e2 .~1.2246e2)
3575Test whether `a` is equal to `b`.
3579`a` is a `@rd`, a double-precision float.
3581`b` is a `@rd`, a double-precision float.
3599 > (equ:rd .~7.94099e2 .~1.2246e3)
3602 > (equ:rd .~7.94099e2 .~1.2246e2)
3605 > (equ:rd .~1.2246e2 .~1.2246e2)
3613Greater than or equal
3615Test whether `a` is greater than or equal to `b`.
3619`a` is a `@rd`, a double-precision float.
3621`b` is a `@rd`, a double-precision float.
3639 > (gte:rd .~7.94099e2 .~1.2246e3)
3642 > (gte:rd .~7.94099e2 .~1.2246e2)
3645 > (gte:rd .~1.2246e2 .~1.2246e2)
3655Test whether `a` is greater `b`.
3659`a` is a `@rd`, a double-precision float.
3661`b` is a `@rd`, a double-precision float.
3679 > (gth:rd .~7.94099e2 .~1.2246e3)
3682 > (gth:rd .~7.94099e2 .~1.2246e2)
3685 > (gth:rd .~1.2246e2 .~1.2246e2)
3693Unsigned integer to `@rd`
3695Converts an unsigned integer `a` to `@rd`.
3699`a` is a `@u`, an unsigned integer.
3708 ++ sun |= [a=@u] ^- @rd (sun:ma a)
3722Unsigned integer to `@rd`
3724Converts a signed integer `a` to `@rd`.
3728`a` is a `@s`, a signed integer.
3737 ++ san |= [a=@s] ^- @rd (san:ma a)
3753Produces the sign of `a`.
3766 ++ sig |= [a=@rd] ^- ? (sig:ma a)
3772 > (sig:rd .~1.2246e3)
3782Produces the exponent of `a`.
3795 ++ exp |= [a=@rd] ^- @s (exp:ma a) :: get exponent
3801 > (exp:rd .~1.2246e3)
3811Rounds `a` to the nearest integer.
3824 ++ toi |= [a=@rd] ^- (unit @s) (toi:ma a)
3830 > (toi:rd .~1.2246e3)
3838`@rd` to decimal float
3840Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
3841accurate results for rounded floats.
3854 ++ drg |= [a=@rd] ^- dn (drg:ma a)
3860 > (drg:rd .~1.2246e3)
3861 [%d s=%.y e=-1 a=12.246]
3868Decimal float to `@rd`
3870Converts `a` from decimal float to `@rd`.
3883 ++ grd |= [a=dn] ^- @rd (grd:ma a) :: decimal float to @rd
3890 > (grd:rd [%d s=%.y e=-1 a=12.246])
3900A container core for operations related to single-precision binary floats.
3902`++rs` has four rounding modes: round to nearest (`$n`), round up (`$u`), round
3903down (`$d`), and round to zero (`$z`).
3911 |_ r=$?($n $u $d $z)
3920Instantiates the core `ff`, giving values to its samples based on the
3921configuration of the `rs` core.
3927 %*(. ff w 8, p 23, b --127, r r)
3935 {{{w/@ud p/@ud b/@sd} r/?($n $u $d $z)} <54.tyv 119.wim 31.ohr 1.jmk $143>}
3945Converts `a` from `@rs` to `fn`.
3949`a` is a `@rs`, an single-precision float.
3959 |= [a=@rs] (sea:ma a)
3966 [%f s=%.y e=-149 a=100]
3975Converts `a` from `fn` to `@rs`.
3983A `@rs`, a single-precision float.
3989 |= [a=fn] ^- @rs (bit:ma a)
3995 > (bit:rs [%f & -2 1.000])
4005Produces the sum of `a` plus `b`.
4009`a` is a `@rs`, a single-precision float.
4021 |= [a=@rs b=@rs] ^- @rs
4029 > (add:rs .2.5e1 .2.5e2)
4039Subtracts `a` from `b`.
4045 |= [a=@rs b=@rs] ^- @rs
4053 > (sub:rs .2.5e1 .2.5e2)
4063Produces the product of `a` multiplied by `b`.
4067`a` is a `@rs`, a single-precision float.
4079 |= [a=@rs b=@rs] ^- @rs
4087 > (mul:rs .2.5e1 .2.5e2)
4097Produces the quotient of `a` divided by `b`.
4101`a` is a `@rs`, a single-precision float.
4113 |= [a=@rs b=@rs] ^- @rs
4121 > (div:rs .4.5e1 .2.2e2)
4131Produces the sum of `c` plus the product of `a` multiplied by `b`;
4136`a` is a `@rs`, a single-precision float.
4150 |= [a=@rs b=@rs c=@rs] ^- @rs
4158 > (fma:rs .2.5e1 .2.5e2 .8.2e1)
4168Produces the square root of `a`.
4172`a` is a `@rs`, a single-precision float.
4200Test whether `a` is less than `b`.
4204`a` is a `@rs`, a single-precision float.
4224 > (lth:rs .9.9e1 .1.1e2)
4227 > (lth:rs .9.9e1 .9.9e1)
4237Test whether `a` is less than or equal to `b`.
4241`a` is a `@rs`, a single-precision float.
4261 > (lte:rs .9.9e1 .1.1e2)
4264 > (lte:rs .9.9e1 .9.9e1)
4274Test whether `a` is equal to `b`.
4278`a` is a `@rs`, a single-precision float.
4298 > (equ:rs .9.9e1 .1.1e2)
4301 > (equ:rs .9.9e1 .9.9e1)
4309Greater than or equal
4311Test whether `a` is greater than or equal to `b`.
4315`a` is a `@rs`, a single-precision float.
4335 > (gte:rs .9.9e1 .9.9e1)
4338 > (gte:rs .9.9e1 .9.2e2)
4348Test whether `a` is greater than `b`.
4352`a` is a `@rs`, a single-precision float.
4372 > (gth:rs .9.9e1 .9.2e2)
4375 > (gth:rs .9.9e1 .9.9e1)
4378 > (gth:rs .9.9e1 .1.9e1)
4386Unsigned integer to `@rs`
4388Converts `a` from an unsigned integer to `@rs`.
4392`a` is an unsigned integer.
4401 ++ sun |= [a=@u] ^- @rs (sun:ma a)
4415Signed integer to `@rs`'
4417Converts `a` from an unsigned integer to `@rs`.
4421`a` is a signed integer.
4430 ++ san |= [a=@s] ^- @rs (san:ma a)
4444Produces the sign of `a`.
4457 ++ sig |= [a=@rs] ^- ? (sig:ma a)
4476Produces the exponent of `a`.
4489 ++ exp |= [a=@rs] ^- @s (exp:ma a)
4505Rounds `a` to the nearest integer.
4518 ++ toi |= [a=@rs] ^- (unit @s) (toi:ma a)
4532`@rs` to decimal float
4534Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
4535accurate results for rounded floats.
4548 ++ drg |= [a=@rs] ^- dn (drg:ma a)
4555 [%d s=%.n e=--0 a=343]
4562Decimal float to `@rs`
4564Converts `a` from `dn` to `@rs`.
4577 ++ grd |= [a=dn] ^- @rs (grd:ma a)
4584 > (grd:rs [%d s=%.n e=--0 a=343])
4592Quadruple-precision fp
4594A container core for operations related to quadruple-precision binary floats.
4596`++rq` has four rounding modes: round to nearest (`$n`), round up (`$u`), round
4597down (`$d`), and round to zero (`$z`).
4605 |_ r=$?($n $u $d $z)
4612Instantiates the core `ff`, giving values to its samples based on the
4613configuration of the `rq` core.
4619 %*(. ff w 15, p 112, b --16.383, r r)
4628Converts `a` from `@rq` to `fn`.
4632`a` is a `@rq`, a quad-precision float.
4642 |= [a=@rq] (sea:ma a)
4648 > (sea:rq .~~~1.05102e5)
4649 [%f s=%.y e=-96 a=8.327.038.336.574.210.409.756.656.268.214.272]
4658Converts `a` from `fn` to `@rq`.
4666A `@rq`, a quad-precision float.
4672 |= [a=n] ^- @rq (bit:ma a)
4678 > (bit:rq [%f s=%.y e=-96 a=8.327.038.336.574.210.409.756.656.268.214.272])
4688Produces the sum of `a` plus `b`.
4692`a` is a `@rq`, a quad-precision float.
4704 |= [a=@rq b=@rq] ^- @rq
4712 > (add:rq .~~~-1.821e5 .~~~1.05102e5)
4722Produces the difference of `a` minus `b`.
4726`a` is a `@rq`, a quad-precision float.
4738 |= [a=@rq b=@rq] ^- @rq
4746 > (sub:rq .~~~1.821e5 .~~~1.05102e5)
4749 > (sub:rq .~~~1.821e5 .~~~-1.05102e5)
4759Produces the product of `a` times `b`.
4763`a` is a `@rq`, a quad-precision float.
4775 |= [a=@rq b=@rq] ^- @rq
4783 > (mul:rq .~~~1.821e5 .~~~-1.05102e5)
4793Produces the product of `a` divided by `b`.
4797`a` is a `@rq`, a quad-precision float.
4809 |= [a=@rq b=@rq] ^- @rq
4817 > (div:rq .~~~1.821e5 .~~~1.05102e3)
4818 .~~~1.732602614602957127361991208540275e2
4827Produces the sum of `c` plus the product of `a` multiplied by `b`;
4832`a` is a `@rq`, a quad-precision float.
4846 |= [a=@rq b=@rq c=@rq] ^- @rq
4854 > (fma:rq .~~~1.821e5 .~~~-1.05102e2 .~~~6.2044e7)
4864Produces the square root of `a`.
4868`a` is a `@rq`, a quad-precision float.
4886 > (sqt:rq .~~~6.2044e7)
4887 .~~~7.876801381271461258959876570289002e3
4896Tests whether `a` is less than `b`.
4900`a` is a `@rq`, a quad-precision float.
4920 > (lth:rq .~~~1.2044e7 (mul:rq .~~~9.02e2 .~~~7.114e3))
4923 > (lth:rq .~~~1.2044e7 (mul:rq .~~~9.02e3 .~~~7.114e3))
4933Tests whether `a` is less than or equal to `b`.
4937`a` is a `@rq`, a quad-precision float.
4957 > (lte:rq .~~~1.2044e7 (mul:rq .~~~9.02e2 .~~~7.114e3))
4960 > (lte:rq .~~~1.2044e7 (mul:rq .~~~9.02e3 .~~~7.114e3))
4963 > (lte:rq .~~~1.2044e7 .~~~1.2044e7)
4973Tests whether `a` is equal to `b`.
4977`a` is a `@rq`, a quad-precision float.
4997 > (equ:rq .~~~1.2044e7 .~~~1.2044e7)
5000 > (equ:rq .~~~2.2044e7 .~~~1.2044e7)
5008Greater than or equal
5010Tests whether `a` is greater than or equal to `b`.
5014`a` is a `@rq`, a quad-precision float.
5034 > (gte:rq .~~~1.2044e7 .~~~1.2044e7)
5037 > (gte:rq .~~~2.2044e7 .~~~1.2044e7)
5040 > (gte:rq .~~~1.2044e7 .~~~2.2044e7)
5048Tests whether `a` is greater than `b`.
5052`a` is a `@rq`, a quad-precision float.
5072 > (gth:rq .~~~1.2044e7 .~~~1.2044e7)
5075 > (gth:rq .~~~2.2044e7 .~~~1.2044e7)
5078 > (gth:rq .~~~1.2044e7 .~~~2.2044e7)
5086Unsigned integer to `@rq`
5088Converts `@` from an unsigned integer to `@rq`.
5092`a` is a `@u`, an unsigned integer.
5096A `@rq`, a quad-precision float.
5101 ++ sun |= [a=@u] ^- @rq (sun:ma a)
5115Signed integer to `rq`
5117Converts `@` from a signed integer to `@rq`.
5121`a` is a `@s`, a signed integer.
5125A `@rq`, a quad-precision float.
5130 ++ san |= [a=@s] ^- @rq (san:ma a)
5146Produces the sign of `a`.
5150`a` is a `@rq`, a quad-precision float.
5159 ++ sig |= [a=@rq] ^- ? (sig:ma a)
5165 > (sig:rq .~~~-2.05e2)
5175Gets the exponent of `a`.
5179`a` is a `@rq`, a quad-precision float.
5183A `@s`, a signed integer.
5188 ++ exp |= [a=@rq] ^- @s (exp:ma a)
5194 > (exp:rq .~~~-2.05e2)
5204Rounds `a` to the nearest integer.
5208`a` is a `@rq`, a quad-precision float.
5217 ++ toi |= [a=@rq] ^- (unit @s) (toi:ma a)
5223 > (toi:rq .~~~-2.085e2)
5226 > (toi:rq .~~~-2.08e2)
5234`@rq` to decimal float
5236Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
5237accurate results for rounded floats.
5241`a` is a `@rq`, a quad-precision float.
5250 ++ drg |= [a=@rq] ^- dn (drg:ma a) :: @rq to decimal float
5256 > (drg:rq .~~~-2.085e2)
5257 [%d s=%.n e=-1 a=2.085]
5259 > (drg:rq .~~~-2.08e2)
5260 [%d s=%.n e=--0 a=208]
5267Decimal float to `@rq`
5269Converts `a` from `dn` to `@rq`.
5279A `@rq`, a quad-precision float.
5284 ++ grd |= [a=dn] ^- @rq (grd:ma a)
5291 > (grd:rq [%d s=%.n e=--0 a=343])
5301A container core for operations related to half-precision binary floats.
5303`++rh` has four rounding modes: round to nearest (`$n`), round up (`$u`), round
5304down (`$d`), and round to zero (`$z`).
5312 |_ r=$?($n $u $d $z)
5321Instantiates the core `ff`, giving values to its samples based on the
5322configuration of the `rh` core.
5328 %*(. ff w 5, p 10, b --15, r r)
5337Converts `a` from `@rh` to `fn`.
5341`a` is a `@rh`, a half-precision float.
5351 |= [a=@rh] (sea:ma a)
5357 > (sea:rh .~~1.22e-5)
5358 [%f s=%.y e=-24 a=205]
5367Converts `a` from `fn` to `@rh`.
5375A `@rh`, a half-precision float.
5381 |= [a=fn] ^- @rh (bit:ma a)
5387 > (bit:rh [%f s=%.y e=-24 a=205])
5395Produces the sum of `a` plus `b`.
5399`a` is a `@rh`, a half-precision float.
5411 |= [a=@rh b=@rh] ^- @rh
5419 > (add:rh .~~1.82e2 .~~1.02e2)
5429Produces the difference of `a` minus `b`.
5433`a` is a `@rh`, a half-precision float.
5445 |= [a=@rh b=@rh] ^- @rh
5453 > (sub:rh .~~1.821e2 .~~1.051e2)
5456 > (sub:rh .~~1.821e2 .~~6.051e2)
5466Produces the product of `a` times `b`.
5470`a` is a `@rh`, a quad-precision float.
5482 |= [a=@rh b=@rh] ^- @rh
5490 > (mul:rh .~~1.821e1 .~~-1.05102e2)
5500Produces the product of `a` divided by `b`.
5504`a` is a `@rh`, a half-precision float.
5516 |= [a=@rh b=@rh] ^- @rh
5524 > (div:rh .~~1.821e3 .~~1.05102e2)
5534Produces the sum of `c` plus the product of `a` multiplied by `b`;
5539`a` is a `@rh`, a half-precision float.
5553 |= [a=@rh b=@rh c=@rh] ^- @rh
5561 > (fma:rh .~~1.821e4 .~~-1.05102e2 .~~6.2044e3)
5571Produces the square root of `a`.
5575`a` is a `@rh`, a half-precision float.
5593 > (sqt:rh .~~6.24e4)
5603Tests whether `a` is less than `b`.
5607`a` is a `@rh`, a half-precision float.
5627 > (lth:rh .~~1.2e5 (mul:rh .~~9.02e2 .~~7.114e2))
5630 > (lth:rh .~~1.2e3 (mul:rh .~~9.02e1 .~~7.114e2))
5640Tests whether `a` is less than or equal to `b`.
5644`a` is a `@rh`, a half-precision float.
5664 > (lte:rh .~~1.2e5 (mul:rh .~~9.02e2 .~~7.114e2))
5667 > (lte:rh .~~1.2e3 (mul:rh .~~9.02e1 .~~7.114e2))
5670 > (lte:rh .~~1.2e3 .~~1.2e3)
5680Tests whether `a` is equal to `b`.
5684`a` is a `@rh`, a half-precision float.
5704 > (equ:rh .~~1.24e4 .~~1.24e4)
5707 > (equ:rh .~~2.24e4 .~~1.24e4)
5715Greater than or equal
5717Tests whether `a` is greater than or equal to `b`.
5721`a` is a `@rh`, a half-precision float.
5741 > (gte:rh .~~1.24e4 .~~1.24e4)
5744 > (gte:rh .~~2.24e4 .~~1.24e4)
5747 > (gte:rh .~~1.24e4 .~~2.24e4)
5755Tests whether `a` is greater than `b`.
5759`a` is a `@rh`, a half-precision float.
5779 > (gth:rh .~~1.24e4 .~~1.244e4)
5782 > (gth:rh .~~2.24e4 .~~1.24e4)
5785 > (gth:rh .~~1.24e4 .~~2.24e4)
5795Converts `@` from `@rh` to `@rs`.
5799`a` is a `@rh`, a half-precision float.
5803A `@rs`, a single-precision float.
5808 ++ tos |= {a/@rh} (bit:rs (sea a))
5824Converts `@` from `@rs` to `@rh`.
5828`a` is a `@rs`, a single-precision float.
5832A `@rh`, a half-precision float.
5837 ++ fos |= {a/@rs} (bit (sea:rs a))
5851Unsigned integer to `@rh`
5853Converts `@` from an unsigned integer to `@rh`.
5857`a` is a `@u`, an unsigned integer.
5861A `@rh`, a half-precision float.
5866 ++ sun |= [a=@u] ^- @rh (sun:ma a)
5880Signed integer to `@rh`
5882Converts `@` from a signed integer to `@rh`.
5886`a` is a `@s`, a signed integer.
5890A `@rh`, a half-precision float.
5895 ++ san |= [a=@s] ^- @rh (san:ma a)
5911Produces the sign of `a`.
5915`a` is a `@rh`, a half-precision float.
5924 ++ sig |= [a=@rh] ^- ? (sig:ma a)
5930 > (sig:rh .~~-2.05e2)
5940Gets the exponent of `a`.
5944`a` is a `@rh`, a half-precision float.
5948A `@s`, a signed integer.
5953 ++ exp |= [a=@rh] ^- @s (exp:ma a)
5959 > (exp:rh .~~-2.05e2)
5969Rounds `a` to the nearest integer.
5973`a` is a `@rh`, a half-precision float.
5982 ++ toi |= [a=@rh] ^- (unit @s) (toi:ma a)
5988 > (toi:rh .~~-2.085e2)
5991 > (toi:rh .~~-2.08e2)
5999`@rh` to decimal float
6001Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
6002accurate results for rounded floats.
6006`a` is a `@rh`, a half-precision float.
6015 ++ drg |= [a=@rh] ^- dn (drg:ma a)
6021 > (drg:rh .~~-2.085e2)
6022 [%d s=%.n e=-1 a=2.085]
6024 > (drg:rh .~~-2.08e2)
6025 [%d s=%.n e=--0 a=208]
6032Decimal float to `@rh`
6034Converts `a` from `dn` to `@rh`.
6044A `@rh`, a a half-precision float.
6049 ++ grd |= [a=dn] ^- @rh (grd:ma a)
6056 > (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