groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] Arithmetic in groff


From: Mike Bianchi
Subject: Re: [Groff] Arithmetic in groff
Date: Wed, 21 Oct 2009 09:30:00 -0400
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

Joachim,

10^2 Thanks!

I made one _little_ change.  I always name my macros, etc. starting with a 
Capital Letter, so as to keep them distinct from the standard offerings.

                                                        Mike Bianchi

On Tue, Oct 20, 2009 at 08:41:39PM +0200, Joachim Walsdorff wrote:
> Here is a little macro to enhance the restricted groff-arithmetics. It  
> uses the unix bc-command for arbitrary precision calculations (see the  
> bc-manpage). Maybe it's easier to use for people (like me) who are not  
> familiar with pic to use its numerical engine like suggested by Ted:
>
> .de calc
> .  sy  echo -n ".ds *calc " > /tmp/calc; echo "\\$*" | bc -l >> /tmp/calc
> .  pso cat /tmp/calc; rm /tmp/calc
> ..
>
> The argument of calc is the expression to be calculated; string *calc  
> returns the result. groff must be called with -U, because the  register  
> .U is readonly and therefore it is not possible to change between  
> safe/unsafe-mode inside groff.
>
> Examples:
>
> .calc scale=5; 10^2      \" scale=5: 5 digits right from the decimal point.
> .tm \*[*calc] => 100.00000
>
> The second example should yield the same result:
>
> .calc scale=5; e(2*l(10))\" e=exponential function, l=natural logarithm.
> .tm \*[*calc] => 99.99898
>
> This result is not exact, since bc /truncates/ (without rounding) the  
> values of e(2) and l (10) to 5 digits (value of scale).
>
> Joachim

-- 
 Mike Bianchi
 Foveal Systems

 973 822-2085   call to arrange Fax

 address@hidden
 http://www.AutoAuditorium.com
 http://www.FovealMounts.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]