[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bc and dc. (Was: neatroff for Russian.)

From: Alejandro Colomar
Subject: Re: bc and dc. (Was: neatroff for Russian.)
Date: Fri, 28 Apr 2023 15:23:42 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0

Hi Ralph,

On 4/28/23 11:34, Ralph Corderoy wrote:
> Hi Alejandro,
> None of the below may apply to GNU's bc and dc.  I prefer Unix.
>> bc(1) on the contrary, is likely to be using 'long double', for being
>> able to provide so many digits.
> No, bc doesn't use a C language or machine type.  The precision can
> be set.
>     $ bc -l
>     scale=42
>     l(1114112) / l(2)
>     20.087462841250339408254066010810404354011270
>     $
> bc's l() function is written in bc rather than a built-in and can be
> read for fun.  bc uses dc(1) to do the work and can be asked to ‘compile
> only’ with -c.  dc has k to set the precision; bc's scale simply uses k.

Would you please share that?  I'm curious.  I could only see this:

$ echo 'l(1114112) / l(2)' | bc -lc

$ echo 'l(1114112) / l(2)' | /usr/lib/plan9/bin/bc -c
 1114112 l<12>x 2 l<12>x/ps.

$ echo 'l(1114112) / l(2)' | /usr/lib/plan9/bin/bc -lc
c[cannot open input file:1, ]pc
 1114112 l<12>x 2 l<12>x/ps.

> dc uses a byte to store each pair of decimal digits.  This allows
> overflow within the byte during calculations and makes it quick to
> perform the common case of formatting the many-byte number to
> decimal-digit text.

Makes sense.


GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]