Eben King wrote:
> On Sat, 7 Jul 2007, ronan wrote:
>
>> Eben King wrote:
>>> Anyone know how to truncate values in dc(1)? I RTFMed but couldn't
>>> find it. For example:
>>>
>>> If I set the precision to three places:
>>>
>>> 3k
>>>
>>> and then calculate 1/3:
>>>
>>> 1 3/p
>>> .333
>>>
>>> It's correct. Supposing I only want one place to the right of the
>>> decimal point:
>>>
>>> 1k
>>>
>>> Adding 0 or 0.0, or multiplying by 1 or 1.0 won't work:
>>>
>>> 0+p
>>> .333
>>> 0.0+p
>>> .333
>>>
>>> 1*p
>>> .333
>>> 1.0*p
>>> .333
>>>
>>> So how do I do it?
>>>
>> Before doing your math, send "1 k" to set the precision to 1 decimal
>> place. For example:
>>
>> 1 k 1 3/p
>>
>> yields:
>> .3
>
> I think that sets the intermediate precision as well as the output
> precision. That is generally undesirable, and can only be worked around
> with careful equation design. For example:
>
> 1k 41 90 / 90 * p
> 36.0
> 8k 41 90 / 90 * p
> 40.99999950
>
I've used dc a fair amount, and I know of no way to specify intermediate
precision differently from output precision in a single statement. For
example:
3 k 1 3 / p
.333
3 k 1 3 / 1 k p
.333
3 k 1 3 / p 1 k p
.333
.333
It's a weird problem, and I don't know a way around it.
Paul
-- Paul M. Foster ----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.
This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:48:34 EDT