Questions tagged [dc]

dc is an arbitrary precision calculator which reads instructions from standard input or files.

A reverse-polish calculator stores numbers on a stack. Entering a number pushes it on the stack. Arithmetic operations pop 1 to 3 arguments off the stack, depending on the operation, and push the results back onto the stack.

Links

See also

  • (An arbitrary precision calculator)
42 questions
16
votes
2 answers

Making decimal.Decimal the default numerical type in Python

Is there some way I could make decimal.Decimal the default type for all numerical values in Python? I would like to be able to use Python in a manner similar to the bc and dc programs without having to call decimal.Decimal(...) for every…
Eric Pruitt
  • 1,825
  • 3
  • 21
  • 34
8
votes
0 answers

How do I use the "three line version of the RSA algorithm" written in Perl?

The book "An Introduction to Mathematical Cryptography" by J. Hoffstein et al. talks about a three-line implementation of the RSA algorithm in Perl, which people used to protest US government censorship of cryptography: To protest the government's…
Árni Dagur
  • 89
  • 1
  • 2
8
votes
2 answers

Rounding the result using dc (desk calculator)

Is it possible to round the top of the stack using dc in a shell skript? If yes are there commands to round the result up and down? Thanks guys!
MichaelScott
  • 387
  • 1
  • 3
  • 21
7
votes
1 answer

dc: how do I pop (and discard) the top number of the stack?

In dc, how do I pop and discard a number from the top of the stack? A stack with three items (1 2 3) should become a stack with two items (2 3). Currently I'm shoving the number onto another stack (Sz) but that seems rather lame.
Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
5
votes
1 answer

Is it possible to set a default precision for the Unix dc calculator? Is there a config file for it?

You can set the precision after invoking dc with the 'k' command, which pops a number off the stack and uses it to set the precision. But I always want a precision of three digits after the decimal by default. Is there a way to set a default…
Magneto
  • 93
  • 7
4
votes
1 answer

Compute logarithms in dc

I have seen this question for bc, but how do you do this in dc? For example, if the command were q, I would want to use it like this: 10k 5q2q/ To compute log_2(5).
Brian McCutchon
  • 8,354
  • 3
  • 33
  • 45
3
votes
6 answers

Most elegant unix shell one-liner to sum list of numbers of arbitrary precision?

As regards integer adding one-liners, several proposed shell scripting solutions exist; however, on closer look at each of the solutions chosen, there are inherent limitations: awk ones would choke at arbitrary precision and integer size (it…
fgeorgatos
  • 171
  • 1
  • 10
3
votes
1 answer

dc (desk calculator) - hashes type

Reading this page on TLDP: http://www.tldp.org/LDP/abs/html/mathc.html I've found the following command: bash$ echo "16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D68736142snlbxq" | dc Bash And I was just wondering: someone knows what type of hash is that…
Hector
  • 31
  • 1
2
votes
0 answers

Convert values of two dc motors to angle ( single output)

I have built a 2WD + caster robot car. The two back wheels are powered by two dc motors. The steering is done by either turning on both motors to drive straight forward or turning any of them to turn left or right. I have written a python code that…
E199504
  • 425
  • 4
  • 12
2
votes
3 answers

dc(1) and leading zeros

I've got a shell script and I do some calculations with dc(1). I need to have one number printed with leading zeros; I can't find an easy and straightforward way to do this with dc itself, but the manpage does mention: Z Pops a value off the…
Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
2
votes
2 answers

Install dc in Cygwin

How to install dc (desktop calculator) in Cygwin? dc is not found among Cygwin packages. Should it be compiled from the sources? What is the proper way?
ruvim
  • 7,151
  • 2
  • 27
  • 36
2
votes
1 answer

Changing to a horizontal stack display with GNU dc?

GNU DC displays the stack vertically, (f displays the stack) 1 2 3 4 f # to display the stack 4 3 2 1 Is there a way to change this to be more like FORTH? While GNU FORTH displays the stack horizontally, (.s displays the stack) 1 2 3 4 ok .s <4>…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
2
votes
1 answer

Branching or if/else in GNU dc (desk calculator)

How would one go about branching in GNU dc? OpenBSD's implementation has conditionals with an else-branch, but GNU's does not... so you can conditionally execute one macro, but when it completes it drops you back in the same place in the code. It…
SAyotte
  • 387
  • 3
  • 9
1
vote
0 answers

DC.js pie chart of already summarized data

I have aggregate data like so: Event Yellows Reds talls shorts A. 1 3 5 0 B. 0 7 17 19 So each row contains a set of colours and a set of heights. The real data has more group fields (event is…
artfulrobot
  • 20,637
  • 11
  • 55
  • 81
1
vote
1 answer

Getting Domain Controller (DC) Site name via Linux (windows "ntlest /sgetsite" equivalent)

I'm trying to extract the domain controller site name On as windows system you can simply run nltest /dsgetsite and get the name. From the doc: "/dsgetsite Returns the name of the site in which the domain controller resides." However, googling…
CapBird
  • 33
  • 5
1
2 3