From 5f979c9346524dd5428219ad23b64de429b21b48 Mon Sep 17 00:00:00 2001 From: Jared Hance Date: Wed, 4 Jun 2014 10:20:15 -0400 Subject: [PATCH 1/4] Various fixes to Fl Points. Printing/parsing still pretty broken. --- arvo/hoon.hoon | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/arvo/hoon.hoon b/arvo/hoon.hoon index c60566b1c..6e25194c6 100644 --- a/arvo/hoon.hoon +++ b/arvo/hoon.hoon @@ -1163,7 +1163,7 @@ :: ++ rlyd |= red=@rd ^- [s=? h=@ f=@] !: ~& [%rlyd `@ux`red] - [s=(sig:rd red) h=(exp:rd red) f=(fac:rd red)] + [s=(sig:rd red) h=(hol:rd red) f=0] ++ rlyh |=(reh=@rh ~|(%real-nyet ^-([s=? h=@ f=@] !!))) ++ rlyq |=(req=@rq ~|(%real-nyet ^-([s=? h=@ f=@] !!))) ++ rlys |=(res=@rs ~|(%real-nyet ^-([s=? h=@ f=@] !!))) @@ -1217,6 +1217,12 @@ ::=+ (^mul ari (bex e)) !! + :: Decimal length of number, for use in ++den + ++ dcl |= [f=@u] ^- @u + ?: =(f 0) + 0 + (^add 1 $(f (^div f 10))) + :: Denominator of fraction, f is base 10 ++ den |= f=@u ^- @u (bey 10 (dcl f) 0 1) @@ -1231,11 +1237,12 @@ =+ d=(bex (^sub (met 0 a) 1)) (^div (^mul a (bey 10 q 0 1)) d) - :: Decimal length of number, for use in ++den - ++ dcl |= [f=@u] ^- @u - ?: =(f 0) - 0 - (^add 1 $(f (^div f 10))) + ++ hol |= [p=@u n=[s=? e=@s a=@u]] ^- @u + ?: =((mod `@`e.n 2) 0) + ?: (^gte (abs:si e.n) p) + (lsh 0 (^sub (abs:si e.n) p) a.n) + (rsh 0 (^sub p (abs:si e.n)) a.n) + 0 :: reverse ari, ari -> mantissa ++ ira |= a=@u ^- @u @@ -1342,7 +1349,7 @@ ++ bit |= a=[s=? e=@s a=@u] =+ a2=(lia:fl 52 a.a) =+ b=(ira:fl a2) - =+ c=(lsh 0 (^sub 52 (dec (met 0 a2))) b) + =+ c=(lsh 0 (^sub 52 (met 0 b)) b) (can 0 [[52 c] [[11 (abs:si (sum:si (sun:si 1.023) e.a))] [[1 `@`s.a] ~]]]) :: Sign of an @rd ++ sig |= [a=@rd] ^- ? @@ -1352,10 +1359,13 @@ (dif:si (sun:si (rsh 0 52 (end 0 63 a))) (sun:si 1.023)) :: Fraction of an @rd (binary) ++ fac |= [a=@rd] ^- @u - (end 0 52 a) + (fre:fl 14 (ari:fl 52 (end 0 52 a))) + :: Whole + ++ hol |= [a=@rd] ^- @u + (hol:fl 52 (sea a)) :: Convert to sign/exp/ari form ++ sea |= a=@rd ^- [s=? e=@s a=@u] - [s=(sig a) e=(exp a) a=(ari:fl 52 (fac a))] + [s=(sig a) e=(exp a) a=(ari:fl 52 (end 0 52 a))] :::::::::::: ++ add ~/ %add @@ -1389,6 +1399,19 @@ ++ gth ~/ %gth |= [a=@rd b=@rd] ^- ? (gth:fl (sea a) (sea b)) + + ++ max |= [a=@rd b=@rd] ^- @rd + ?: (gth a b) + a + b + + ++ min |= [a=@rd b=@rd] ^- @rd + ?: (lth a b) + a + b + + ++ bex |= a=@s ^- @rd + (bit [s=%.y e=a a=(ari:fl 52 0)]) -- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: section 2cH, urbit time :: From 1fde43b3d52dc8a92a6a4c6265b58d2505beeebe Mon Sep 17 00:00:00 2001 From: Jared Hance Date: Wed, 4 Jun 2014 13:56:09 -0400 Subject: [PATCH 2/4] Fix floating point parsing. Not completely finished, but it can parse numbers not in the range (-1,1) --- arvo/hoon.hoon | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/arvo/hoon.hoon b/arvo/hoon.hoon index 6e25194c6..d25f9dd9a 100644 --- a/arvo/hoon.hoon +++ b/arvo/hoon.hoon @@ -1167,11 +1167,11 @@ ++ rlyh |=(reh=@rh ~|(%real-nyet ^-([s=? h=@ f=@] !!))) ++ rlyq |=(req=@rq ~|(%real-nyet ^-([s=? h=@ f=@] !!))) ++ rlys |=(res=@rs ~|(%real-nyet ^-([s=? h=@ f=@] !!))) -++ ryld |= v=[syn=? hol=@ fac=@] ^- @rd !: +++ ryld |= v=[syn=? hol=@ zer=@ fac=@] ^- @rd !: (bit:rd (cof:fl 52 v)) -++ rylh |=([syn=? hol=@ fac=@] ~|(%real-nyet ^-(@rh !!))) -++ rylq |=([syn=? hol=@ fac=@] ~|(%real-nyet ^-(@rq !!))) -++ ryls |=([syn=? hol=@ fac=@] ~|(%real-nyet ^-(@rs !!))) +++ rylh |=([syn=? hol=@ zer=@ fac=@] ~|(%real-nyet ^-(@rh !!))) +++ rylq |=([syn=? hol=@ zer=@ fac=@] ~|(%real-nyet ^-(@rq !!))) +++ ryls |=([syn=? hol=@ zer=@ fac=@] ~|(%real-nyet ^-(@rs !!))) :: Floating point operations for general floating points. :: Not really needed, since the actual floating point operations @@ -1201,12 +1201,18 @@ $(c (^mul c a), b (^add b 1)) :: convert from sign/whole/frac -> sign/exp/ari w/ precision p, bias b - ++ cof |= [p=@u s=? h=@u f=@u] ^- [s=? e=@s a=@u] - =+ b=(fra p f) - =+ e=(dif:si (sun:si (xeb h)) (sun:si 1)) - =+ a=(lia p (mix (lsh 0 p h) b)) - [s=s e=e a=a] - + ++ cof |= [p=@u s=? h=@u z=@ f=@u] ^- [s=? e=@s a=@u] + ?: &(=(0 h) =(0 f)) + ~| %zero-pars + !! + ?: &(=(0 h)) + ~| %small-pars + !! + =+ b=(fra p z f) :: p-bits + =+ a=(mix b (lsh 0 p h)) + =+ e=(dif:si (sun:si (met 0 a)) (sun:si +(p))) + [s=s e=e a=(lia p a)] + :: convert from sign/exp/ari -> sign/whole/frac w/ precision q ++ cog |= [q=@u s=? e=@s a=@u] ^- [s=? h=@u f=@u] ::?: =(e -0) @@ -1224,13 +1230,12 @@ (^add 1 $(f (^div f 10))) :: Denominator of fraction, f is base 10 - ++ den |= f=@u ^- @u - (bey 10 (dcl f) 0 1) + ++ den |= [f=@u z=@u] ^- @u + (bey 10 (^add z (dcl f)) 0 1) :: Binary fraction of precision p (ex, for doubles, p=52) - ++ fra |= [p=@u f=@u] ^- @u - =+ d=(den f) - (^div (lsh 0 p f) d) + ++ fra |= [p=@u z=@u f=@u] ^- @u + (^div (lsh 0 p f) (den f z)) :: Decimal fraction of precision q [for printing only] ++ fre |= [q=@u a=@u] ^- @u @@ -1349,8 +1354,8 @@ ++ bit |= a=[s=? e=@s a=@u] =+ a2=(lia:fl 52 a.a) =+ b=(ira:fl a2) - =+ c=(lsh 0 (^sub 52 (met 0 b)) b) - (can 0 [[52 c] [[11 (abs:si (sum:si (sun:si 1.023) e.a))] [[1 `@`s.a] ~]]]) + ::=+ c=(lsh 0 (^sub 52 (met 0 b)) b) + (can 0 [[52 b] [[11 (abs:si (sum:si (sun:si 1.023) e.a))] [[1 `@`s.a] ~]]]) :: Sign of an @rd ++ sig |= [a=@rd] ^- ? =(0 (rsh 0 63 a)) @@ -3208,11 +3213,13 @@ (stag ~ zust) (stag %many (ifix [cab ;~(plug cab cab)] (more cab nusk))) == - ++ royl + ++ royl !: + =+ ^= zer + (cook lent (star (just '0'))) =+ ^= vox ;~ plug ;~(pose (cold | hep) (easy &)) - ;~(plug dim:ag ;~(pose ;~(pfix dot dim:ag) (easy 0))) + ;~(plug dim:ag ;~(pose ;~(pfix dot ;~(plug zer dim:ag)) (easy [0 0]))) == ;~ pose (stag %rh (cook rylh ;~(pfix ;~(plug sig sig) vox))) From 95c9309f78d6efa249bf4b1c58bbd4aec5c851ea Mon Sep 17 00:00:00 2001 From: Jared Hance Date: Wed, 4 Jun 2014 14:44:02 -0400 Subject: [PATCH 3/4] Finish fixing the floating point parser. --- arvo/hoon.hoon | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arvo/hoon.hoon b/arvo/hoon.hoon index d25f9dd9a..9831eacef 100644 --- a/arvo/hoon.hoon +++ b/arvo/hoon.hoon @@ -1168,7 +1168,7 @@ ++ rlyq |=(req=@rq ~|(%real-nyet ^-([s=? h=@ f=@] !!))) ++ rlys |=(res=@rs ~|(%real-nyet ^-([s=? h=@ f=@] !!))) ++ ryld |= v=[syn=? hol=@ zer=@ fac=@] ^- @rd !: - (bit:rd (cof:fl 52 v)) + (bit:rd (cof:fl 52 1.023 v)) ++ rylh |=([syn=? hol=@ zer=@ fac=@] ~|(%real-nyet ^-(@rh !!))) ++ rylq |=([syn=? hol=@ zer=@ fac=@] ~|(%real-nyet ^-(@rq !!))) ++ ryls |=([syn=? hol=@ zer=@ fac=@] ~|(%real-nyet ^-(@rs !!))) @@ -1201,15 +1201,15 @@ $(c (^mul c a), b (^add b 1)) :: convert from sign/whole/frac -> sign/exp/ari w/ precision p, bias b - ++ cof |= [p=@u s=? h=@u z=@ f=@u] ^- [s=? e=@s a=@u] + ++ cof |= [p=@u b=@u s=? h=@u z=@ f=@u] ^- [s=? e=@s a=@u] ?: &(=(0 h) =(0 f)) - ~| %zero-pars - !! + [s=s e=`@s`(dec (^mul 2 b)) a=(ari p 0)] ?: &(=(0 h)) - ~| %small-pars - !! - =+ b=(fra p z f) :: p-bits - =+ a=(mix b (lsh 0 p h)) + =+ a=(fra (^add p b) z f) ::p+b bits + =+ e=(dif:si (sun:si (met 0 a)) (sun:si +((^add p b)))) + [s=s e=e a=(lia p a)] + =+ c=(fra p z f) :: p-bits + =+ a=(mix c (lsh 0 p h)) =+ e=(dif:si (sun:si (met 0 a)) (sun:si +(p))) [s=s e=e a=(lia p a)] From 4c2fd59789770397c705413d82e35c0f0197711f Mon Sep 17 00:00:00 2001 From: Jared Hance Date: Wed, 4 Jun 2014 15:16:15 -0400 Subject: [PATCH 4/4] Add function for @u -> @rd --- arvo/hoon.hoon | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arvo/hoon.hoon b/arvo/hoon.hoon index 9831eacef..34c2ecfa9 100644 --- a/arvo/hoon.hoon +++ b/arvo/hoon.hoon @@ -1373,6 +1373,10 @@ [s=(sig a) e=(exp a) a=(ari:fl 52 (end 0 52 a))] :::::::::::: + ++ sun ~/ %sun + |= a=@u ^- @rd + (bit (cof:fl 52 1.023 %.y a 0 0)) + ++ add ~/ %add |= [a=@rd b=@rd] ^- @rd (bit (add:fl 52 (sea a) (sea b)))