Live data from Hacker News

A deeper introduction to Unix DC

ben165.github.io

11–20 of 21 posts

Re: A deeper introduction to Unix DC

#11
post #5

dc is worth having installed because of this CLI gem alone: echo "[q]sa[ln0=aln256%Pln256/snlbx]sb729901041524823122snlbxq" | dc I've never tried to understand what's really going on to produce the result, but also wouldn't really know where to start - maybe someone in HN's audience can enlighten me? :)

    echo '1033333377708482P' | dc
produces the same output using Unix dc but not in the GNU near-clone. (To understand why, you have to R the P as well as the M.)

Re: A deeper introduction to Unix DC

#13
post #8
post #6

Earlier quoted context omitted.

dc and bc are standard POSIX utils (and also part of busybox for embedded systems) so for most unix-like systems they're installed by default unless you take active measures to exclude them.

POSIX.1-2017 describes the `dc` program as "excluded" from the standard; check https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu... for details. Many GNU/Linux distros (at least Debian and RHEL) install neither `dc` nor `bc` by default, afaik.

I stand corrected, only bc is included in POSIX.

Re: A deeper introduction to Unix DC

#14
post #8
post #6

Earlier quoted context omitted.

dc and bc are standard POSIX utils (and also part of busybox for embedded systems) so for most unix-like systems they're installed by default unless you take active measures to exclude them.

POSIX.1-2017 describes the `dc` program as "excluded" from the standard; check https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu... for details. Many GNU/Linux distros (at least Debian and RHEL) install neither `dc` nor `bc` by default, afaik.

Gentoo doesn't include it in the common 'stage3' tarball, either. Which is annoying because it's actually required to compile the linux kernel.

Re: A deeper introduction to Unix DC

#15
I love reading examples of these "great-great-grandparent" applications hidden in /bin. I've used dc in shell scripts for years, but for the simplest of simple computations (e.g., automating FDISK partitioning and doing sector math). Had no idea it could do this.

TIL this and a cool CSS trick.

Re: A deeper introduction to Unix DC

#16
post #5

dc is worth having installed because of this CLI gem alone: echo "[q]sa[ln0=aln256%Pln256/snlbx]sb729901041524823122snlbxq" | dc I've never tried to understand what's really going on to produce the result, but also wouldn't really know where to start - maybe someone in HN's audience can enlighten me? :)

https://stackoverflow.com/questions/37880810/how-come-is-thi...

Re: A deeper introduction to Unix DC

#17

    [Monte Carlo approximation of Pi.
    Registers:
    u - routine : execute i if sum of squares less than 1
    i - routine : increment register x
    z - routine : iterator - execute u while n > m++
    r - routine : RANDU PRNG
    m - variable: number of samples
    x - variable: number of samples inside circle
    s - variable: seed for r
    k - variable: scale for division
    n - variable: number of iterations (user input)
    ]c
    [lrx 2^ lrx 2^ + 1>i]su
    [lx 1+ sx]si
    [lu x lm 1+ d sm ln>z]sz
    [0k ls 65539 * 2 31^ % d ss lkk 2 31 ^ /]sr
    ? sn
    5dksk
    1 ss
    lzx
    lx lm / 4*
    p

    $ dc pi.dc
    100000
    3.13372

Re: A deeper introduction to Unix DC

#18
post #8
post #6

Earlier quoted context omitted.

dc and bc are standard POSIX utils (and also part of busybox for embedded systems) so for most unix-like systems they're installed by default unless you take active measures to exclude them.

POSIX.1-2017 describes the `dc` program as "excluded" from the standard; check https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu... for details. Many GNU/Linux distros (at least Debian and RHEL) install neither `dc` nor `bc` by default, afaik.

> Many GNU/Linux distros (at least Debian and RHEL) install neither `dc` nor `bc` by default, afaik.

Yeah, I recently wrote a script that used bc and immediately discovered that it didn't work on at least Arch Linux (and I think others, although I only seem to have added it to the Arch ansible config...); conveniently, I only needed the most trivial of calculations, so I just shifted to awk, which has better default availability.

Re: A deeper introduction to Unix DC

#19
post #5

dc is worth having installed because of this CLI gem alone: echo "[q]sa[ln0=aln256%Pln256/snlbx]sb729901041524823122snlbxq" | dc I've never tried to understand what's really going on to produce the result, but also wouldn't really know where to start - maybe someone in HN's audience can enlighten me? :)

  echo 'EGSZ%%%'|tr 'E-Z%' 'R-ZA-M!'
Post reply on HN