1 |
Mike Huber wrote: |
2 |
|
3 |
> Hi, |
4 |
> I'm just trying to do some quick calculations using bc, but the |
5 |
> version installed through portage truncates on |
6 |
> multiplication/division. It didn't used to do this 2 years ago when I |
7 |
> was taking number theory, and there are no USE flags available for |
8 |
> sys-devel/bc to change this. From the manpage: |
9 |
> |
10 |
> --------------------------------------------------------------------- |
11 |
> |
12 |
> The most basic element in bc is the number. Numbers are arbitrary |
13 |
> precision numbers. This precision is both in |
14 |
> the integer part and the fractional part. All numbers are |
15 |
> represented internally in decimal and all computation is done in |
16 |
> decimal. ( This version truncates results from divide and multiply |
17 |
> operations.) There are two attributes of numbers, the length and the |
18 |
> scale. The length is the total number of significant decimal digits |
19 |
> in a number and the scale is the total number of decimal digits after |
20 |
> the decimal point. For example: |
21 |
> .000001 has a length of 6 and scale of 6. |
22 |
> 1935.000 has a length of 7 and a scale of 3. |
23 |
> |
24 |
> |
25 |
> ------------------------------------------------------------------------ |
26 |
> |
27 |
> |
28 |
> Anyone have any ideas? |
29 |
> |
30 |
> --Mike |
31 |
|
32 |
Hi, |
33 |
|
34 |
Try this. |
35 |
|
36 |
$ echo '1/5' | bc |
37 |
0 |
38 |
$ echo '1/5' | bc -l |
39 |
.20000000000000000000 |
40 |
|
41 |
I don't think bc has changed in a long time. |
42 |
Maybe you forgot the -l option. |
43 |
|
44 |
You can also control the scale explicitly like this. |
45 |
|
46 |
echo 'scale=3;1/5' | bc -l |
47 |
.200 |
48 |
|
49 |
Hope this helps. |
50 |
|
51 |
John Green |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
-- |
57 |
gentoo-user@g.o mailing list |