Date: Wed, 13 Jan 2016 17:52:25 -0500 From: Jon Radel <jon@radel.com> To: freebsd-questions@freebsd.org Subject: Re: dc(1) bugs Message-ID: <5696D529.9080901@radel.com> In-Reply-To: <slrnn9d8oc.d44.naddy@lorvorc.mips.inka.de> References: <0McVKy-1aajq60oIS-00Hgju@mail.gmx.com> <slrnn9d8oc.d44.naddy@lorvorc.mips.inka.de>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On 1/13/16 2:18 PM, Christian Weisgerber wrote:
> Simpler examples:
>
> $ dc -e '50k 16i .1 p'
> 0.0
> $ dc -e '50k 16i .10 p'
> .06
> $ dc -e '50k 16i .100 p'
> .062
> $ dc -e '50k 16i .1000 p'
> .0625
>
> I'll note that GNU dc(1) behaves the same way, so I think it is a
> case of poorly documented or counter-intuitive behavior rather than
> a bug.
The man page makes clear, in a slightly muddy sort of way, that scale
set with the "k" operator can set limits on the scale of the output, but
is not deterministic. See the section on the ordinary arithmetic
operators. Base conversion, apparently, ignores the scale set with
"k". A bit clumsy, IMHO; for starters, 4 digits of precision in hex
isn't exactly 4 digits of precision base 10.
Clumsy? Well, I'd think that
$ dc -e '50k 16i .10 .1 + p'
.06
$
should really output .12, but there is a certain logic to the answer it
does give if one assumes it converts base first and then adds.
For an example where "k" does something:
$ dc -e '3k 16i .10000 .10000 * p'
.00390
$ dc -e '6k 16i .10000 .10000 * p'
.003906
$
Bottom line? dc might not be the best tool for hex fractions. :-(
--Jon Radel
jon@radel.com
[-- Attachment #2 --]
0 *H
010
`He 0 *H
00 #SanzTgk!0
*H
0o10 USE10U
AddTrust AB1&0$UAddTrust External TTP Network1"0 UAddTrust External CA Root0
141222000000Z
200530104838Z010 UGB10UGreater Manchester10USalford10U
COMODO CA Limited1A0?U8COMODO SHA-256 Client Authentication and Secure Email CA0"0
*H
0
zSNpRV&IQZI`zQBy"aNv#
J n=ٺ.CRC|2PȦOZϓ%{0dV*$3DiFK3@@:*S= a<UNv%!)|qvO_T{5R"=,0-1YR73i-C֥wgQ'뼥8v8ߌIs:2:=F:WtaP@?⟢! 00U#0z4&&T$T0UakᢠOg£ 0U0U0 0U%0++0U
00U 0DU=0;09753http://crl.usertrust.com/AddTrustExternalCARoot.crl05+)0'0%+0http://ocsp.usertrust.com0
*H
*nU:Uka+ #fjow^a } [jr
AX&MX"cR6}Xޫ;cs{B#ʶM>K-ػBKiۦ74{:ǟO4ne6d)5ֱqC>2Svʆ4,Jؙ
␒ZBj#!eջ~ꌅ b:,Yř38zyJ&|00sT<}k
`i
0
*H
010 UGB10UGreater Manchester10USalford10U
COMODO CA Limited1A0?U8COMODO SHA-256 Client Authentication and Secure Email CA0
150330000000Z
180329235959Z010 UUS10U2215010 UVA10USpringfield10U 6917 Ridgeway Dr.10U
Jon T. Radel1200U)Issued through Jon T. Radel E-PKI Manager10UCorporate Secure Email10U Jon Radel10 *H
jon@radel.com0"0
*H
0
aЩ@@g3eGރ͛; d#>q7&Hf
:3vL"jV#Xݷ>U-H[$SUڻ{Ϝ,z¶IchO=rcyrn v.Vh7k;%ueYuӬnz6!| !Aȡ+,u+
CAպF-un#vjUJWnk%j]
2JPkl 00U#0akᢠOg£ 0UE|GDp/ʚB0U0U0 0U%0++0FU ?0=0;+10+0)+https://secure.comodo.net/CPS0]UV0T0RPNLhttp://crl.comodoca.com/COMODOSHA256ClientAuthenticationandSecureEmailCA.crl0+00X+0Lhttp://crt.comodoca.com/COMODOSHA256ClientAuthenticationandSecureEmailCA.crt0$+0http://ocsp.comodoca.com0U0
jon@radel.com0
*H
KS `?H_D`8G߿VbĘ<tB-Ӈї|{'Ũݹg0Gp$%F(;*MO*gt$@ t6,?0|#ăz,&! {j2i[%b7ߪP+9G㲍["y<?8rZ'[UR6%L̤
w"=:L~Ƨ^jf36 OP1.}(e1A0=0010 UGB10UGreater Manchester10USalford10U
COMODO CA Limited1A0?U8COMODO SHA-256 Client Authentication and Secure Email CAsT<}k
`i
0
`He a0 *H
1 *H
0 *H
1
160113225225Z0/ *H
1" Ix/x[!"m7)/u0"?0l *H
1_0]0 `He*0 `He0
*H
0*H
0
*H
@0+0
*H
(0 +710010 UGB10UGreater Manchester10USalford10U
COMODO CA Limited1A0?U8COMODO SHA-256 Client Authentication and Secure Email CAsT<}k
`i
0*H
1010 UGB10UGreater Manchester10USalford10U
COMODO CA Limited1A0?U8COMODO SHA-256 Client Authentication and Secure Email CAsT<}k
`i
0
*H
L>un9<zvbfWT:$33 gcd)|s/x_a"wp6!4ɭ rA6 6.v@R1)Jfvs}㨏-tLt`_XC MHSx3Pcr] jq"1i)P14i
\ʦ>s]3~(mӐ9C:ZִL<dt,-
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5696D529.9080901>
