Discussion:
apnum
o***@gmail.com
2018-11-06 11:20:53 UTC
Gods of TeX and LaTeX, please enlighten me with your wisdom: in the apnum package how can I
(a) replace the dot with a comma in the calculations with decimals? (for instance, use pi as 3,1415 instead of 3.1415).
(b) convert easily from the "calculator" scientific notation to the "pretty" scientific notation? (for instance, to print a result as 3\times10^{8} instead of 3E8).
Jean-Côme Charpentier
2018-11-06 19:35:01 UTC
There is only one God of TeX and his name is Knuth

<https://www.netfunny.com/rhf/jokes/99/Aug/knuth.html>
Post by o***@gmail.com
in the
apnum package how can I (a) replace the dot with a comma in the
calculations with decimals? (for instance, use pi as 3,1415 instead
of 3.1415).
Not so easily (it's hard coded) but xstring could be useful:

-----%<----------%<----------%<----------%<----------%<-----
\input apnum
\input xstring

\evaldef\A {2.3+5.15}
\StrSubstitute{$\A$}{.}{,}

\StrSubstitute{$\A$}{.}{{,}}
\bye
-----%<----------%<----------%<----------%<----------%<-----

Note the substitution by "{,}" rather than by "," (better result).

(b) convert easily from the "calculator" scientific
Post by o***@gmail.com
notation to the "pretty" scientific notation? (for instance, to print
a result as 3\times10^{8} instead of 3E8).
Maybe

-----%<----------%<----------%<----------%<----------%<-----
\input apnum

\def\printsci#1{%
\expandafter\printsciaux#1EE\stop
}
\def\printsciaux#1E#2\stop{%
\def\Expo{#2}
\if\Expo\stringE
#1\times10^0
\else
\Clean#2\stop
#1\times10^{\EXPO}
\fi
}
\def\stringE{E}
\def\Clean#1EE\stop{%
\CleanSign#1\stop
}
\def\CleanSign#1#2\stop{%
\if#1+
\def\EXPO{#2}%
\else
\def\EXPO{#1#2}%
\fi
}

% Examples

\evaldef\foo{3.14*4}
$\printsci\foo$

\evaldef\foo{3.14E5*4E9}
$\printsci\foo$
\bye
-----%<----------%<----------%<----------%<----------%<-----

Jean-Côme Charpentier
o***@gmail.com
2018-11-06 21:07:59 UTC