Home > Software engineering >  Linux tool dc gives "stack underflow" error
Linux tool dc gives "stack underflow" error

Time:12-11

I'm trying to calculate a floating number via shell. When I execute the following line, the dc tool fails.

dc -e "4000 0.531 / p"

First, I was thinking that the problem was related to the floating precision. Then, I tried to change the divider with an integer. Unfortunately, the result is the same.

dc -e "4000 1000 / p"

Both of the executions above gives the same error:

dc: stack underflow

Host CPU is ARM-Cortex A53 placed inside the Zynq Ultrascale SoC. What would be the reason? How can I solve it?

Additional Info

The output of dc --version also gives the same output.

dc: stack underflow

Luckily, the dc --help works and shows the version as follows.

BusyBox v1.24.1 (2021-12-08 08:10:27 UTC) multi-call binary.

The output of the type dc is as follows

dc is hashed (/usr/bin/dc)

CodePudding user response:

What would be the reason?

Busybox dc does not take any -e argument. Because -e is parsed as - followed by command e, - tries to pop two values and the stack is empty.

How can I solve it?

Just:

dc "4000 0.531 / p"

The proper way is anyway to pipe the data to stdin.

echo "4000 0.531 / p" | dc
  • Related