Mike Huber wrote:

> Hi,
>    I'm just trying to do some quick calculations using bc, but the
> version installed through portage truncates on
> multiplication/division.  It didn't used to do this 2 years ago when I
> was taking number theory, and there are no USE flags available for
> sys-devel/bc to change this.  From the manpage:
>
> ---------------------------------------------------------------------
>
> The most basic element in bc is the number.  Numbers are arbitrary
> precision numbers.  This precision is both in
> the  integer  part  and  the fractional part.  All numbers are
> represented internally in decimal and all computation is done in
> decimal.  ( This  version  truncates  results from divide and multiply
> operations.)  There are two attributes of numbers, the length and the
> scale.  The length is the total number of significant  decimal  digits
> in a number and the scale is the total number of decimal digits after
> the decimal point.  For example:
>                .000001 has a length of 6 and scale of 6.
>                1935.000 has a length of 7 and a scale of 3.
>
>
> ------------------------------------------------------------------------
>
>
> Anyone have any ideas?
>
> --Mike

Hi,

Try this.

$ echo '1/5' | bc
0
$ echo '1/5' | bc -l
.20000000000000000000

I don't think bc has changed in a long time.
Maybe you forgot the -l option.

You can also control the scale explicitly like this.

echo 'scale=3;1/5' | bc -l
.200

Hope this helps.

John Green




-- 
gentoo-user@gentoo.org mailing list

Reply via email to