|
Home > Archive > Unix Shell > November 2006 > precision of bc (was: printing stings in bc -- basic calculator)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
precision of bc (was: printing stings in bc -- basic calculator)
|
|
| Michael Paoli 2006-11-26, 7:18 pm |
| Stephane CHAZELAS wrote:
> 2006-11-25, 16:57(+00), Robert Katz:
>
> bc is arbitrary precision so has no limit. awk will generally
That's a nice theory, but may implementations of bc(1) are fairly
limited in their precision - and well before CPU or memory become the
practical limiting factors. I've seen many bc(1) implementations that
bomb out (typically core dumping) somewhere in the range of 20 to 55
for scale. E.g. try:
$ echo 'scale=60;4*a(1)' | bc -l
on some various implementations and see what you get. There are many
that can't handle that.
| |
| Stephane CHAZELAS 2006-11-26, 7:18 pm |
| 2006-11-26, 14:08(-08), Michael Paoli:
> Stephane CHAZELAS wrote:
>
> That's a nice theory, but may implementations of bc(1) are fairly
> limited in their precision - and well before CPU or memory become the
> practical limiting factors. I've seen many bc(1) implementations that
> bomb out (typically core dumping) somewhere in the range of 20 to 55
> for scale. E.g. try:
> $ echo 'scale=60;4*a(1)' | bc -l
> on some various implementations and see what you get. There are many
> that can't handle that.
You're right.
The POSIX conformant implementations should support at least
scale=99 though.
getconf BC_SCALE_MAX
should give the actual limit, except that on Solaris, the limit
seems to be 98 despite getconf BC_SCALE_MAX pretending it's 99.
On GNU, 99 is returned as well, but GNU bc doesn't seem to have
any limit.
--
Stéphane
|
|
|
|
|