Merge branch 'test' of https://github.com/urbit/urbit into test

Conflicts:
	urb/zod/lib/tree.hoon
This commit is contained in:
Anton Dyudin 2015-08-06 17:13:20 -07:00
commit 55d9f093d6

View File

@ -1278,7 +1278,7 @@
[%n ~] [%n ~]
== ==
:: ::
++ fl ++ fl :: arb. precision fp
=+ ^- [[p=@u v=@s w=@u] r=?(%n %u %d %z %a) d=?(%d %f %i)] =+ ^- [[p=@u v=@s w=@u] r=?(%n %u %d %z %a) d=?(%d %f %i)]
[[113 -16.494 32.765] %n %d] [[113 -16.494 32.765] %n %d]
:: p=precision: number of bits in arithmetic form; must be at least 2 :: p=precision: number of bits in arithmetic form; must be at least 2
@ -1289,7 +1289,9 @@
:: infinite exponent range :: infinite exponent range
=> =>
~% %cofl +> ~ ~% %cofl +> ~
|% :: don't put 0s into [@s @u] args :: internal functions; mostly operating on [e=@s a=@u], in other words
:: positive numbers. many of these have undefined behavior if a=0.
|%
++ rou ++ rou
|= [a=[e=@s a=@u]] ^- fn (rau a &) |= [a=[e=@s a=@u]] ^- fn (rau a &)
:: ::
@ -1301,17 +1303,17 @@
%n (lug %ne a t) %n (lug %ne a t)
== ==
:: ::
++ add ++ add :: add; exact if e
|= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn |= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn
=+ q=(dif:si e.a e.b) =+ q=(dif:si e.a e.b)
|- ?. (syn:si q) $(b a, a b, q +(q)) :: a has larger exponent |- ?. (syn:si q) $(b a, a b, q +(q)) :: a has larger exp
?: e ?: e
[%f & e.b (^add (lsh 0 (abs:si q) a.a) a.b)] [%f & e.b (^add (lsh 0 (abs:si q) a.a) a.b)]
=+ [ma=(met 0 a.a) mb=(met 0 a.b)] =+ [ma=(met 0 a.a) mb=(met 0 a.b)]
=+ ^= w %+ dif:si e.a %- sun:si :: expanded exponent of a =+ ^= w %+ dif:si e.a %- sun:si :: expanded exp of a
?: (gth prc ma) (^sub prc ma) 0 ?: (gth prc ma) (^sub prc ma) 0
=+ ^= x %+ sum:si e.b (sun:si mb) :: highest exponent that b reaches =+ ^= x %+ sum:si e.b (sun:si mb) :: highest exp for b
?: =((cmp:si w x) --1) :: don't actually need to add ?: =((cmp:si w x) --1) :: don't need to add
?- r ?- r
%z (lug %fl a &) %d (lug %fl a &) %z (lug %fl a &) %d (lug %fl a &)
%a (lug %lg a &) %u (lug %lg a &) %a (lug %lg a &) %u (lug %lg a &)
@ -1319,7 +1321,7 @@
== ==
(rou [e.b (^add (lsh 0 (abs:si q) a.a) a.b)]) (rou [e.b (^add (lsh 0 (abs:si q) a.a) a.b)])
:: ::
++ sub ++ sub :: subtract; exact if e
|= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn |= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn
=+ q=(dif:si e.a e.b) =+ q=(dif:si e.a e.b)
|- ?. (syn:si q) |- ?. (syn:si q)
@ -1341,11 +1343,11 @@
?~ i [%f & zer] ?~ i [%f & zer]
?: e [%f & e.b i] (rou [e.b i]) ?: e [%f & e.b i] (rou [e.b i])
:: ::
++ mul ++ mul :: multiply
|= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- fn |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- fn
(rou (sum:si e.a e.b) (^mul a.a a.b)) (rou (sum:si e.a e.b) (^mul a.a a.b))
:: ::
++ div ++ div :: divide
|= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- fn |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- fn
=+ [ma=(met 0 a.a) mb=(met 0 a.b)] =+ [ma=(met 0 a.a) mb=(met 0 a.b)]
=+ v=(dif:si (sun:si ma) (sun:si +((^add mb prc)))) =+ v=(dif:si (sun:si ma) (sun:si +((^add mb prc))))
@ -1354,18 +1356,7 @@
=+ [j=(dif:si e.a e.b) q=(dvr a.a a.b)] =+ [j=(dif:si e.a e.b) q=(dvr a.a a.b)]
(rau [j p.q] =(q.q 0)) (rau [j p.q] =(q.q 0))
:: ::
++ fma ++ sqt :: square root
|= [a=[e=@s a=@u] b=[e=@s a=@u] c=[e=@s a=@u]] ^- fn
(add [(sum:si e.a e.b) (^mul a.a a.b)] c |)
::
++ frd :: a/2, rounds to -inf
|= [a=@s]
=+ b=(old:si a)
?: |(-.b =((end 0 1 +.b) 0))
(new:si -.b (rsh 0 1 +.b))
(new:si -.b +((rsh 0 1 +.b)))
::
++ sqt
|= [a=[e=@s a=@u]] ^- fn |= [a=[e=@s a=@u]] ^- fn
=. a =. a
=+ [w=(met 0 a.a) x=(^mul +(prc) 2)] =+ [w=(met 0 a.a) x=(^mul +(prc) 2)]
@ -1373,10 +1364,10 @@
=+ ?: =((dis - 1) (dis (abs:si e.a) 1)) - =+ ?: =((dis - 1) (dis (abs:si e.a) 1)) -
(^add - 1) (^add - 1)
a(e (dif:si e.a (sun:si -)), a (lsh 0 - a.a)) a(e (dif:si e.a (sun:si -)), a (lsh 0 - a.a))
=+ [y=(^sqt a.a) z=(frd e.a)] =+ [y=(^sqt a.a) z=(fra:si e.a --2)]
(rau [z p.y] =(q.y 0)) (rau [z p.y] =(q.y 0))
:: ::
++ lth ++ lth :: less-than
|= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ? |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ?
?: =(e.a e.b) (^lth a.a a.b) ?: =(e.a e.b) (^lth a.a a.b)
=+ c=(cmp:si (ibl a) (ibl b)) =+ c=(cmp:si (ibl a) (ibl b))
@ -1385,7 +1376,7 @@
(^lth (rsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b) (^lth (rsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b)
(^lth (lsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b) (^lth (lsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b)
:: ::
++ lte ++ lte :: less-equals
|= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ? |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ?
?: =(e.a e.b) (^lte a.a a.b) ?: =(e.a e.b) (^lte a.a a.b)
=+ c=(cmp:si (ibl a) (ibl b)) =+ c=(cmp:si (ibl a) (ibl b))
@ -1394,7 +1385,7 @@
(^lte a.a (lsh 0 (abs:si (dif:si e.a e.b)) a.b)) (^lte a.a (lsh 0 (abs:si (dif:si e.a e.b)) a.b))
(^lte (lsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b) (^lte (lsh 0 (abs:si (dif:si e.a e.b)) a.a) a.b)
:: ::
++ equ ++ equ :: equals
|= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ? |= [a=[e=@s a=@u] b=[e=@s a=@u]] ^- ?
?. =((ibl a) (ibl b)) | ?. =((ibl a) (ibl b)) |
?: =((cmp:si e.a e.b) -1) ?: =((cmp:si e.a e.b) -1)
@ -1406,16 +1397,18 @@
|= [a=[e=@s a=@u]] ^- @s |= [a=[e=@s a=@u]] ^- @s
(sum:si (sun:si (dec (met 0 a.a))) e.a) (sum:si (sun:si (dec (met 0 a.a))) e.a)
:: ::
:: change to a representation where a.a is odd
:: every fn has a unique representation of this kind
++ uni ++ uni
|= [a=[e=@s a=@u]] |= [a=[e=@s a=@u]]
?< =(a.a 0)
|- ?: =((end 0 1 a.a) 1) a |- ?: =((end 0 1 a.a) 1) a
$(a.a (rsh 0 1 a.a), e.a (sum:si e.a --1)) $(a.a (rsh 0 1 a.a), e.a (sum:si e.a --1))
:: ::
:: expands to either full precision or to denormalized
:: assumes (met 0 a.a) <= precision
++ xpd ++ xpd
|= [a=[e=@s a=@u]] |= [a=[e=@s a=@u]]
=+ ma=(met 0 a.a) =+ ma=(met 0 a.a)
?< =(ma 0)
=+ ?: =(den %i) (^sub prc ma) =+ ?: =(den %i) (^sub prc ma)
=+ ^= q =+ ^= q
=+ w=(dif:si e.a emn) =+ w=(dif:si e.a emn)
@ -1423,13 +1416,16 @@
(min q (^sub prc ma)) (min q (^sub prc ma))
a(e (dif:si e.a (sun:si -)), a (lsh 0 - a.a)) a(e (dif:si e.a (sun:si -)), a (lsh 0 - a.a))
:: ::
:: in order: floor, ceiling, nearest (even, away from 0, toward 0), :: central rounding mechanism
:: larger, smaller; t=sticky bit :: can perform: floor, ceiling, smaller, larger,
:: nearest (round ties to: even, away from 0, toward 0)
:: s is sticky bit: represents a value less than ulp(a) = 2^(e:(xpd a))
++ lug ++ lug
~/ %lug ~/ %lug
|= [t=?(%fl %ce %ne %na %nt %lg %sm) a=[e=@s a=@u] s=?] ^- fn |= [t=?(%fl %ce %sm %lg %ne %na %nt) a=[e=@s a=@u] s=?] ^- fn
?< =(a.a 0)
=- =-
?. =(den %f) - ?. =(den %f) - :: flush denormals
?. ?=([%f *] -) - ?. ?=([%f *] -) -
?: =((met 0 ->+>) prc) - [%f & zer] ?: =((met 0 ->+>) prc) - [%f & zer]
:: ::
@ -1456,7 +1452,7 @@
%na [%f & ?:((^lth b (bex (dec q))) zer spd)] %na [%f & ?:((^lth b (bex (dec q))) zer spd)]
== ==
:: ::
=. a (xpd a) :: expand =. a (xpd a)
:: ::
=. a =. a
?- t ?- t
@ -1470,7 +1466,7 @@
%ce ?: &(=(b 0) s) a a(a +(a.a)) %ce ?: &(=(b 0) s) a a(a +(a.a))
%ne ?~ b a %ne ?~ b a
=+ y=(bex (dec q)) =+ y=(bex (dec q))
?: &(=(b y) s) :: halfway rounds to even ?: &(=(b y) s) :: round halfs to even
?~ (dis a.a 1) a a(a +(a.a)) ?~ (dis a.a 1) a a(a +(a.a))
?: (^lth b y) a a(a +(a.a)) ?: (^lth b y) a a(a +(a.a))
%na ?~ b a %na ?~ b a
@ -1489,9 +1485,10 @@
?: =(den %i) [%f & a] ?: =(den %i) [%f & a]
?: =((cmp:si emx e.a) -1) [%i &] [%f & a] :: enforce max. exp ?: =((cmp:si emx e.a) -1) [%i &] [%f & a] :: enforce max. exp
:: ::
++ drg :: dragon4 ++ drg :: dragon4;
~/ %drg ~/ %drg :: convert to decimal
|= [a=[e=@s a=@u]] ^- [@s @u] |= [a=[e=@s a=@u]] ^- [@s @u]
?< =(a.a 0)
=. a ?: (^lth (met 0 a.a) prc) (xpd a) a =. a ?: (^lth (met 0 a.a) prc) (xpd a) a
=+ r=(lsh 0 ?:((syn:si e.a) (abs:si e.a) 0) a.a) =+ r=(lsh 0 ?:((syn:si e.a) (abs:si e.a) 0) a.a)
=+ s=(lsh 0 ?.((syn:si e.a) (abs:si e.a) 0) 1) =+ s=(lsh 0 ?.((syn:si e.a) (abs:si e.a) 0) 1)
@ -1525,7 +1522,7 @@
=. o (^add (^mul o 10) ?:(q +(u) u)) =. o (^add (^mul o 10) ?:(q +(u) u))
[k o] [k o]
:: ::
++ toi ++ toj :: round to integer
|= [a=[e=@s a=@u]] ^- fn |= [a=[e=@s a=@u]] ^- fn
?. =((cmp:si e.a --0) -1) [%f & a] ?. =((cmp:si e.a --0) -1) [%f & a]
=+ x=(abs:si e.a) =+ x=(abs:si e.a)
@ -1537,50 +1534,49 @@
?: &(=(z i) =((dis y 1) 0)) [%f & --0 y] ?: &(=(z i) =((dis y 1) 0)) [%f & --0 y]
?: (^lth z i) [%f & --0 y] [%f & --0 +(y)] ?: (^lth z i) [%f & --0 y] [%f & --0 +(y)]
:: ::
++ ned ++ ned :: require ?=([%f *] a)
|= [a=fn] ^- [%f s=? e=@s a=@u] |= [a=fn] ^- [%f s=? e=@s a=@u]
?: ?=([%f *] a) a ?: ?=([%f *] a) a
~| %need-float !! ~| %need-float !!
:: ::
++ shf ++ shf :: a * 2^b; no rounding
|= [a=fn b=@s] |= [a=fn b=@s]
?: |(?=([%n *] a) ?=([%i *] a)) a ?: |(?=([%n *] a) ?=([%i *] a)) a
a(e (sum:si e.a b)) a(e (sum:si e.a b))
:: ::
++ fli ++ fli :: flip sign
|= [a=fn] ^- fn |= [a=fn] ^- fn
?-(-.a %f a(s !s.a), %i a(s !s.a), %n a) ?-(-.a %f a(s !s.a), %i a(s !s.a), %n a)
:: ::
++ swr ?+(r r %d %u, %u %d) ++ swr ?+(r r %d %u, %u %d) :: flipped rounding
++ prc ?>((gth p 1) p) ++ prc ?>((gth p 1) p) :: force >= 2 precision
++ den d ++ den d :: denorm/flush/inf exp
++ emn v ++ emn v :: minimum exponent
++ emm (sum:si emn (sun:si (dec prc))) ++ emx (sum:si emn (sun:si w)) :: maximum exponent
++ emx (sum:si emn (sun:si w)) ++ spd [e=emn a=1] :: smallest denormal
++ spd [e=emn a=1] :: smallest "denormal" ++ spn [e=emn a=(bex (dec prc))] :: smallest normal
++ spn [e=emn a=(bex (dec prc))] :: smallest "normal"
++ lfn [e=emx a=(fil 0 prc 1)] :: largest ++ lfn [e=emx a=(fil 0 prc 1)] :: largest
++ lfe (sum:si emx (sun:si prc)) :: 2^lfe is larger than all floats ++ lfe (sum:si emx (sun:si prc)) :: 2^lfe is > than all
++ zer [e=--0 a=0] ++ zer [e=--0 a=0]
-- --
|% |%
++ rou ++ rou :: round
|= [a=fn] ^- fn |= [a=fn] ^- fn
?. ?=([%f *] a) a ?. ?=([%f *] a) a
?~ a.a [%f s.a zer] ?~ a.a [%f s.a zer]
?: s.a (^rou +>.a) ?: s.a (^rou +>.a)
=.(r swr (fli (^rou +>.a))) =.(r swr (fli (^rou +>.a)))
:: ::
++ syn ++ syn :: get sign
|= [a=fn] ^- ? |= [a=fn] ^- ?
?-(-.a %f s.a, %i s.a, %n &) ?-(-.a %f s.a, %i s.a, %n &)
:: ::
++ abs ++ abs :: absolute value
|= [a=fn] ^- fn |= [a=fn] ^- fn
?: ?=([%f *] a) [%f & e.a a.a] ?: ?=([%f *] a) [%f & e.a a.a]
?: ?=([%i *] a) [%i &] [%n ~] ?: ?=([%i *] a) [%i &] [%n ~]
:: ::
++ add ++ add :: add
|= [a=fn b=fn] ^- fn |= [a=fn b=fn] ^- fn
?: |(?=([%n *] a) ?=([%n *] b)) [%n ~] ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
?: |(?=([%i *] a) ?=([%i *] b)) ?: |(?=([%i *] a) ?=([%i *] b))
@ -1610,16 +1606,20 @@
?: |(=(a.a 0) =(a.b 0)) ?: |(=(a.a 0) =(a.b 0))
?. &(=(a.a 0) =(a.b 0)) ?~(a.a b a) ?. &(=(a.a 0) =(a.b 0)) ?~(a.a b a)
[%f ?:(=(r %d) &(s.a s.b) |(s.a s.b)) zer] [%f ?:(=(r %d) &(s.a s.b) |(s.a s.b)) zer]
%- |= [a=fn]
?. ?=([%f *] a) a
?. =(a.a 0) a
[%f !=(r %d) zer]
?: =(s.a s.b) ?: =(s.a s.b)
?: s.a (^add +>.a +>.b &) ?: s.a (^add +>.a +>.b &)
(fli (^add +>.a +>.b &)) (fli (^add +>.a +>.b &))
?: s.a (^sub +>.a +>.b &) ?: s.a (^sub +>.a +>.b &)
(^sub +>.b +>.a &) (^sub +>.b +>.a &)
:: ::
++ sub ++ sub :: subtract
|= [a=fn b=fn] ^- fn (add a (fli b)) |= [a=fn b=fn] ^- fn (add a (fli b))
:: ::
++ mul ++ mul :: multiply
|= [a=fn b=fn] ^- fn |= [a=fn b=fn] ^- fn
?: |(?=([%n *] a) ?=([%n *] b)) [%n ~] ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
?: ?=([%i *] a) ?: ?=([%i *] a)
@ -1642,7 +1642,7 @@
?: |(=(a.a 0) =(a.b 0)) [%f =(s.a s.b) zer] ?: |(=(a.a 0) =(a.b 0)) [%f =(s.a s.b) zer]
[%f =(s.a s.b) (sum:si e.a e.b) (^^mul a.a a.b)] [%f =(s.a s.b) (sum:si e.a e.b) (^^mul a.a a.b)]
:: ::
++ div ++ div :: divide
|= [a=fn b=fn] ^- fn |= [a=fn b=fn] ^- fn
?: |(?=([%n *] a) ?=([%n *] b)) [%n ~] ?: |(?=([%n *] a) ?=([%n *] b)) [%n ~]
?: ?=([%i *] a) ?: ?=([%i *] a)
@ -1653,8 +1653,8 @@
?: =(s.a s.b) (^div +>.a +>.b) ?: =(s.a s.b) (^div +>.a +>.b)
=.(r swr (fli (^div +>.a +>.b))) =.(r swr (fli (^div +>.a +>.b)))
:: ::
++ fma :: a * b + c ++ fma :: fused multiply-add
|= [a=fn b=fn c=fn] ^- fn |= [a=fn b=fn c=fn] ^- fn :: (a * b) + c
(add (emu a b) c) (add (emu a b) c)
:: ::
++ sqt :: square root ++ sqt :: square root
@ -1664,20 +1664,21 @@
?~ a.a [%f s.a zer] ?~ a.a [%f s.a zer]
?: s.a (^sqt +>.a) [%n ~] ?: s.a (^sqt +>.a) [%n ~]
:: ::
++ inv ++ inv :: inverse
|= [a=fn] ^- fn |= [a=fn] ^- fn
(div [%f & --0 1] a) (div [%f & --0 1] a)
:: ::
++ sun ++ sun :: uns integer to float
|= [a=@u] ^- fn |= [a=@u] ^- fn
(rou [%f & --0 a]) (rou [%f & --0 a])
:: ::
++ san ++ san :: sgn integer to float
|= [a=@s] ^- fn |= [a=@s] ^- fn
=+ b=(old:si a) =+ b=(old:si a)
(rou [%f -.b --0 +.b]) (rou [%f -.b --0 +.b])
:: ::
++ lth :: comparisons return ~ in the event of a NaN
++ lth :: less-than
|= [a=fn b=fn] ^- (unit ,?) |= [a=fn b=fn] ^- (unit ,?)
?: |(?=([%n *] a) ?=([%n *] b)) ~ :- ~ ?: |(?=([%n *] a) ?=([%n *] b)) ~ :- ~
?: =(a b) | ?: =(a b) |
@ -1688,7 +1689,7 @@
?: !=(s.a s.b) s.b ?: !=(s.a s.b) s.b
?: s.a (^lth +>.a +>.b) (^lth +>.b +>.a) ?: s.a (^lth +>.a +>.b) (^lth +>.b +>.a)
:: ::
++ lte ++ lte :: less-equal
|= [a=fn b=fn] ^- (unit ,?) |= [a=fn b=fn] ^- (unit ,?)
?: |(?=([%n *] a) ?=([%n *] b)) ~ :- ~ ?: |(?=([%n *] a) ?=([%n *] b)) ~ :- ~
?: =(a b) & ?: =(a b) &
@ -1699,7 +1700,7 @@
?: !=(s.a s.b) s.b ?: !=(s.a s.b) s.b
?: s.a (^lte +>.a +>.b) (^lte +>.b +>.a) ?: s.a (^lte +>.a +>.b) (^lte +>.b +>.a)
:: ::
++ equ ++ equ :: equal
|= [a=fn b=fn] ^- (unit ,?) |= [a=fn b=fn] ^- (unit ,?)
?: |(?=([%n *] a) ?=([%n *] b)) ~ :- ~ ?: |(?=([%n *] a) ?=([%n *] b)) ~ :- ~
?: =(a b) & ?: =(a b) &
@ -1709,10 +1710,10 @@
?: |(=(e.a e.b) !=(s.a s.b)) | ?: |(=(e.a e.b) !=(s.a s.b)) |
(^equ +>.a +>.b) (^equ +>.a +>.b)
:: ::
++ gte ++ gte :: greater-equal
|= [a=fn b=fn] ^- (unit ,?) (lte b a) |= [a=fn b=fn] ^- (unit ,?) (lte b a)
:: ::
++ gth ++ gth :: greater-than
|= [a=fn b=fn] ^- (unit ,?) (lth b a) |= [a=fn b=fn] ^- (unit ,?) (lth b a)
:: ::
++ drg :: float to decimal ++ drg :: float to decimal
@ -1732,29 +1733,41 @@
(mul [%f s.a --0 a.a] [%f & e.a (pow 5 q)]) (mul [%f s.a --0 a.a] [%f & e.a (pow 5 q)])
(div [%f s.a --0 a.a] [%f & (sun:si q) (pow 5 q)]) (div [%f s.a --0 a.a] [%f & (sun:si q) (pow 5 q)])
:: ::
++ toi :: round to integer ++ toi :: round to integer @s
|= [a=fn] ^- (unit ,@s)
=+ b=(toj a)
?. ?=([%f *] b) ~ :- ~
=+ c=(^^mul (bex (abs:si e.b)) a.b)
(new:si s.b c)
::
++ toj :: round to integer fn
|= [a=fn] ^- fn |= [a=fn] ^- fn
?. ?=([%f *] a) a ?. ?=([%f *] a) a
?~ a.a [%f s.a zer] ?~ a.a [%f s.a zer]
?: s.a (^toi +>.a) ?: s.a (^toj +>.a)
=.(r swr (fli (^toi +>.a))) =.(r swr (fli (^toj +>.a)))
-- --
:: ::
++ ff :: ieee754 format ++ ff :: ieee 754 format fp
|_ [[w=@u p=@u b=@s] r=?(%n %u %d %z %a)] |_ [[w=@u p=@u b=@s] r=?(%n %u %d %z %a)]
:: this core has no use outside of the functionality
:: provided to ++rd, ++rs, ++rq, and ++rh
:: ::
++ sz +((^add w p)) :: w=width: bits in exponent field
++ sb (bex (^add w p)) :: p=precision: bits in fraction field
++ me (dif:si (dif:si --1 b) (sun:si p)) :: w=bias: added to exponent when storing
:: r=rounding mode: same as in ++fl
::
++ sb (bex (^add w p)) :: sign bit
++ me (dif:si (dif:si --1 b) (sun:si p)) :: minimum exponent
:: ::
++ pa ++ pa
%*(. fl p +(p), v me, w (^sub (bex w) 3), d %d, r r) %*(. fl p +(p), v me, w (^sub (bex w) 3), d %d, r r)
:: ::
++ sea ++ sea :: @r to fn
|= [a=@r] ^- fn |= [a=@r] ^- fn
=+ f=(cut 0 [0 p] a) =+ [f=(cut 0 [0 p] a) e=(cut 0 [p w] a)]
=+ e=(cut 0 [p w] a) =+ s=(sig a)
=+ s==(0 (cut 0 [(^add p w) 1] a))
?: =(e 0) ?: =(e 0)
?: =(f 0) [%f s --0 0] [%f s me f] ?: =(f 0) [%f s --0 0] [%f s me f]
?: =(e (fil 0 w 1)) ?: =(e (fil 0 w 1))
@ -1763,9 +1776,9 @@
=+ r=(^add f (bex p)) =+ r=(^add f (bex p))
[%f s q r] [%f s q r]
:: ::
++ bit |= [a=fn] (bif (rou:pa a)) ++ bit |= [a=fn] (bif (rou:pa a)) :: fn to @r w/ rounding
:: ::
++ bif ++ bif :: fn to @r no rounding
|= [a=fn] ^- @r |= [a=fn] ^- @r
?: ?=([%i *] a) ?: ?=([%i *] a)
=+ q=(lsh 0 p (fil 0 w 1)) =+ q=(lsh 0 p (fil 0 w 1))
@ -1781,180 +1794,280 @@
=+ r=(^add (lsh 0 p (abs:si q)) (end 0 p a.a)) =+ r=(^add (lsh 0 p (abs:si q)) (end 0 p a.a))
?: s.a r (^add r sb) ?: s.a r (^add r sb)
:: ::
++ sig ++ sig :: get sign
|= [a=@r] ^- ? |= [a=@r] ^- ?
=(0 (cut 0 [(^add p w) 1] a)) =(0 (cut 0 [(^add p w) 1] a))
:: ::
++ exp ++ exp :: get exponent
|= [a=@r] ^- @s |= [a=@r] ^- @s
(dif:si (sun:si (cut 0 [p w] a)) b) (dif:si (sun:si (cut 0 [p w] a)) b)
:: ::
++ toi ++ add :: add
|= [a=@r] ^- (unit ,@s) |= [a=@r b=@r]
=+ b=(toi:pa (sea a)) (bif (add:pa (sea a) (sea b)))
?. ?=([%f *] b) ~ :- ~
=+ c=(^mul (bex (abs:si e.b)) a.b)
(new:si s.b c)
:: ::
++ add |= [a=@r b=@r] (bif (add:pa (sea a) (sea b))) ++ sub :: subtract
++ sub |= [a=@r b=@r] (bif (sub:pa (sea a) (sea b))) |= [a=@r b=@r]
++ mul |= [a=@r b=@r] (bif (mul:pa (sea a) (sea b))) (bif (sub:pa (sea a) (sea b)))
++ div |= [a=@r b=@r] (bif (div:pa (sea a) (sea b))) ::
++ fma |= [a=@r b=@r c=@r] (bif (fma:pa (sea a) (sea b) (sea c))) ++ mul :: multiply
++ sqt |= [a=@r] (bif (sqt:pa (sea a))) |= [a=@r b=@r]
++ sun |= [a=@u] (bit [%f & --0 a]) (bif (mul:pa (sea a) (sea b)))
++ san |= [a=@s] (bit [%f (syn:si a) --0 (abs:si a)]) ::
++ lth |= [a=@r b=@r] (fall (lth:pa (sea a) (sea b)) |) ++ div :: divide
++ lte |= [a=@r b=@r] (fall (lte:pa (sea a) (sea b)) |) |= [a=@r b=@r]
++ equ |= [a=@r b=@r] (fall (equ:pa (sea a) (sea b)) |) (bif (div:pa (sea a) (sea b)))
++ gte |= [a=@r b=@r] (fall (gte:pa (sea a) (sea b)) |) ::
++ gth |= [a=@r b=@r] (fall (gth:pa (sea a) (sea b)) |) ++ fma :: fused multiply-add
++ drg |= [a=@r] (drg:pa (sea a)) |= [a=@r b=@r c=@r]
++ grd |= [a=dn] (bif (grd:pa a)) (bif (fma:pa (sea a) (sea b) (sea c)))
::
++ sqt :: square root
|= [a=@r]
(bif (sqt:pa (sea a)))
::
++ lth :: less-than
|= [a=@r b=@r] (fall (lth:pa (sea a) (sea b)) |)
++ lte :: less-equals
|= [a=@r b=@r] (fall (lte:pa (sea a) (sea b)) |)
++ equ :: equals
|= [a=@r b=@r] (fall (equ:pa (sea a) (sea b)) |)
++ gte :: greater-equals
|= [a=@r b=@r] (fall (gte:pa (sea a) (sea b)) |)
++ gth :: greater-than
|= [a=@r b=@r] (fall (gth:pa (sea a) (sea b)) |)
++ sun :: uns integer to @r
|= [a=@u] (bit [%f & --0 a])
++ san :: signed integer to @r
|= [a=@s] (bit [%f (syn:si a) --0 (abs:si a)])
++ toi :: round to integer
|= [a=@r] (toi:pa (sea a))
++ drg :: @r to decimal float
|= [a=@r] (drg:pa (sea a))
++ grd :: decimal float to @r
|= [a=dn] (bif (grd:pa a))
-- --
:: ::
++ rlyd |= a=@rd ^- dn (drg:rd a) ++ rlyd |= a=@rd ^- dn (drg:rd a) :: prep @rd for print
++ rlys |= a=@rs ^- dn (drg:rs a) ++ rlys |= a=@rs ^- dn (drg:rs a) :: prep @rs for print
++ rlyh |= a=@rh ^- dn (drg:rh a) ++ rlyh |= a=@rh ^- dn (drg:rh a) :: prep @rh for print
++ rlyq |= a=@rq ^- dn (drg:rq a) ++ rlyq |= a=@rq ^- dn (drg:rq a) :: prep @rq for print
++ ryld |= a=dn ^- @rd (grd:rd a) ++ ryld |= a=dn ^- @rd (grd:rd a) :: finish parsing @rd
++ ryls |= a=dn ^- @rs (grd:rs a) ++ ryls |= a=dn ^- @rs (grd:rs a) :: finish parsing @rs
++ rylh |= a=dn ^- @rh (grd:rh a) ++ rylh |= a=dn ^- @rh (grd:rh a) :: finish parsing @rh
++ rylq |= a=dn ^- @rq (grd:rq a) ++ rylq |= a=dn ^- @rq (grd:rq a) :: finish parsing @rq
:: ::
++ rd ++ rd :: double precision fp
~% %rd +> ~ ~% %rd +> ~
|_ r=?(%n %u %d %z) |_ r=?(%n %u %d %z)
:: round to nearest, round up, round down, round to zero
::
++ ma ++ ma
%*(. ff w 11, p 52, b --1.023, r r) %*(. ff w 11, p 52, b --1.023, r r)
++ sea
|= [a=@rd] (sea:ma a)
++ bit
|= [a=fn] ^- @rd (bit:ma a)
++ add ~/ %add
|= [a=@rd b=@rd] ^- @rd ~| %rd-fail (add:ma a b)
++ sub ~/ %sub
|= [a=@rd b=@rd] ^- @rd ~| %rd-fail (sub:ma a b)
++ mul ~/ %mul
|= [a=@rd b=@rd] ^- @rd ~| %rd-fail (mul:ma a b)
++ div ~/ %div
|= [a=@rd b=@rd] ^- @rd ~| %rd-fail (div:ma a b)
++ fma ~/ %fma
|= [a=@rd b=@rd c=@rd] ^- @rd ~| %rd-fail (fma:ma a b c)
++ sqt ~/ %sqt
|= [a=@rd] ^- @rd ~| %rd-fail (sqt:ma a)
:: ::
++ sun |= [a=@u] ^- @rd (sun:ma a) ++ sea :: @rd to fn
++ san |= [a=@s] ^- @rd (san:ma a) |= [a=@rd] (sea:ma a)
++ lth ~/ %lth |= [a=@rd b=@rd] ~| %rd-fail (lth:ma a b) ::
++ lte ~/ %lte |= [a=@rd b=@rd] ~| %rd-fail (lte:ma a b) ++ bit :: fn to @rd
++ equ ~/ %equ |= [a=@rd b=@rd] ~| %rd-fail (equ:ma a b) |= [a=fn] ^- @rd (bit:ma a)
++ gte ~/ %gte |= [a=@rd b=@rd] ~| %rd-fail (gte:ma a b) ::
++ gth ~/ %gth |= [a=@rd b=@rd] ~| %rd-fail (gth:ma a b) ++ add ~/ %add :: add
++ sig |= [a=@rd] (sig:ma a) |= [a=@rd b=@rd] ^- @rd ~| %rd-fail
++ exp |= [a=@rd] (exp:ma a) (add:ma a b)
++ toi |= [a=@rd] (toi:ma a) ::
++ drg |= [a=@rd] (drg:ma a) ++ sub ~/ %sub :: subtract
++ grd |= [a=dn] (grd:ma a) |= [a=@rd b=@rd] ^- @rd ~| %rd-fail
(sub:ma a b)
::
++ mul ~/ %mul :: multiply
|= [a=@rd b=@rd] ^- @rd ~| %rd-fail
(mul:ma a b)
::
++ div ~/ %div :: divide
|= [a=@rd b=@rd] ^- @rd ~| %rd-fail
(div:ma a b)
::
++ fma ~/ %fma :: fused multiply-add
|= [a=@rd b=@rd c=@rd] ^- @rd ~| %rd-fail
(fma:ma a b c)
::
++ sqt ~/ %sqt :: square root
|= [a=@rd] ^- @rd ~| %rd-fail
(sqt:ma a)
::
++ lth ~/ %lth :: less-than
|= [a=@rd b=@rd] ~| %rd-fail (lth:ma a b)
++ lte ~/ %lte :: less-equals
|= [a=@rd b=@rd] ~| %rd-fail (lte:ma a b)
++ equ ~/ %equ :: equals
|= [a=@rd b=@rd] ~| %rd-fail (equ:ma a b)
++ gte ~/ %gte :: greater-equals
|= [a=@rd b=@rd] ~| %rd-fail (gte:ma a b)
++ gth ~/ %gth :: greater-than
|= [a=@rd b=@rd] ~| %rd-fail (gth:ma a b)
::
++ sun |= [a=@u] ^- @rd (sun:ma a) :: uns integer to @rd
++ san |= [a=@s] ^- @rd (san:ma a) :: sgn integer to @rd
++ sig |= [a=@rd] ^- ? (sig:ma a) :: get sign
++ exp |= [a=@rd] ^- @s (exp:ma a) :: get exponent
++ toi |= [a=@rd] ^- (unit ,@s) (toi:ma a) :: round to integer
++ drg |= [a=@rd] ^- dn (drg:ma a) :: @rd to decimal float
++ grd |= [a=dn] ^- @rd (grd:ma a) :: decimal float to @rd
-- --
:: ::
++ rs ++ rs :: single precision fp
~% %rs +> ~ ~% %rs +> ~
|_ r=?(%n %u %d %z) |_ r=?(%n %u %d %z)
++ ma :: round to nearest, round up, round down, round to zero
%*(. ff w 8, p 23, b --127, r r)
++ sea
|= [a=@rs] (sea:ma a)
++ bit
|= [a=fn] ^- @rs (bit:ma a)
++ add ~/ %add
|= [a=@rs b=@rs] ^- @rs ~| %rs-fail (add:ma a b)
++ sub ~/ %sub
|= [a=@rs b=@rs] ^- @rs ~| %rs-fail (sub:ma a b)
++ mul ~/ %mul
|= [a=@rs b=@rs] ^- @rs ~| %rs-fail (mul:ma a b)
++ div ~/ %div
|= [a=@rs b=@rs] ^- @rs ~| %rs-fail (div:ma a b)
++ fma ~/ %fma
|= [a=@rs b=@rs c=@rs] ^- @rs ~| %rs-fail (fma:ma a b c)
++ sqt ~/ %sqt
|= [a=@rs] ^- @rs ~| %rs-fail (sqt:ma a)
:: ::
++ sun |= [a=@u] ^- @rs (sun:ma a) ++ ma
++ san |= [a=@s] ^- @rs (san:ma a) %*(. ff w 11, p 52, b --1.023, r r)
++ lth ~/ %lth |= [a=@rs b=@rs] ~| %rs-fail (lth:ma a b) ::
++ lte ~/ %lte |= [a=@rs b=@rs] ~| %rs-fail (lte:ma a b) ++ sea :: @rs to fn
++ equ ~/ %equ |= [a=@rs b=@rs] ~| %rs-fail (equ:ma a b) |= [a=@rs] (sea:ma a)
++ gte ~/ %gte |= [a=@rs b=@rs] ~| %rs-fail (gte:ma a b) ::
++ gth ~/ %gth |= [a=@rs b=@rs] ~| %rs-fail (gth:ma a b) ++ bit :: fn to @rs
++ sig |= [a=@rs] (sig:ma a) |= [a=fn] ^- @rs (bit:ma a)
++ exp |= [a=@rs] (exp:ma a) ::
++ toi |= [a=@rs] (toi:ma a) ++ add ~/ %add :: add
++ drg |= [a=@rs] (drg:ma a) |= [a=@rs b=@rs] ^- @rs ~| %rs-fail
++ grd |= [a=dn] (grd:ma a) (add:ma a b)
::
++ sub ~/ %sub :: subtract
|= [a=@rs b=@rs] ^- @rs ~| %rs-fail
(sub:ma a b)
::
++ mul ~/ %mul :: multiply
|= [a=@rs b=@rs] ^- @rs ~| %rs-fail
(mul:ma a b)
::
++ div ~/ %div :: divide
|= [a=@rs b=@rs] ^- @rs ~| %rs-fail
(div:ma a b)
::
++ fma ~/ %fma :: fused multiply-add
|= [a=@rs b=@rs c=@rs] ^- @rs ~| %rs-fail
(fma:ma a b c)
::
++ sqt ~/ %sqt :: square root
|= [a=@rs] ^- @rs ~| %rs-fail
(sqt:ma a)
::
++ lth ~/ %lth :: less-than
|= [a=@rs b=@rs] ~| %rs-fail (lth:ma a b)
++ lte ~/ %lte :: less-equals
|= [a=@rs b=@rs] ~| %rs-fail (lte:ma a b)
++ equ ~/ %equ :: equals
|= [a=@rs b=@rs] ~| %rs-fail (equ:ma a b)
++ gte ~/ %gte :: greater-equals
|= [a=@rs b=@rs] ~| %rs-fail (gte:ma a b)
++ gth ~/ %gth :: greater-than
|= [a=@rs b=@rs] ~| %rs-fail (gth:ma a b)
::
++ sun |= [a=@u] ^- @rs (sun:ma a) :: uns integer to @rs
++ san |= [a=@s] ^- @rs (san:ma a) :: sgn integer to @rs
++ sig |= [a=@rs] ^- ? (sig:ma a) :: get sign
++ exp |= [a=@rs] ^- @s (exp:ma a) :: get exponent
++ toi |= [a=@rs] ^- (unit ,@s) (toi:ma a) :: round to integer
++ drg |= [a=@rs] ^- dn (drg:ma a) :: @rs to decimal float
++ grd |= [a=dn] ^- @rs (grd:ma a) :: decimal float to @rs
-- --
:: ::
++ rq ++ rq :: quad precision fp
~% %rq +> ~ ~% %rq +> ~
|_ r=?(%n %u %d %z) |_ r=?(%n %u %d %z)
++ ma :: round to nearest, round up, round down, round to zero
%*(. ff w 15, p 112, b --16.383, r r)
++ sea
|= [a=@rq] (sea:ma a)
++ bit
|= [a=fn] ^- @rq (bit:ma a)
++ add ~/ %add
|= [a=@rq b=@rq] ^- @rq ~| %rq-fail (add:ma a b)
++ sub ~/ %sub
|= [a=@rq b=@rq] ^- @rq ~| %rq-fail (sub:ma a b)
++ mul ~/ %mul
|= [a=@rq b=@rq] ^- @rq ~| %rq-fail (mul:ma a b)
++ div ~/ %div
|= [a=@rq b=@rq] ^- @rq ~| %rq-fail (div:ma a b)
++ fma ~/ %fma
|= [a=@rq b=@rq c=@rq] ^- @rq ~| %rq-fail (fma:ma a b c)
++ sqt ~/ %sqt
|= [a=@rq] ^- @rq ~| %rq-fail (sqt:ma a)
:: ::
++ sun |= [a=@u] ^- @rq (sun:ma a) ++ ma
++ san |= [a=@s] ^- @rq (san:ma a) %*(. ff w 11, p 52, b --1.023, r r)
++ lth ~/ %lth |= [a=@rq b=@rq] ~| %rq-fail (lth:ma a b) ::
++ lte ~/ %lte |= [a=@rq b=@rq] ~| %rq-fail (lte:ma a b) ++ sea :: @rq to fn
++ equ ~/ %equ |= [a=@rq b=@rq] ~| %rq-fail (equ:ma a b) |= [a=@rq] (sea:ma a)
++ gte ~/ %gte |= [a=@rq b=@rq] ~| %rq-fail (gte:ma a b) ::
++ gth ~/ %gth |= [a=@rq b=@rq] ~| %rq-fail (gth:ma a b) ++ bit :: fn to @rq
++ sig |= [a=@rq] (sig:ma a) |= [a=fn] ^- @rq (bit:ma a)
++ exp |= [a=@rq] (exp:ma a) ::
++ toi |= [a=@rq] (toi:ma a) ++ add ~/ %add :: add
++ drg |= [a=@rq] (drg:ma a) |= [a=@rq b=@rq] ^- @rq ~| %rq-fail
++ grd |= [a=dn] (grd:ma a) (add:ma a b)
::
++ sub ~/ %sub :: subtract
|= [a=@rq b=@rq] ^- @rq ~| %rq-fail
(sub:ma a b)
::
++ mul ~/ %mul :: multiply
|= [a=@rq b=@rq] ^- @rq ~| %rq-fail
(mul:ma a b)
::
++ div ~/ %div :: divide
|= [a=@rq b=@rq] ^- @rq ~| %rq-fail
(div:ma a b)
::
++ fma ~/ %fma :: fused multiply-add
|= [a=@rq b=@rq c=@rq] ^- @rq ~| %rq-fail
(fma:ma a b c)
::
++ sqt ~/ %sqt :: square root
|= [a=@rq] ^- @rq ~| %rq-fail
(sqt:ma a)
::
++ lth ~/ %lth :: less-than
|= [a=@rq b=@rq] ~| %rq-fail (lth:ma a b)
++ lte ~/ %lte :: less-equals
|= [a=@rq b=@rq] ~| %rq-fail (lte:ma a b)
++ equ ~/ %equ :: equals
|= [a=@rq b=@rq] ~| %rq-fail (equ:ma a b)
++ gte ~/ %gte :: greater-equals
|= [a=@rq b=@rq] ~| %rq-fail (gte:ma a b)
++ gth ~/ %gth :: greater-than
|= [a=@rq b=@rq] ~| %rq-fail (gth:ma a b)
::
++ sun |= [a=@u] ^- @rq (sun:ma a) :: uns integer to @rq
++ san |= [a=@s] ^- @rq (san:ma a) :: sgn integer to @rq
++ sig |= [a=@rq] ^- ? (sig:ma a) :: get sign
++ exp |= [a=@rq] ^- @s (exp:ma a) :: get exponent
++ toi |= [a=@rq] ^- (unit ,@s) (toi:ma a) :: round to integer
++ drg |= [a=@rq] ^- dn (drg:ma a) :: @rq to decimal float
++ grd |= [a=dn] ^- @rq (grd:ma a) :: decimal float to @rq
-- --
:: ::
++ rh ++ rh :: half precision fp
|_ r=?(%n %u %d %z) |_ r=?(%n %u %d %z)
:: round to nearest, round up, round down, round to zero
::
++ ma ++ ma
%*(. ff w 5, p 10, b --15, r r) %*(. ff w 5, p 10, b --15, r r)
++ sea ::
++ sea :: @rh to fn
|= [a=@rh] (sea:ma a) |= [a=@rh] (sea:ma a)
++ bit ::
++ bit :: fn to @rh
|= [a=fn] ^- @rh (bit:ma a) |= [a=fn] ^- @rh (bit:ma a)
++ tos ::
++ tos :: @rh to @rs
|= [a=@rh] (bit:rs (sea a)) |= [a=@rh] (bit:rs (sea a))
++ fos ::
++ fos :: @rs to @rh
|= [a=@rs] (bit (sea:rs a)) |= [a=@rs] (bit (sea:rs a))
:: ::
++ sun |= [a=@u] ^- @rh (sun:ma a) ++ lth ~/ %lth :: less-than
++ san |= [a=@s] ^- @rh (san:ma a) |= [a=@rh b=@rh] ~| %rh-fail (lth:ma a b)
++ lth |= [a=@rh b=@rh] ~| %rh-fail (lth:ma a b) ++ lte ~/ %lte :: less-equals
++ lte |= [a=@rh b=@rh] ~| %rh-fail (lte:ma a b) |= [a=@rh b=@rh] ~| %rh-fail (lte:ma a b)
++ equ |= [a=@rh b=@rh] ~| %rh-fail (equ:ma a b) ++ equ ~/ %equ :: equals
++ gte |= [a=@rh b=@rh] ~| %rh-fail (gte:ma a b) |= [a=@rh b=@rh] ~| %rh-fail (equ:ma a b)
++ gth |= [a=@rh b=@rh] ~| %rh-fail (gth:ma a b) ++ gte ~/ %gte :: greater-equals
++ sig |= [a=@rh] (sig:ma a) |= [a=@rh b=@rh] ~| %rh-fail (gte:ma a b)
++ exp |= [a=@rh] (exp:ma a) ++ gth ~/ %gth :: greater-than
++ toi |= [a=@rh] (toi:ma a) |= [a=@rh b=@rh] ~| %rh-fail (gth:ma a b)
++ drg |= [a=@rh] (drg:ma a) ::
++ grd |= [a=dn] (grd:ma a) ++ sun |= [a=@u] ^- @rh (sun:ma a) :: uns integer to @rh
++ san |= [a=@s] ^- @rh (san:ma a) :: sgn integer to @rh
++ sig |= [a=@rh] ^- ? (sig:ma a) :: get sign
++ exp |= [a=@rh] ^- @s (exp:ma a) :: get exponent
++ toi |= [a=@rh] ^- (unit ,@s) (toi:ma a) :: round to integer
++ drg |= [a=@rh] ^- dn (drg:ma a) :: @rh to decimal float
++ grd |= [a=dn] ^- @rh (grd:ma a) :: decimal float to @rh
-- --
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: section 2cH, urbit time :: :: section 2cH, urbit time ::
@ -2135,7 +2248,7 @@
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: section 2cJ, extra math :: :: section 2cJ, extra math ::
:: ::
++ sqt :: square root w/remainder ++ sqt :: sqrt w/remainder
~/ %sqt ~/ %sqt
|= a=@ ^- [p=@ q=@] |= a=@ ^- [p=@ q=@]
?~ a [0 0] ?~ a [0 0]
@ -5751,8 +5864,8 @@
?: (lth b 256) ?: (lth b 256)
[[b (end 0 b d)] ~] [[b (end 0 b d)] ~]
[[256 d] $(c d, b (sub b 256))] [[256 d] $(c d, b (sub b 256))]
++ raws :: random bits continuation ++ raws :: random bits
|= b=@ |= b=@ :: continuation
=+ r=(raw b) =+ r=(raw b)
[r +>.$(a (shas %og-s r))] [r +>.$(a (shas %og-s r))]
-- --