2title = "3b: Floating Point"
10A mold for the floating-point arithmetic using the base of two, the formula is
13Produces either a float (`$f`), an infinity of other sign (`$i`),
14or not-a-number (`$n`). `s` refers to sign, the `flag`s `&` or `|`; `e` to
15exponent, a signed decimal; and `a` to the significand, an unsigned integer.
33 > (add:fl [%f & --33 2] [%f | --23 2])
34 [%f s=%.y e=-79 a=10.374.452.512.267.829.421.849.019.032.797.184]
36 > (add:fl [%i &] [%i &])
39 > (add:fl [%n ~] [%i |])
42 > (sun:fl 961.193.554.848.514.048.973.893.027.381.506.219.443)
43 [%f s=%.y e=--17 a=7.333.324.850.834.000.007.430.214.137.126.970]
52A mold for the floating-point arithmetic using the base of 10; the formula is
55Valid values are a float (`$d`), an infinity (`$i`), or a not-a-number (`$n`).
56`s` refers to sign, the `flag`s `&` or `|`; `e` to exponent, a signed decimal;
57and `a` to the significand, an unsigned integer.
70 > `dn`[%d & --0 17.163.091.968]
71 [%d s=%.y e=--0 a=17.163.091.968]
85A mold for the floating-point arithmetic using the base of 10; the formula is
88Produces either a parsed float (`$d`), infinity of either sign (`$i`), or
94 $% [$d a=? b=[c=@ [d=@ e=@] f=? i=@]]
103 > `rn`[%d | [2 [3 4] | 17.163]]
104 [%d a=%.n b=[c=2 [d=3 e=4] f=%.n i=17.163]]
110Arbitrary-precision floating-point
112Container arm for floating-point arithmetic functions.
114- Precision (`p`): number of bits in the significand; must be at least 2.
116- Minimum exponent (`v`): minimum value of e. Default is -16.494.
117- Width (`w`): Max value of `e` minus min value of `e`. 0 is for fixed-point.
119- Rounding mode (`r`): Possible modes are nearest (`$n`), up (`$u`),
120 down (`$d`), to zero (`$z`), and away from zero (`$a`). Default value is `%n`.
121- Behavior (`d`): return denormals (`$d`), flush denormals to zero (`$z`),
122 infinite exponent range (`$i`). Default value is `%d`.
128 =+ ^- [[p=@u v=@s w=@u] r=$?($n $u $d $z $a) d=$?($d $f $i)]
129 [[113 -16.494 32.765] %n %d]
140Rounds `a` to a the nearest float that can be represented with a 113-bit
141significand. There is no term to sign the significand, meaning that a positive
142sign will always be produced.
146`a` is a cell of a signed integer and an unsigned integer.
156 |= [a=[e=@s a=@u]] ^- fn (rau a &)
162 > =a 10.161.487.211.429.486.882.397.572.894.294.017.777
164 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
166 > (^rou:fl [--12 (add a 1)])
167 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
169 > (^rou:fl [--12 (add a 300)])
170 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
172 > (^rou:fl [--12 (add a 1.000)])
173 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.003]
181Rounds `a` based on what the state of of `r` in the core contained in `fl`. `t`
182is a sticky bit that represents a value less than ULP(a) = 2^(e.a) when passed
187`a` is a cell of a signed integer and an unsigned integer.
199 |= [a=[e=@s a=@u] t=?] ^- fn
201 $z (lug %fl a t) $d (lug %fl a t)
202 $a (lug %ce a t) $u (lug %ce a t)
210 > (rau:fl [-18 342.602.577] &)
211 [%f s=%.y e=-102 a=6.626.897.619.228.945.634.459.505.846.648.832]
217See `lug:fl` for possible rounding operations.
224Produces the sum of `a` and `b`. `e` is used to choose between an exact result
225(any-sized significand) or a rounded result (113-bit significand).
227There is no term to sign the significands, so a positive sign will always be
246 |= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn
247 =+ q=(dif:si e.a e.b)
248 |- ?. (syn:si q) $(b a, a b, q +(q)) :: a has larger exp
250 [%f & e.b (^add (lsh 0 (abs:si q) a.a) a.b)]
251 =+ [ma=(met 0 a.a) mb=(met 0 a.b)]
252 =+ ^= w %+ dif:si e.a %- sun:si :: expanded exp of a
253 ?: (gth prc ma) (^sub prc ma) 0
254 =+ ^= x %+ sum:si e.b (sun:si mb) :: highest exp for b
255 ?: =((cmp:si w x) --1) :: don't need to add
257 $z (lug %fl a &) $d (lug %fl a &)
258 $a (lug %lg a &) $u (lug %lg a &)
261 (rou [e.b (^add (lsh 0 (abs:si q) a.a) a.b)])
267 > (^add:fl [--33 2.718] [--23 11] %.y)
268 [%f s=%.y e=--23 a=2.783.243]
270 > (^add:fl [--33 2.718] [--23 11] %.n)
271 [%f s=%.y e=-68 a=6.890.975.897.521.519.304.902.126.405.156.864]
279Produces the difference of `a` minus `b.` `e` is used to choose between an exact
280result (any-sized significand) or a rounded result (113-bit significand).
284`a` is a cell of a signed integer and an unsigned integer.
286`b` is a cell of a signed integer and an unsigned integer.
298 |= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn
299 =+ q=(dif:si e.a e.b)
301 (fli $(b a, a b, q +(q), r swr))
302 =+ [ma=(met 0 a.a) mb=(met 0 a.b)]
303 =+ ^= w %+ dif:si e.a %- sun:si
304 ?: (gth prc ma) (^sub prc ma) 0
305 =+ ^= x %+ sum:si e.b (sun:si +(mb))
306 ?: &(!e =((cmp:si w x) --1))
308 $z (lug %sm a &) $d (lug %sm a &)
309 $a (lug %ce a &) $u (lug %ce a &)
312 =+ j=(lsh 0 (abs:si q) a.a)
314 (fli $(a.b j, j a.b, r swr))
317 ?: e [%f & e.b i] (rou [e.b i])
323 > (^sub:fl [--33 2.718] [--23 11] %.y)
324 [%f s=%.y e=--23 a=2.783.221]
326 > (^sub:fl [--33 2.718] [--63 11] %.y)
327 [%f s=%.n e=--33 a=11.811.157.346]
335Produces the product of `a` multiplied by `b`. There is no term to sign the
336significands, so a positive sign will always be produced.
340`a` is a cell of a signed integer and an unsigned integer.
342`b` is a cell of a signed integer and an unsigned integer.
352 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- fn
353 (rou (sum:si e.a e.b) (^mul a.a a.b))
359 > (^mul:fl [--3 2.718] [--23 11])
360 [%f s=%.y e=-72 a=9.475.054.411.405.900.661.487.108.108.582.912]
368Produces the quotient of `a` divided by `b`. There is no term to sign the
369significands, so a positive sign will always be produced.
373`a` is a cell of a signed integer and an unsigned integer.
375`b` is a cell of a signed integer and an unsigned integer.
385 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- fn
386 =+ [ma=(met 0 a.a) mb=(met 0 a.b)]
387 =+ v=(dif:si (sun:si ma) (sun:si +((^add mb prc))))
389 a(e (sum:si v e.a), a (lsh 0 (abs:si v) a.a))
390 =+ [j=(dif:si e.a e.b) q=(dvr a.a a.b)]
391 (rau [j p.q] =(q.q 0))
397 > (^div:fl [--13 2.718] [--23 11])
398 [%f s=%.y e=-115 a=10.023.198.055.040.952.765.870.659.817.343.907]
406Produces the square root of `a`.
410`a` is a cell of a signed integer and an unsigned integer.
420 |= [a=[e=@s a=@u]] ^- fn
422 =+ [w=(met 0 a.a) x=(^mul +(prc) 2)]
423 =+ ?:((^lth w x) (^sub x w) 0)
424 =+ ?: =((dis - 1) (dis (abs:si e.a) 1)) -
426 a(e (dif:si e.a (sun:si -)), a (lsh 0 - a.a))
427 =+ [y=(^sqt a.a) z=(fra:si e.a --2)]
428 (rau [z p.y] =(q.y 0))
434 > (^sqt:fl [-18 342.602.577])
435 [%f s=%.y e=-107 a=5.865.903.143.604.945.574.132.671.852.050.553]
443Tests if `a` is less than `b`.
447`a` is a cell of a signed integer and an unsigned integer.
449`b` is a cell of a signed integer and an unsigned integer.
459 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ?
460 ?: =(e.a e.b) (^lth a.a a.b)
461 =+ c=(cmp:si (ibl a) (ibl b))
462 ?: =(c -1) & ?: =(c --1) |
463 ?: =((cmp:si e.a e.b) -1)
464 (^lth (rsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b)
465 (^lth (lsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b)
471 > (^lth:fl [-4 684] [--0 35])
474 > (^lth:fl [-4 684] [--0 90])
483Tests if `a` is equal to `b`.
487`a` is a cell of a signed integer and an unsigned integer.
489`b` is a cell of a signed integer and an unsigned integer.
499 |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ?
500 ?. =((ibl a) (ibl b)) |
501 ?: =((cmp:si e.a e.b) -1)
502 =((lsh 0 (abs:si (dif:si e.a e.b)) a.b) a.a)
503 =((lsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b)
509 > (^equ:fl [-4 480] [-0 50])
512 > (^equ:fl [-4 480] [-0 30])
519Integer binary logarithm
521Produces the lowest power to which the number 2 must be raised to obtain `a` or
526`a` is a cell of a signed integer and an unsigned integer.
536 |= [a=[e=@s a=@u]] ^- @s
537 (sum:si (sun:si (dec (met 0 a.a))) e.a)
543 > (ibl:fl [-18 342.602.577])
550Change representation to odd
552Produces another representation of the floating point `a` where the significand
553is odd. Every floating-point number has a unique representation of this kind. If
554the significand of `a` is already odd, nothing changes.
558`a` is a cell of a signed integer and an unsigned integer.
562A cell of a signed integer and an unsigned integer.
569 |- ?: =((end 0 1 a.a) 1) a
570 $(a.a (rsh 0 1 a.a), e.a (sum:si e.a --1))
576 > (uni:fl [-8 342.602.578])
579 > (uni:fl [-8 342.602.577])
588Produces the fully precise form of `a`, or the denormalized form of `a`.
592`a` is a cell of a signed integer and an unsigned integer.
596A cell of a signed integer and an unsigned integer.
605 =+ ?: =(den %i) (^sub prc ma)
607 =+ w=(dif:si e.a emn)
608 ?: (syn:si w) (abs:si w) 0
609 (min q (^sub prc ma))
610 a(e (dif:si e.a (sun:si -)), a (lsh 0 - a.a))
617 [e=-106 a=7.788.445.287.802.241.442.795.744.493.830.144]
619 > (xpd:fl [-8 342.602.577])
620 [e=-92 a=6.626.897.619.228.945.634.459.505.846.648.832]
622 > (xpd:fl [-92 6.626.897.619.228.945.634.459.505.846.648.832])
623 [e=-92 a=6.626.897.619.228.945.634.459.505.846.648.832]
629Central rounding mechanism
631Performs various rounding operations on `a`. An operation is chosen based on the
632value selected for `t`. `s` is a sticky bit that represents a value less than
635Possible rounding operations:
640- Nearest (`$ne`) -- Rounds ties away from 0 if the number is even, rounds
641 toward 0 if the number is odd.
645`t` is one of the following: `$fl`, `$ce`, `$sm`, `$lg`, `$ne`, `$na`, or `$nt`.
647`a` is a cell of a signed integer and an unsigned integer.
659 :: central rounding mechanism
660 :: can perform: floor, ceiling, smaller, larger,
661 :: nearest (round ties to: even, away from 0, toward 0)
662 :: s is sticky bit: represents a value less than ulp(a) = 2^(e.a)
666 |= [t=$?($fl $ce $sm $lg $ne $na $nt) a=[e=@s a=@u] s=?] ^- fn
669 ?. =(den %f) - :: flush denormals
671 ?: =((met 0 ->+>) prc) - [%f & zer]
674 ?> |(s (gth m prc)) :: require precision
676 ?: (gth m prc) (^sub m prc) 0 :: reduce precision
677 %- abs:si ?: =(den %i) --0 :: enforce min. exp
678 ?: =((cmp:si e.a emn) -1) (dif:si emn e.a) --0
679 =^ b a :- (end 0 q a.a)
680 a(e (sum:si e.a (sun:si q)), a (rsh 0 q a.a))
689 $ne ?: s [%f & ?:((lte b (bex (dec q))) zer spd)]
690 [%f & ?:((^lth b (bex (dec q))) zer spd)]
691 $nt ?: s [%f & ?:((lte b (bex (dec q))) zer spd)]
692 [%f & ?:((^lth b (bex (dec q))) zer spd)]
693 $na [%f & ?:((^lth b (bex (dec q))) zer spd)]
703 ?: &(=(e.a emn) !=(den %i)) a(a (dec a.a))
704 =+ y=(dec (^mul a.a 2))
705 ?. (lte (met 0 y) prc) a(a (dec a.a))
707 $ce ?: &(=(b 0) s) a a(a +(a.a))
710 ?: &(=(b y) s) :: round halfs to even
711 ?~ (dis a.a 1) a a(a +(a.a))
712 ?: (^lth b y) a a(a +(a.a))
715 ?: (^lth b y) a a(a +(a.a))
718 ?: =(b y) ?: s a a(a +(a.a))
719 ?: (^lth b y) a a(a +(a.a))
722 =. a ?. =((met 0 a.a) +(prc)) a
723 a(a (rsh 0 1 a.a), e (sum:si e.a --1))
726 ?: =(den %i) [%f & a]
727 ?: =((cmp:si emx e.a) -1) [%i &] [%f & a] :: enforce max. exp
736Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
737accurate results for rounded floats.
741`a` is a cell of a signed integer and an unsigned integer.
745A cell of a signed integer and an unsigned integer.
752 |= [a=[e=@s a=@u]] ^- [@s @u]
755 =+ r=(lsh 0 ?:((syn:si e.a) (abs:si e.a) 0) a.a)
756 =+ s=(lsh 0 ?.((syn:si e.a) (abs:si e.a) 0) 1)
757 =+ mn=(lsh 0 ?:((syn:si e.a) (abs:si e.a) 0) 1)
760 ?& =(a.a (bex (dec prc))) :: if next smallest
761 |(!=(e.a emn) =(den %i)) :: float is half ULP,
762 == :: tighten lower bound
769 =+ [k=--0 q=(^div (^add s 9) 10)]
777 |- ?: (gte (^add (^mul r 2) mp) (^mul s 2))
778 $(s (^mul s 10), k (sum:si k --1))
780 |- :: r/s+o = a*10^-k
781 =+ v=(dvr (^mul r 10) s)
789 =+ l=(^lth (^mul r 2) mn) :: in lower bound
790 =+ ^= h :: in upper bound
791 ?| (^lth (^mul s 2) mp)
792 (gth (^mul r 2) (^sub (^mul s 2) mp))
795 $(o (^add (^mul o 10) u))
796 =+ q=&(h |(!l (gth (^mul r 2) s)))
797 =. o (^add (^mul o 10) ?:(q +(u) u))
805 [%f s=%.y e=-95 a=8.640.464.947.480.640.129.276.716.135.743.488]
806 > (^drg:fl [e=-95 a=8.640.464.947.480.640.129.276.716.135.743.488])
809 > (sun:fl 102.057.673.128.349)
810 [%f s=%.y e=-66 a=7.530.527.107.827.833.883.675.587.233.447.936]
811 > (^drg:fl [e=-66 a=7.530.527.107.827.833.883.675.587.233.447.936])
812 [--0 102.057.673.128.349]
820Rounds float `a` to the nearest decimal float with an exponent of 0.
824`a` is a cell of a signed integer and an unsigned integer.
834 |= [a=[e=@s a=@u]] ^- fn
835 ?. =((cmp:si e.a --0) -1) [%f & a]
838 ?: |(=(r %d) =(r %z)) [%f & --0 y]
840 ?: |(=(r %u) =(r %a)) [%f & --0 ?~(z y +(y))]
842 ?: &(=(z i) =((dis y 1) 0)) [%f & --0 y]
843 ?: (^lth z i) [%f & --0 y] [%f & --0 +(y)]
849 > (^toj:fl [-11 7.530.107.827.833.587])
850 [%f s=%.y e=--0 a=3.676.810.462.809]
852 > (^toj:fl [-11 7.530.107.827.833.589])
853 [%f s=%.y e=--0 a=3.676.810.462.809]
861Produces `a` if `a` is a is of floating-point representation. If `a` is another
862case of `fn`, such as infinity or not-a-number, a crash is produced.
870A cell of a signed integer and an unsigned integer.
876 |= [a=fn] ^- [$f s=? e=@s a=@u]
886 > (ned:fl [%f s=%.y e=-11 a=7.530.107.827.833.587])
887 [%f s=%.y e=-11 a=7.530.107.827.833.587]
903Multiplies `a` by 2 to the `b` power without rounding. This results in shifting
904the exponent term by `b`.
910`b` is a signed integer.
921 ?: |(?=([$n *] a) ?=([$i *] a)) a
928 > (shf:fl [[%f & -2 7] --2])
931 > (shf:fl [[%f & -2 7] -2])
934 > (shf:fl [%f & -11 7.530.107.827.833.587] --5)
935 [%f s=%.y e=-6 a=7.530.107.827.833.587]
943Produces `a` with its signed changed from positive to negative, or vice versa.
958 ?-(-.a $f a(s !s.a), $i a(s !s.a), $n a)
964 > (fli:fl [%f %.y -2 7])
967 > (fli:fl [%f %.n --2 30.617])
968 [%f s=%.y e=--2 a=30.617]
970 > (fli:fl [%f | --2 30.617])
971 [%f s=%.y e=--2 a=30.617]
979Switches the rounding mode of `r:fl`.
984 ++ swr ?+(r r $d %u, $u %d)
995 > =new-fl fl :: new fl core with changed state
996 > =new-fl new-fl(r %u)
1004Force precision of 2 or greater
1006Produces `p`, the core's precision, if `p` is greater than or equal to 2.
1007Otherwise, a crash is produced.
1012 ++ prc ?>((gth p 1) p)
1022 > =new-fl new-fl(p 1)
1026 > =new-fl new-fl(p 2)
1036Produces `d:fl`. Denormalizes if `d:fl` is `%d`. Flushes denormals to zero if
1039- Denormalizes if `d:fl` is `%d`.
1040- Flushes denormals to zero if `d:fl` is `%f`.
1041- Infinite exponent range if `$d` is `$i`.
1043The default value of `d` is `%d`.
1058 > =new-fl new-fl(d %f)
1068Produces `v:fl`, the minimum exponent. The default minimum exponent is -16.494.
1088Returns the maximum exponent of `fl`. The default maximum exponent is --16.271.
1093 ++ emx (sum:si emn (sun:si w))
1111Produces the smallest possible denormalized float.
1131Produces the smallest representable normal float.
1136 ++ spn [e=emn a=(bex (dec prc))]
1143 [e=-16.494 a=5.192.296.858.534.827.628.530.496.329.220.096]
1151Produces the largest representable normal float.
1156 ++ lfn [e=emx a=(fil 0 prc 1)]
1163 [e=--16.271 a=10.384.593.717.069.655.257.060.992.658.440.191]
1171Produces the sum of `emx:fl` plus `prc:fl`.
1176 ++ lfe (sum:si emx (sun:si prc)) :: 2^lfe is > than all
1191Produces zero represented as a float.
1213Rounds `a`. The way in which `a` is rounded depends on the value of `r:fl`.
1231 =.(r swr (fli (^rou +>.a)))
1237 > =a 10.161.487.211.429.486.882.397.572.894.294.017.777
1238 > (rou:fl [%f & --12 a])
1239 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
1241 > (rou:fl [%f & --12 (add a 1)])
1242 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
1244 > (rou:fl [%f & --12 (add a 300)])
1245 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.002]
1247 > (rou:fl [%f & --12 (add a 1.000)])
1248 [%f s=%.y e=--22 a=9.923.327.354.911.608.283.591.379.779.584.003]
1256Produces the sign of `a`.
1271 ?-(-.a $f s.a, $i s.a, $n &)
1277 > (syn:fl (sun:fl 106))
1280 > (syn:fl [%f | --0 106])
1289Produces the absolute value of `a`.
1304 ?: ?=([$f *] a) [%f & e.a a.a]
1305 ?: ?=([$i *] a) [%i &] [%n ~]
1311 > (abs:fl [%f | --0 106])
1312 [%f s=%.y e=--0 a=106]
1314 > (abs:fl [%f & --0 106])
1315 [%f s=%.y e=--0 a=106]
1323Produces the sum of `a` plus `b`.
1339 |= [a=fn b=fn] ^- fn
1340 ?: |(?=([$n *] a) ?=([$n *] b)) [%n ~]
1341 ?: |(?=([$i *] a) ?=([$i *] b))
1342 ?: &(?=([$i *] a) ?=([$i *] b))
1345 ?: |(=(a.a 0) =(a.b 0))
1346 ?. &(=(a.a 0) =(a.b 0)) %- rou ?~(a.a b a)
1347 [%f ?:(=(r %d) &(s.a s.b) |(s.a s.b)) zer]
1353 ?: s.a (^add +>.a +>.b |)
1354 =.(r swr (fli (^add +>.a +>.b |)))
1355 ?: s.a (^sub +>.a +>.b |)
1362 > (add:fl [%f & --0 106] [%f | --3 55])
1363 [%f s=%.n e=-104 a=6.774.324.807.619.657.921.598.381.929.529.344]
1371Produces the exact sum of `a` plus `b`.
1387 |= [a=fn b=fn] ^- fn
1388 ?: |(?=([$n *] a) ?=([$n *] b)) [%n ~]
1389 ?: |(?=([$i *] a) ?=([$i *] b))
1390 ?: &(?=([$i *] a) ?=([$i *] b))
1393 ?: |(=(a.a 0) =(a.b 0))
1394 ?. &(=(a.a 0) =(a.b 0)) ?~(a.a b a)
1395 [%f ?:(=(r %d) &(s.a s.b) |(s.a s.b)) zer]
1401 ?: s.a (^add +>.a +>.b &)
1402 (fli (^add +>.a +>.b &))
1403 ?: s.a (^sub +>.a +>.b &)
1411 > (ead:fl [%f & --0 106] [%f | --3 55])
1412 [%f s=%.n e=--0 a=334]
1420Produces the difference of `a` minus `b`.
1436 |= [a=fn b=fn] ^- fn (add a (fli b))
1442 > (sub:fl [%f & --13 2.718] [%f & --23 11])
1443 [%f s=%.n e=-86 a=5.416.671.014.775.224.232.595.412.796.571.648]
1451Produces the product of `a` multiplied by `b`.
1467 |= [a=fn b=fn] ^- fn
1468 ?: |(?=([$n *] a) ?=([$n *] b)) [%n ~]
1472 ?: =(a.b 0) [%n ~] [%i =(s.a s.b)]
1474 ?: =(a.a 0) [%n ~] [%i =(s.a s.b)]
1475 ?: |(=(a.a 0) =(a.b 0)) [%f =(s.a s.b) zer]
1476 ?: =(s.a s.b) (^mul +>.a +>.b)
1477 =.(r swr (fli (^mul +>.a +>.b)))
1485Produces the exact product of `a` multiplied by `b`.
1501 |= [a=fn b=fn] ^- fn
1502 ?: |(?=([$n *] a) ?=([$n *] b)) [%n ~]
1506 ?: =(a.b 0) [%n ~] [%i =(s.a s.b)]
1508 ?: =(a.a 0) [%n ~] [%i =(s.a s.b)]
1509 ?: |(=(a.a 0) =(a.b 0)) [%f =(s.a s.b) zer]
1510 [%f =(s.a s.b) (sum:si e.a e.b) (^^mul a.a a.b)]
1518Produces the quotient of `a` divided by `b`.
1534 |= [a=fn b=fn] ^- fn
1535 ?: |(?=([$n *] a) ?=([$n *] b)) [%n ~]
1537 ?: ?=([$i *] b) [%n ~] [%i =(s.a s.b)]
1538 ?: ?=([$i *] b) [%f =(s.a s.b) zer]
1539 ?: =(a.a 0) ?: =(a.b 0) [%n ~] [%f =(s.a s.b) zer]
1540 ?: =(a.b 0) [%i =(s.a s.b)]
1541 ?: =(s.a s.b) (^div +>.a +>.b)
1542 =.(r swr (fli (^div +>.a +>.b)))
1550Produces the sum of `c` plus the product of `a` multiplied by `b`;
1569 |= [a=fn b=fn c=fn] ^- fn
1576 > (fma:fl [%f & --13 2.718] [%f & --23 11] [%f & --13 2.718])
1577 [%f s=%.y e=-62 a=9.475.054.514.089.037.465.004.673.635.188.736]=
1585Produces the square root of `a`.
1600 ?: ?=([$n *] a) [%n ~]
1601 ?: ?=([$i *] a) ?:(s.a a [%n ~])
1603 ?: s.a (^sqt +>.a) [%n ~]
1609 > (sqt:fl [%f s=%.y e=-18 a=342.602.577])
1610 [%f s=%.y e=-107 a=5.865.903.143.604.945.574.132.671.852.050.553]
1618Produces the inverse of `a` by dividing `1` by `a`.
1633 (div [%f & --0 1] a)
1639 > (inv:fl [%f s=%.y e=--0 a=10])
1640 [%f s=%.y e=-116 a=8.307.674.973.655.724.205.648.794.126.752.154]
1641 > (drg:fl [%f s=%.y e=-116 a=8.307.674.973.655.724.205.648.794.126.752.154])
1644 > (inv:fl [%f s=%.y e=--1 a=10])
1645 [%f s=%.y e=-117 a=8.307.674.973.655.724.205.648.794.126.752.154]
1646 > (drg:fl [%f s=%.y e=-117 a=8.307.674.973.655.724.205.648.794.126.752.154])
1649 > (inv:fl [%f s=%.y e=--2 a=10])
1650 [%f s=%.y e=-118 a=8.307.674.973.655.724.205.648.794.126.752.154]
1651 > (drg:fl [%f s=%.y e=-118 a=8.307.674.973.655.724.205.648.794.126.752.154])
1652 [%d s=%.y e=-3 a=25]
1658Signed integer to float
1660Produces `a` in floating-point representation.
1664`a` is an unsigned integer.
1682 [%f s=%.y e=--0 a=0]
1684 > (sun:fl 5.048.729)
1685 [%f s=%.y e=-90 a=6.250.023.776.601.238.669.911.180.544.311.296]
1694Signed integer to float
1696Produces the floating-point representation of `a`, an unsigned integer.
1700`a` is an unsigned integer.
1712 (rou [%f -.b --0 +.b])
1719 [%f s=%.y e=-106 a=8.112.963.841.460.668.169.578.900.514.406.400]
1722 [%f s=%.n e=-106 a=8.112.963.841.460.668.169.578.900.514.406.400]
1730Tests if `a` is less than `b`. Returns `~` in the event of `a` or `b` being a
1747 |= [a=fn b=fn] ^- (unit ?)
1748 ?: |(?=([$n *] a) ?=([$n *] b)) ~ :- ~
1750 ?: ?=([$i *] a) !s.a ?: ?=([$i *] b) s.b
1751 ?: |(=(a.a 0) =(a.b 0))
1752 ?: &(=(a.a 0) =(a.b 0)) |
1753 ?: =(a.a 0) s.b !s.a
1755 ?: s.a (^lth +>.a +>.b) (^lth +>.b +>.a)
1761 > (lth:fl (sun:fl 116) (sun:fl 4.820))
1764 > (lth:fl (sun:fl 218.116) (sun:fl 4.820))
1767 > (lth:fl (sun:fl 218.116) [%n ~])
1776Tests whether `a` is less than or equal to `b`. Returns `~` in the event of `a`
1777or `b` being a NaN (`[%n ~]`).
1793 |= [a=fn b=fn] ^- (unit ?)
1794 %+ bind (lth b a) |= a=? !a
1800 > (lte:fl (sun:fl 102) [%f %.y -5 973.655.724])
1803 > (lte:fl (sun:fl 102) [%f %.y -24 973.655.724])
1806 > (lte:fl [%f %.y --2 25] (sun:fl 100))
1809 > (lte:fl [%f %.y --2 25] [%f %.y --3 2])
1812 > (lte:fl [%f %.y --2 25] [%n ~])
1821Tests if `a` is equal to `b`. Returns `~` in the event of `a` or `b` being a NaN
1838 |= [a=fn b=fn] ^- (unit ?)
1839 ?: |(?=([$n *] a) ?=([$n *] b)) ~ :- ~
1841 ?: |(?=([$i *] a) ?=([$i *] b)) |
1842 ?: |(=(a.a 0) =(a.b 0))
1843 ?: &(=(a.a 0) =(a.b 0)) & |
1844 ?: |(=(e.a e.b) !=(s.a s.b)) |
1851 > (equ:fl [%f %.y --2 25] (sun:fl 100))
1854 > (equ:fl [%f %.y --2 25] (sun:fl 101))
1861Greater or equal than
1863Tests whether `a` is greater than or equal to `b`. Returns `~` in the event of
1864`a` or `b` being a NaN (`[%n ~]`).
1880 |= [a=fn b=fn] ^- (unit ?) (lte b a)
1886 > (gte:fl [%f %.y --2 25] (sun:fl 100))
1889 > (gth:fl [%f %.y --6 73.989] [%f %.y --5 919.599])
1892 > (gth:fl [%f %.y --6 73.989] [%n ~])
1901Tests whether `a` is greater than `b`. Returns `~` in the event of `a` or `b`
1902being a NaN (`[%n ~]`).
1918 |= [a=fn b=fn] ^- (unit ?) (lth b a)
1924 > (gth:fl [%f %.y --2 25] (sun:fl 100))
1927 > (gth:fl [%f %.y --6 73.989] [%f %.y --5 119.599])
1936Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
1937accurate results for rounded floats.
1952 ?: ?=([$n *] a) [%n ~]
1953 ?: ?=([$i *] a) [%i s.a]
1954 ?~ a.a [%d s.a --0 0]
1955 [%d s.a (^drg +>.a)]
1961 > (drg:fl [%f | --6 73.989])
1962 [%d s=%.n e=--0 a=4.735.296]
1970Converts decimal `a` to `fn`.
1985 ?: ?=([$n *] a) [%n ~]
1986 ?: ?=([$i *] a) [%i s.a]
1990 (mul [%f s.a --0 a.a] [%f & e.a (pow 5 q)])
1991 (div [%f s.a --0 a.a] [%f & (sun:si q) (pow 5 q)])
1997 > (grd:fl [%d s=%.n e=--0 a=73.989])
1998 [%f s=%.n e=-96 a=5.862.012.516.267.904.074.208.723.341.410.304]
2000 > (grd:fl [%d s=%.n e=--0 a=100])
2001 [%f s=%.n e=-106 a=8.112.963.841.460.668.169.578.900.514.406.400]
2007Round to signed integer
2009Rounds `a` to the nearest signed integer.
2023 |= [a=fn] ^- (unit @s)
2025 ?. ?=([$f *] b) ~ :- ~
2026 =+ c=(^^mul (bex (abs:si e.b)) a.b)
2033 > (toi:fl [%f s=%.y e=-78 a=8.112.963.841.460.668.169.578.900.514.406.400])
2034 [~ u=--26.843.545.600]
2042Rounds `a` to the nearest decimal integer.
2060 =.(r swr (fli (^toj +>.a)))
2067 > (toj:fl [%f s=%.y e=-78 a=8.112.963.841.460.668.169.578.900.514.406.400])
2068 [%f s=%.y e=--0 a=26.843.545.600]
2070 > (toj:fl [%f s=%.y e=-78 a=8.112.963.841.460.668.169.578.900.514])
2071 [%f s=%.y e=--0 a=26.844]
2073 > (toj:fl [%f s=%.y e=-78 a=8.112.963.841.460])
2074 [%f s=%.y e=--0 a=0]
2076 > (toj:fl [%f s=%.y e=-9 a=9.002])
2077 [%f s=%.y e=--0 a=16]
2085Container core for IEEE-754 formatting operations.
2087- `w` is width: The number of bits in the exponent field.
2088- `p` is precision: The number of bits in the significand field.
2089- `w` is bias: Added to exponent when storing.
2090- `r` is rounding mode: Possible modes are nearest (`$n`), up (`$u`),
2091 down (`$d`), to zero (`$z`), and away from zero (`$a`). Default value is `%a`.
2097 |_ [[w=@u p=@u b=@s] r=$?($n $u $d $z $a)]
2103 > =ffcore ~(. ff [8 8 0] %n)
2105 <24.ltg {{{@ud @ud @ud} r/$n} <54.tyv 119.wim 31.ohr 1.jmk $143>}>
2112`++ff` has no use outside of the functionality provided to other cores: `++rd`,
2113`++rs`, `++rq`, and `++rh`. It's not intended to be used directly; it's just
2114meant to power those cores.
2121Produces the sign bit of `++ff`.
2126 ++ sb (bex (^add w p))
2141Produces the minimum possible exponent of `ff`.
2146 ++ me (dif:si (dif:si --1 b) (sun:si p))
2161Instantiates the core `fl`, giving values to its samples based on the
2162configuration of the `ff` core.
2168 %*(. fl p +(p), v me, w (^sub (bex w) 3), d %d, r r)
2174 > ~(pa ff [11 52 --1.023] %n)
2177 { {{p/@ v/@s w/@} r/?($n $u $a $d $z) d/$d}
2178 <54.tyv 119.wim 31.ohr 1.jmk $143>
2185`++pa` exists exclusively for internal use of `++ff`, and `++ff` exists for
2186internal use in other cores.
2193Converts `a` from `@r` to `fn`.
2197`a` is a `@r`, an IEEE float.
2208 =+ [f=(cut 0 [0 p] a) e=(cut 0 [p w] a)]
2211 ?: =(f 0) [%f s --0 0] [%f s me f]
2213 ?: =(f 0) [%i s] [%n ~]
2214 =+ q=:(sum:si (sun:si e) me -1)
2215 =+ r=(^add f (bex p))
2223 [%f s=%.y e=--0 a=0]
2229`fn` to `@r`, rounding
2231Converts `a` from `fn` to `@r` and applies rounding.
2244 ++ bit |= [a=fn] (bif (rou:pa a))
2250 > (bit:ma:rd [%f | -6 202])
2257`fn` to `@r`, no rounding
2259Converts `a` from `fn` to `@r`. No rounding is applied.
2263`a` is a `@r`, an IEEE float.
2275 =+ q=(lsh 0 p (fil 0 w 1))
2276 ?: s.a q (^add q sb)
2277 ?: ?=([$n *] a) (lsh 0 (dec p) (fil 0 +(w) 1))
2278 ?~ a.a ?: s.a `@r`0 sb
2283 ?: s.a `@r`a.a (^add a.a sb)
2284 =+ q=(sum:si (dif:si e.a me) --1)
2285 =+ r=(^add (lsh 0 p (abs:si q)) (end 0 p a.a))
2286 ?: s.a r (^add r sb)
2301Produces the sign of `a`.
2305`a` is a `@r`, an IEEE float.
2316 =(0 (cut 0 [(^add p w) 1] a))
2331Produces the exponent of `a`.
2335`a` is a `@r`, an IEEE float.
2346 (dif:si (sun:si (cut 0 [p w] a)) b)
2361Produces the sum of `a` plus `b`.
2365`a` is a `@r`, an IEEE float.
2367`b` is a `@r`, an IEEE float.
2371A `@r`, an IEEE float.
2378 (bif (add:pa (sea a) (sea b)))
2384 > (add:ma:rd `@r`5 `@r`11)
2393Produces the sum of `a` plus `b`.
2397`a` is a `@r`, an IEEE float.
2399`b` is a `@r`, an IEEE float.
2403A `@r`, an IEEE float.
2410 (bif (sub:pa (sea a) (sea b)))
2416 > (sub:ma:rd `@r`5 `@r`11)
2425Produces the product of `a` multiplied by `b`.
2429`a` is a `@r`, an IEEE float.
2431`b` is a `@r`, an IEEE float.
2435A `@r`, an IEEE float.
2442 (bif (mul:pa (sea a) (sea b)))
2448 > (mul:ma:rd `@r`11 `@r`2)
2457Produces the quotient of `a` divided by `b`.
2461`a` is a `@r`, an IEEE float.
2463`b` is a `@r`, an IEEE float.
2467A `@r`, an IEEE float.
2474 (bif (div:pa (sea a) (sea b)))
2480 > (div:ma:rd `@r`175 `@r`26)
2489Produces the sum of `c` plus the product of `a` multiplied by `b`;
2494`a` is a `@r`, an IEEE float.
2496`b` is a `@r`, an IEEE float.
2498`c` is a `@r`, an IEEE float.
2502A `@r`, an IEEE float.
2509 (bif (fma:pa (sea a) (sea b) (sea c)))
2515 > (fma:ma:rd `@r`175 `@r`26 `@r`100)
2524Produces the square root of `a`.
2528`a` is a `@r`, an IEEE float.
2532A `@r`, an IEEE float.
2539 (bif (sqt:pa (sea a)))
2545 > (sqt:ma:rd `@r`175)
2554Tests whether `a` is less than `b`.
2558`a` is a `@r`, an IEEE float.
2560`b` is a `@r`, an IEEE float.
2570 |= [a=@r b=@r] (fall (lth:pa (sea a) (sea b)) |)
2576 > (lth:ma:rd `@rd`1 `@rd`2)
2579 > (lth:ma:rd `@rd`10 `@rd`2)
2586Less than or equal to
2588Tests whether `a` is less than or equal to `b`.
2592`a` is a `@r`, an IEEE float.
2594`b` is a `@r`, an IEEE float.
2604 |= [a=@r b=@r] (fall (lte:pa (sea a) (sea b)) |)
2610 > (lte:ma:rd `@rd`10 `@rd`2)
2613 > (lte:ma:rd `@rd`10 `@rd`10)
2622Tests whether `a` is equal to `b`.
2626`a` is a `@r`, an IEEE float.
2628`b` is a `@r`, an IEEE float.
2638 |= [a=@r b=@r] (fall (equ:pa (sea a) (sea b)) |)
2644 > (equ:ma:rd `@rd`10 `@rd`2)
2647 > (equ:ma:rd `@rd`10 `@rd`10)
2654Greater or equal than
2656Tests whether `a` is greater than or equal to `b`.
2660`a` is a `@r`, an IEEE float.
2662`b` is a `@r`, an IEEE float.
2672 |= [a=@r b=@r] (fall (gte:pa (sea a) (sea b)) |)
2678 > (gte:ma:rd `@rd`10 `@rd`10)
2681 > (gte:ma:rd `@rd`10 `@rd`11)
2690Tests whether `a` is greater than or equal to `b`.
2694`a` is a `@r`, an IEEE float.
2696`b` is a `@r`, an IEEE float.
2706 |= [a=@r b=@r] (fall (gth:pa (sea a) (sea b)) |)
2712 > (gth:ma:rd `@rd`10 `@rd`10)
2715 > (gth:ma:rd `@rd`10 `@rd`9)
2722Unsigned integer to `@r`
2724Converts `a` from an unsigned integer (`@u`) to `@r`.
2728`a` is `@u`, unsigned integer.
2732A `@r`, an IEEE float.
2738 |= [a=@u] (bit [%f & --0 a])
2744 > (sun:ma:rd 658.149.282)
2751Signed integer to `@r`
2753Converts `a` from a signed integer to `@r`.
2757`a` is `@s`, an unsigned integer
2761A `@r`, an IEEE float.
2767 |= [a=@s] (bit [%f (syn:si a) --0 (abs:si a)])
2782Rounds `a` to the nearest signed integer.
2786`a` is a `@r`, an IEEE float.
2796 |= [a=@r] (toi:pa (sea a))
2802 > (toi:ma:rd `@r`0x4af)
2809`@r` to decimal float
2811Converts `a` from `@r` to `dn` using the Dragon4 algorithm.
2815`a` is a `@r`, an IEEE float.
2825 |= [a=@r] (drg:pa (sea a))
2831 > (drg:ma:rd `@r`0x41c0)
2832 [%d s=%.y e=-323 a=8.316]
2834 > (drg:ma:rd (sun:ma:rd 658.149.282))
2835 [%d s=%.y e=--0 a=658.149.282]
2841Decimal float to `@r`
2843Converts `a` from `dn` to `@r`.
2851A `@r`, an IEEE float.
2857 |= [a=dn] (bif (grd:pa a))
2864 > (grd:ma:rd [%d s=%.y e=--0 a=658.149.282])
2873Converts `a` from a double-precision binary float to decimal64.
2877`a` is a `@rd`, a double-precision float.
2886 ++ rlyd |= a=@rd ^- dn (drg:rd a)
2892 > (rlyd .~2.4703e-320)
2893 [%d s=%.y e=-324 a=24.703]
2901Converts `a` from a single-precision binary float to decimal32.
2905`a` is a `@rs`, a single-precision float.
2914 ++ rlys |= a=@rs ^- dn (drg:rs a)
2920 > (rlys .1.681557e-39)
2921 [%d s=%.y e=-45 a=1.681.557]
2929Converts `a` from a half-precision binary float to decimal16.
2933`a` is a `@rh`, a half-precision float.
2942 ++ rlyh |= a=@rh ^- dn (drg:rh a)
2949 [%d s=%.y e=--1 a=3]
2957Converts `a` from a quad-precision binary float to decimal128.
2961`a` is a `@rq`, a quad-precision float.
2970 ++ rlyq |= a=@rq ^- dn (drg:rq a)
2976 > (rlyq .~~~2.2628017865927756787440310766086816e-4343)
2977 [%d s=%.y e=-4.377 a=22.628.017.865.927.756.787.440.310.766.086.816]
2985Converts `a` from a decimal float to a double-precision binary float.
2993A a `@rd`, a double-precision float.
2998 ++ ryld |= a=dn ^- @rd (grd:rd a)
3004 > (ryld [%d s=%.y e=-324 a=24.703])
3013Converts `a` from a decimal float to a single-precision binary float.
3021A a `@rs`, a single-precision float.
3026 ++ ryls |= a=dn ^- @rs (grd:rs a)
3032 > (ryls [%d s=%.y e=-324 a=24.703])
3035 > (ryls [%d s=%.y e=-32 a=24.703])
3044Converts `a` from a decimal float to a half-precision binary float.
3052A a `@rh`, a half-precision float.
3057 ++ rylh |= a=dn ^- @rh (grd:rh a)
3063 > (rylh [%d s=%.y e=--1 a=703])
3066 > (rylh [%d s=%.y e=--3 a=56])
3069 > (rylh [%d s=%.y e=--4 a=56])
3078Converts `a` from a decimal float to a quad-precision binary float.
3086A a `@rq`, a quad-precision float.
3091 ++ rylq |= a=dn ^- @rq (grd:rq a)
3097 > (rylq [%d s=%.y e=-324 a=24.703])
3106A container core for operations related to double-precision binary floats.
3108`++rd` has four rounding modes: round to nearest (`$n`), round up (`$u`), round
3109down (`$d`), and round to zero (`$z`).
3117 |_ r=$?($n $u $d $z)
3125Instantiates the core `ff`, giving values to its samples based on the
3126configuration of the `rd` core.
3132 %*(. ff w 11, p 52, b --1.023, r r)
3140 {{{w/@ud p/@ud b/@sd} r/?($n $u $d $z)} <54.tyv 119.wim 31.ohr 1.jmk $143>}
3149Converts `a` from a double-precision binary float to `fn`.
3153 |= [a=@rd] (sea:ma a)
3159 > (sea:rd .~4.94066e-319)
3160 [%f s=%.y e=-1.074 a=100.000]
3168Converts `a` from `fn` to a double-precision binary float.
3176A `@rd`, a double-precision float.
3182 |= [a=fn] ^- @rd (bit:ma a)
3188 > (bit:rd [%f s=%.y e=-1.074 a=100.000])
3197Produces the sum of `a` plus `b`.
3201`a` is a `@rd`, a double-precision float.
3203`b` is a `@rd`, a double-precision float.
3213 |= [a=@rd b=@rd] ^- @rd
3221 > (add:rd .~3.94066e12 .~9.2846e11)
3230Produces the difference of `a` minus `b`.
3234`a` is a `@rd`, a double-precision float.
3236`b` is a `@rd`, a double-precision float.
3246 |= [a=@rd b=@rd] ^- @rd
3254 > (sub:rd .~7.94069e2 .~1.2846e3)
3255 .~-4.9053099999999995e2
3263Produces the product of `a` times `b`.
3267`a` is a `@rd`, a double-precision float.
3269`b` is a `@rd`, a double-precision float.
3279 |= [a=@rd b=@rd] ^- @rd
3287 > (mul:rd .~7.94069e2 .~1.2246e3)
3288 .~9.724168973999998e5
3296Produces the quotient of `a` divided by `b`.
3300`a` is a `@rd`, a double-precision float.
3312 |= [a=@rd b=@rd] ^- @rd
3320 > (div:rd .~7.94099e2 .~1.2246e3)
3321 .~6.484558223093255e-1
3329Produces the sum of `c` plus the product of `a` multiplied by `b`;
3334`a` is a `@rd`, an IEEE float.
3351 |= [a=@rd b=@rd c=@rd] ^- @rd
3359 > (fma:rd .~7.94099e2 .~1.2246e3 .~3.94066e3)
3368Produces the square root of `a`.
3372`a` is a `@rd`, a double-precision float.
3382 |= [a=@rd] ^- @rd ~_ leaf+"rd-fail"
3389 > (sqt:rd .~3.94066e3)
3390 .~6.2774676422901614e1
3398Test whether `a` is less than `b`.
3402`a` is a `@rd`, a double-precision float.
3404`b` is a `@rd`, a double-precision float.
3422 > (lth:rd .~7.94099e2 .~1.2246e3)
3425 > (lth:rd .~7.94099e2 .~1.2246e2)
3428 > (lth:rd .~1.2246e2 .~1.2246e2)
3437Test whether `a` is less than or equal to `b`.
3441`a` is a `@rd`, a double-precision float.
3443`b` is a `@rd`, a double-precision float.
3452 ++ lte ~/ %lte :: less-equals
3461 > (lte:rd .~7.94099e2 .~1.2246e3)
3464 > (lte:rd .~7.94099e2 .~1.2246e2)
3467 > (lte:rd .~1.2246e2 .~1.2246e2)
3476Test whether `a` is equal to `b`.
3480`a` is a `@rd`, a double-precision float.
3482`b` is a `@rd`, a double-precision float.
3500 > (equ:rd .~7.94099e2 .~1.2246e3)
3503 > (equ:rd .~7.94099e2 .~1.2246e2)
3506 > (equ:rd .~1.2246e2 .~1.2246e2)
3513Greater than or equal
3515Test whether `a` is greater than or equal to `b`.
3519`a` is a `@rd`, a double-precision float.
3521`b` is a `@rd`, a double-precision float.
3539 > (gte:rd .~7.94099e2 .~1.2246e3)
3542 > (gte:rd .~7.94099e2 .~1.2246e2)
3545 > (gte:rd .~1.2246e2 .~1.2246e2)
3554Test whether `a` is greater `b`.
3558`a` is a `@rd`, a double-precision float.
3560`b` is a `@rd`, a double-precision float.
3578 > (gth:rd .~7.94099e2 .~1.2246e3)
3581 > (gth:rd .~7.94099e2 .~1.2246e2)
3584 > (gth:rd .~1.2246e2 .~1.2246e2)
3591Unsigned integer to `@rd`
3593Converts an unsigned integer `a` to `@rd`.
3597`a` is a `@u`, an unsigned integer.
3606 ++ sun |= [a=@u] ^- @rd (sun:ma a)
3619Unsigned integer to `@rd`
3621Converts a signed integer `a` to `@rd`.
3625`a` is a `@s`, a signed integer.
3634 ++ san |= [a=@s] ^- @rd (san:ma a)
3649Produces the sign of `a`.
3662 ++ sig |= [a=@rd] ^- ? (sig:ma a)
3668 > (sig:rd .~1.2246e3)
3677Produces the exponent of `a`.
3690 ++ exp |= [a=@rd] ^- @s (exp:ma a) :: get exponent
3696 > (exp:rd .~1.2246e3)
3705Rounds `a` to the nearest integer.
3718 ++ toi |= [a=@rd] ^- (unit @s) (toi:ma a)
3724 > (toi:rd .~1.2246e3)
3731`@rd` to decimal float
3733Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
3734accurate results for rounded floats.
3747 ++ drg |= [a=@rd] ^- dn (drg:ma a)
3753 > (drg:rd .~1.2246e3)
3754 [%d s=%.y e=-1 a=12.246]
3760Decimal float to `@rd`
3762Converts `a` from decimal float to `@rd`.
3775 ++ grd |= [a=dn] ^- @rd (grd:ma a) :: decimal float to @rd
3782 > (grd:rd [%d s=%.y e=-1 a=12.246])
3791A container core for operations related to single-precision binary floats.
3793`++rs` has four rounding modes: round to nearest (`$n`), round up (`$u`), round
3794down (`$d`), and round to zero (`$z`).
3802 |_ r=$?($n $u $d $z)
3810Instantiates the core `ff`, giving values to its samples based on the
3811configuration of the `rs` core.
3817 %*(. ff w 8, p 23, b --127, r r)
3825 {{{w/@ud p/@ud b/@sd} r/?($n $u $d $z)} <54.tyv 119.wim 31.ohr 1.jmk $143>}
3834Converts `a` from `@rs` to `fn`.
3838`a` is a `@rs`, an single-precision float.
3848 |= [a=@rs] (sea:ma a)
3855 [%f s=%.y e=-149 a=100]
3863Converts `a` from `fn` to `@rs`.
3871A `@rs`, a single-precision float.
3877 |= [a=fn] ^- @rs (bit:ma a)
3883 > (bit:rs [%f & -2 1.000])
3892Produces the sum of `a` plus `b`.
3896`a` is a `@rs`, a single-precision float.
3908 |= [a=@rs b=@rs] ^- @rs
3916 > (add:rs .2.5e1 .2.5e2)
3925Subtracts `a` from `b`.
3931 |= [a=@rs b=@rs] ^- @rs
3939 > (sub:rs .2.5e1 .2.5e2)
3948Produces the product of `a` multiplied by `b`.
3952`a` is a `@rs`, a single-precision float.
3964 |= [a=@rs b=@rs] ^- @rs
3972 > (mul:rs .2.5e1 .2.5e2)
3981Produces the quotient of `a` divided by `b`.
3985`a` is a `@rs`, a single-precision float.
3997 |= [a=@rs b=@rs] ^- @rs
4005 > (div:rs .4.5e1 .2.2e2)
4014Produces the sum of `c` plus the product of `a` multiplied by `b`;
4019`a` is a `@rs`, a single-precision float.
4033 |= [a=@rs b=@rs c=@rs] ^- @rs
4041 > (fma:rs .2.5e1 .2.5e2 .8.2e1)
4050Produces the square root of `a`.
4054`a` is a `@rs`, a single-precision float.
4081Test whether `a` is less than `b`.
4085`a` is a `@rs`, a single-precision float.
4105 > (lth:rs .9.9e1 .1.1e2)
4108 > (lth:rs .9.9e1 .9.9e1)
4117Test whether `a` is less than or equal to `b`.
4121`a` is a `@rs`, a single-precision float.
4141 > (lte:rs .9.9e1 .1.1e2)
4144 > (lte:rs .9.9e1 .9.9e1)
4153Test whether `a` is equal to `b`.
4157`a` is a `@rs`, a single-precision float.
4177 > (equ:rs .9.9e1 .1.1e2)
4180 > (equ:rs .9.9e1 .9.9e1)
4187Greater than or equal
4189Test whether `a` is greater than or equal to `b`.
4193`a` is a `@rs`, a single-precision float.
4213 > (gte:rs .9.9e1 .9.9e1)
4216 > (gte:rs .9.9e1 .9.2e2)
4225Test whether `a` is greater than `b`.
4229`a` is a `@rs`, a single-precision float.
4249 > (gth:rs .9.9e1 .9.2e2)
4252 > (gth:rs .9.9e1 .9.9e1)
4255 > (gth:rs .9.9e1 .1.9e1)
4262Unsigned integer to `@rs`
4264Converts `a` from an unsigned integer to `@rs`.
4268`a` is an unsigned integer.
4277 ++ sun |= [a=@u] ^- @rs (sun:ma a)
4290Signed integer to `@rs`'
4292Converts `a` from an unsigned integer to `@rs`.
4296`a` is a signed integer.
4305 ++ san |= [a=@s] ^- @rs (san:ma a)
4319Produces the sign of `a`.
4332 ++ sig |= [a=@rs] ^- ? (sig:ma a)
4350Produces the exponent of `a`.
4363 ++ exp |= [a=@rs] ^- @s (exp:ma a)
4378Rounds `a` to the nearest integer.
4391 ++ toi |= [a=@rs] ^- (unit @s) (toi:ma a)
4404`@rs` to decimal float
4406Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
4407accurate results for rounded floats.
4420 ++ drg |= [a=@rs] ^- dn (drg:ma a)
4427 [%d s=%.n e=--0 a=343]
4433Decimal float to `@rs`
4435Converts `a` from `dn` to `@rs`.
4448 ++ grd |= [a=dn] ^- @rs (grd:ma a)
4455 > (grd:rs [%d s=%.n e=--0 a=343])
4462Quadruple-precision fp
4464A container core for operations related to quadruple-precision binary floats.
4466`++rq` has four rounding modes: round to nearest (`$n`), round up (`$u`), round
4467down (`$d`), and round to zero (`$z`).
4475 |_ r=$?($n $u $d $z)
4482Instantiates the core `ff`, giving values to its samples based on the
4483configuration of the `rq` core.
4489 %*(. ff w 15, p 112, b --16.383, r r)
4497Converts `a` from `@rq` to `fn`.
4501`a` is a `@rq`, a quad-precision float.
4511 |= [a=@rq] (sea:ma a)
4517 > (sea:rq .~~~1.05102e5)
4518 [%f s=%.y e=-96 a=8.327.038.336.574.210.409.756.656.268.214.272]
4526Converts `a` from `fn` to `@rq`.
4534A `@rq`, a quad-precision float.
4540 |= [a=n] ^- @rq (bit:ma a)
4546 > (bit:rq [%f s=%.y e=-96 a=8.327.038.336.574.210.409.756.656.268.214.272])
4555Produces the sum of `a` plus `b`.
4559`a` is a `@rq`, a quad-precision float.
4571 |= [a=@rq b=@rq] ^- @rq
4579 > (add:rq .~~~-1.821e5 .~~~1.05102e5)
4588Produces the difference of `a` minus `b`.
4592`a` is a `@rq`, a quad-precision float.
4604 |= [a=@rq b=@rq] ^- @rq
4612 > (sub:rq .~~~1.821e5 .~~~1.05102e5)
4615 > (sub:rq .~~~1.821e5 .~~~-1.05102e5)
4624Produces the product of `a` times `b`.
4628`a` is a `@rq`, a quad-precision float.
4640 |= [a=@rq b=@rq] ^- @rq
4648 > (mul:rq .~~~1.821e5 .~~~-1.05102e5)
4657Produces the product of `a` divided by `b`.
4661`a` is a `@rq`, a quad-precision float.
4673 |= [a=@rq b=@rq] ^- @rq
4681 > (div:rq .~~~1.821e5 .~~~1.05102e3)
4682 .~~~1.732602614602957127361991208540275e2
4690Produces the sum of `c` plus the product of `a` multiplied by `b`;
4695`a` is a `@rq`, a quad-precision float.
4709 |= [a=@rq b=@rq c=@rq] ^- @rq
4717 > (fma:rq .~~~1.821e5 .~~~-1.05102e2 .~~~6.2044e7)
4726Produces the square root of `a`.
4730`a` is a `@rq`, a quad-precision float.
4748 > (sqt:rq .~~~6.2044e7)
4749 .~~~7.876801381271461258959876570289002e3
4757Tests whether `a` is less than `b`.
4761`a` is a `@rq`, a quad-precision float.
4782 > (lth:rq .~~~1.2044e7 (mul:rq .~~~9.02e2 .~~~7.114e3))
4785 > (lth:rq .~~~1.2044e7 (mul:rq .~~~9.02e3 .~~~7.114e3))
4794Tests whether `a` is less than or equal to `b`.
4798`a` is a `@rq`, a quad-precision float.
4818 > (lte:rq .~~~1.2044e7 (mul:rq .~~~9.02e2 .~~~7.114e3))
4821 > (lte:rq .~~~1.2044e7 (mul:rq .~~~9.02e3 .~~~7.114e3))
4824 > (lte:rq .~~~1.2044e7 .~~~1.2044e7)
4833Tests whether `a` is equal to `b`.
4837`a` is a `@rq`, a quad-precision float.
4857 > (equ:rq .~~~1.2044e7 .~~~1.2044e7)
4860 > (equ:rq .~~~2.2044e7 .~~~1.2044e7)
4867Greater than or equal
4869Tests whether `a` is greater than or equal to `b`.
4873`a` is a `@rq`, a quad-precision float.
4893 > (gte:rq .~~~1.2044e7 .~~~1.2044e7)
4896 > (gte:rq .~~~2.2044e7 .~~~1.2044e7)
4899 > (gte:rq .~~~1.2044e7 .~~~2.2044e7)
4906Tests whether `a` is greater than `b`.
4910`a` is a `@rq`, a quad-precision float.
4930 > (gth:rq .~~~1.2044e7 .~~~1.2044e7)
4933 > (gth:rq .~~~2.2044e7 .~~~1.2044e7)
4936 > (gth:rq .~~~1.2044e7 .~~~2.2044e7)
4943Unsigned integer to `@rq`
4945Converts `@` from an unsigned integer to `@rq`.
4949`a` is a `@u`, an unsigned integer.
4953A `@rq`, a quad-precision float.
4958 ++ sun |= [a=@u] ^- @rq (sun:ma a)
4971Signed integer to `rq`
4973Converts `@` from a signed integer to `@rq`.
4977`a` is a `@s`, a signed integer.
4981A `@rq`, a quad-precision float.
4986 ++ san |= [a=@s] ^- @rq (san:ma a)
5001Produces the sign of `a`.
5005`a` is a `@rq`, a quad-precision float.
5014 ++ sig |= [a=@rq] ^- ? (sig:ma a)
5020 > (sig:rq .~~~-2.05e2)
5029Gets the exponent of `a`.
5033`a` is a `@rq`, a quad-precision float.
5037A `@s`, a signed integer.
5042 ++ exp |= [a=@rq] ^- @s (exp:ma a)
5048 > (exp:rq .~~~-2.05e2)
5057Rounds `a` to the nearest integer.
5061`a` is a `@rq`, a quad-precision float.
5070 ++ toi |= [a=@rq] ^- (unit @s) (toi:ma a)
5076 > (toi:rq .~~~-2.085e2)
5079 > (toi:rq .~~~-2.08e2)
5086`@rq` to decimal float
5088Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
5089accurate results for rounded floats.
5093`a` is a `@rq`, a quad-precision float.
5102 ++ drg |= [a=@rq] ^- dn (drg:ma a) :: @rq to decimal float
5108 > (drg:rq .~~~-2.085e2)
5109 [%d s=%.n e=-1 a=2.085]
5111 > (drg:rq .~~~-2.08e2)
5112 [%d s=%.n e=--0 a=208]
5118Decimal float to `@rq`
5120Converts `a` from `dn` to `@rq`.
5130A `@rq`, a quad-precision float.
5135 ++ grd |= [a=dn] ^- @rq (grd:ma a)
5142 > (grd:rq [%d s=%.n e=--0 a=343])
5151A container core for operations related to half-precision binary floats.
5153`++rh` has four rounding modes: round to nearest (`$n`), round up (`$u`), round
5154down (`$d`), and round to zero (`$z`).
5162 |_ r=$?($n $u $d $z)
5170Instantiates the core `ff`, giving values to its samples based on the
5171configuration of the `rh` core.
5177 %*(. ff w 5, p 10, b --15, r r)
5185Converts `a` from `@rh` to `fn`.
5189`a` is a `@rh`, a half-precision float.
5199 |= [a=@rh] (sea:ma a)
5205 > (sea:rh .~~1.22e-5)
5206 [%f s=%.y e=-24 a=205]
5214Converts `a` from `fn` to `@rh`.
5222A `@rh`, a half-precision float.
5228 |= [a=fn] ^- @rh (bit:ma a)
5234 > (bit:rh [%f s=%.y e=-24 a=205])
5241Produces the sum of `a` plus `b`.
5245`a` is a `@rh`, a half-precision float.
5257 |= [a=@rh b=@rh] ^- @rh
5265 > (add:rh .~~1.82e2 .~~1.02e2)
5274Produces the difference of `a` minus `b`.
5278`a` is a `@rh`, a half-precision float.
5290 |= [a=@rh b=@rh] ^- @rh
5298 > (sub:rh .~~1.821e2 .~~1.051e2)
5301 > (sub:rh .~~1.821e2 .~~6.051e2)
5310Produces the product of `a` times `b`.
5314`a` is a `@rh`, a quad-precision float.
5326 |= [a=@rh b=@rh] ^- @rh
5334 > (mul:rh .~~1.821e1 .~~-1.05102e2)
5343Produces the product of `a` divided by `b`.
5347`a` is a `@rh`, a half-precision float.
5359 |= [a=@rh b=@rh] ^- @rh
5367 > (div:rh .~~1.821e3 .~~1.05102e2)
5376Produces the sum of `c` plus the product of `a` multiplied by `b`;
5381`a` is a `@rh`, a half-precision float.
5395 |= [a=@rh b=@rh c=@rh] ^- @rh
5403 > (fma:rh .~~1.821e4 .~~-1.05102e2 .~~6.2044e3)
5412Produces the square root of `a`.
5416`a` is a `@rh`, a half-precision float.
5434 > (sqt:rh .~~6.24e4)
5443Tests whether `a` is less than `b`.
5447`a` is a `@rh`, a half-precision float.
5467 > (lth:rh .~~1.2e5 (mul:rh .~~9.02e2 .~~7.114e2))
5470 > (lth:rh .~~1.2e3 (mul:rh .~~9.02e1 .~~7.114e2))
5479Tests whether `a` is less than or equal to `b`.
5483`a` is a `@rh`, a half-precision float.
5503 > (lte:rh .~~1.2e5 (mul:rh .~~9.02e2 .~~7.114e2))
5506 > (lte:rh .~~1.2e3 (mul:rh .~~9.02e1 .~~7.114e2))
5509 > (lte:rh .~~1.2e3 .~~1.2e3)
5518Tests whether `a` is equal to `b`.
5522`a` is a `@rh`, a half-precision float.
5542 > (equ:rh .~~1.24e4 .~~1.24e4)
5545 > (equ:rh .~~2.24e4 .~~1.24e4)
5552Greater than or equal
5554Tests whether `a` is greater than or equal to `b`.
5558`a` is a `@rh`, a half-precision float.
5578 > (gte:rh .~~1.24e4 .~~1.24e4)
5581 > (gte:rh .~~2.24e4 .~~1.24e4)
5584 > (gte:rh .~~1.24e4 .~~2.24e4)
5591Tests whether `a` is greater than `b`.
5595`a` is a `@rh`, a half-precision float.
5615 > (gth:rh .~~1.24e4 .~~1.244e4)
5618 > (gth:rh .~~2.24e4 .~~1.24e4)
5621 > (gth:rh .~~1.24e4 .~~2.24e4)
5631Converts `@` from `@rh` to `@rs`.
5635`a` is a `@rh`, a half-precision float.
5639A `@rs`, a single-precision float.
5644 ++ tos |= {a/@rh} (bit:rs (sea a))
5659Converts `@` from `@rs` to `@rh`.
5663`a` is a `@rs`, a single-precision float.
5667A `@rh`, a half-precision float.
5672 ++ fos |= {a/@rs} (bit (sea:rs a))
5685Unsigned integer to `@rh`
5687Converts `@` from an unsigned integer to `@rh`.
5691`a` is a `@u`, an unsigned integer.
5695A `@rh`, a half-precision float.
5700 ++ sun |= [a=@u] ^- @rh (sun:ma a)
5713Signed integer to `@rh`
5715Converts `@` from a signed integer to `@rh`.
5719`a` is a `@s`, a signed integer.
5723A `@rh`, a half-precision float.
5728 ++ san |= [a=@s] ^- @rh (san:ma a)
5743Produces the sign of `a`.
5747`a` is a `@rh`, a half-precision float.
5756 ++ sig |= [a=@rh] ^- ? (sig:ma a)
5762 > (sig:rh .~~-2.05e2)
5771Gets the exponent of `a`.
5775`a` is a `@rh`, a half-precision float.
5779A `@s`, a signed integer.
5784 ++ exp |= [a=@rh] ^- @s (exp:ma a)
5790 > (exp:rh .~~-2.05e2)
5799Rounds `a` to the nearest integer.
5803`a` is a `@rh`, a half-precision float.
5812 ++ toi |= [a=@rh] ^- (unit @s) (toi:ma a)
5818 > (toi:rh .~~-2.085e2)
5821 > (toi:rh .~~-2.08e2)
5828`@rh` to decimal float
5830Produces the decimal form of `a` using the Dragon4 algorithm. Guarantees
5831accurate results for rounded floats.
5835`a` is a `@rh`, a half-precision float.
5844 ++ drg |= [a=@rh] ^- dn (drg:ma a)
5850 > (drg:rh .~~-2.085e2)
5851 [%d s=%.n e=-1 a=2.085]
5853 > (drg:rh .~~-2.08e2)
5854 [%d s=%.n e=--0 a=208]
5860Decimal float to `@rh`
5862Converts `a` from `dn` to `@rh`.
5872A `@rh`, a a half-precision float.
5877 ++ grd |= [a=dn] ^- @rh (grd:ma a)
5884 > (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