At 10:31 PM 12/5/2001 +0100, Tobias Burnus wrote:
>Hi,
>
>I have a nice document where I need to perform small calculation (actually
>only calculating the average value):
>  if((#1+#2+#3) != 0)
>    (#1*1 + #2*2 + #3*3)/(#1+#2+#3)
>  else
>    "--"
>
>Now I was thinking where I could do so in TeX. (I think there are some
>macros in ConTeXt, but I cannot find them.)

You can play a bit with etex's \dimexpr and \numexpr (docu on tex live)

\def\Tobiased#1#2#3%
   {\ifdim\dimexpr(#1pt+#2pt+#3pt)=\zeropoint
    \else
       \expandafter\withoutpt\the\dimexpr
         (\dimexpr(1\dimexpr(#1pt) + 2\dimexpr(#2pt) + 3\dimexpr(#3pt))/
          \dimexpr(          #1pt  +           #2pt  +           #3pt))
    \fi}

\Tobiased{10}{150}{310.2}

So, te numbers become dimens and are stripped afterwards

>The output should be of the form "1{,}4" (i.e. separator is a {,} and I
>get one figure after the separator).

How about:

\def\OneAfter#1%
   {\expandafter\beforesplitstring#1\at.\to\Before
    \expandafter\aftersplitstring#1\at.\to\After
    \Before.\expandafter\AfterIndeed\After0000\relax}

\def\AfterIndeed#1#2#3\relax{#1}

\OneAfter{1.23}
\OneAfter{1}
\def\Oeps{1.234}
\OneAfter\Oeps

You can probably figure out the rest

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | [EMAIL PROTECTED]
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------

Reply via email to