vote up 0 vote down star

I'm just starting with Gnu's bc and I'm stuck at the very beginning (very discouraging...). I want to divide two numbers and get a float as result:

$bc
bc 1.06.94
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 

15/12
1
15.0/12.0
1
15.000000/12.000000
1
scale(15.00000)
5

The man page says, that division returns a number with the same scale as the initial values. Obviously this is either not true or I'm missing something.

Googling hasn't brought up any new insights (besides that 'BC' can also stand for 'British Columbia').

Do you see my error? Better yet, do you know any good references/tutorials to bc?

flag

1 Answer

vote up 3 vote down check

You can set the scale with

scale=2

Then division works as expected:

scale=2
15/12
1.25

To quote from Wikipedia:

All numbers and variable contents are arbitrary precision numbers whose precision (in decimal places) is determined by the global scale variable.

link|flag
Ah, that is the poodle's core. Can I set the scale globally in some .bcrc file? – Boldewyn Dec 18 at 12:26
Found it: export BC_ENV_ARGS=~/.bcrc – Boldewyn Dec 18 at 12:30
I doubt »Das also war des Pudels Kern [ein fahrender Scholast]« works reliably in other languages :-) At least I don't know how well-known Faust is in other languages :-) – Johannes Rössel Dec 18 at 19:08
This was the poodle's real core, \\ A travelling scholar, then? The casus is diverting. Project Gutenberg ist dein Freund: gutenberg.org/files/14591/14591-h/14591-h.htm – Boldewyn Dec 21 at 17:13
But I must agree, and LEO.org suggests 'the gist of the matter' ;-) – Boldewyn Dec 21 at 17:14

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.