summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/calculator/calculator.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/calculator/calculator.dtx')
-rw-r--r--macros/latex/contrib/calculator/calculator.dtx123
1 files changed, 87 insertions, 36 deletions
diff --git a/macros/latex/contrib/calculator/calculator.dtx b/macros/latex/contrib/calculator/calculator.dtx
index 41d95f24a0..64f6fe0b6a 100644
--- a/macros/latex/contrib/calculator/calculator.dtx
+++ b/macros/latex/contrib/calculator/calculator.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment
%
-% Copyright (C) 2012, 2014 by Robert Fuster <rfuster@mat.upv.es>
+% Copyright (C) 2012, 2014, 2022 by Robert Fuster <rfuster@mat.upv.es>
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3 of this license
@@ -27,15 +27,16 @@
%<*driver>
\documentclass{ltxdoc}
\ProvidesFile{calculator.dtx}
- [2014/02/20 v.2.0 documented calculator package]
+ [2022/09/15 v.2.1 documented calculator package]
\usepackage{calculus}
\usepackage{amsmath}
\usepackage[lmargin=1.75in,rmargin=1in]{geometry}
\usepackage{fancyvrb}
-\def\fileversion{2.0}
-\def\filedate{2014/02/20}
+\usepackage[colorlinks]{hyperref}
+\def\fileversion{2.1}
+\def\filedate{2022/09/15}
\GetFileInfo{calculator.dtx}
@@ -58,6 +59,7 @@
\newcommand{\Marg}[1]{\textnormal{\marg{#1}}}
\newcommand{\newinversion}[1]{\textnormal{\textit{(new in version~#1)}}}
+\newcommand{\renewinversion}[2][]{\textnormal{\footnote{code modified in version~#2\ifx"#1"\else\space (#1)\fi.}}}
\newcommand{\arccot}{\operatorname{arccot}}
\newcommand{\arsinh}{\operatorname{arsinh}}
@@ -97,11 +99,12 @@
%
% \fi
%
-% \CheckSum{3753}
+% \CheckSum{3913}
% \changes{v1.0}{2012/04/25}{First public version}
% \changes{v1.0a}{2012/06/10}{calculator.dtx modified to make it autoinstallable.
% calculus.dtx embedded in calculus.dtx}
% \changes{v2.0}{2014/02/20}{new calculator.dtx and calculator.ins files}
+% \changes{v2.1}{2022/09/15}{Some bugs fixed}
%% \CharacterTable
%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
@@ -154,6 +157,10 @@
% (so that we can work with all the classic elementary functions),
% and also can do some additional calculation with vectors
% (such as the cross product and the angle between two vectors).
+
+% Version 2.1 fixes some bugs and calculation problems.\footnote{Thanks to
+% Schmitz Manuel, Thorsten Wolterin, Jim Cline,
+% Schremmer Alain and July Tikhonov.}
% \end{abstract}
%
% \tableofcontents
@@ -447,7 +454,8 @@
% \end{exemple}
% \item[\cs{FRACTIONALPART}\marg{num}\marg{\cs{cmd}}]%
% \SpecialUsageIndex{\FRACTIONALPART}%
-% Fractional part of \textttit{num}.
+% Fractional part of \textttit{num}.\renewinversion[thanks to July Tikhonov
+% who reported a bug and suggested the solution]{2.1}
% \begin{exemple}
% \FRACTIONALPART{1.256}{\sol}
% \sol
@@ -463,7 +471,9 @@
% truncates the number \textttit{num} to \textttit{n} decimal places.
% \item[\cs{ROUND}{[\textttit{n}]}\marg{num}\marg{\cs{cmd}}]%
% \SpecialUsageIndex{\ROUND}%
-% rounds the number \textttit{num} to \textttit{n} decimal places.
+% rounds the number \textttit{num} to \textttit{n} decimal places.%
+% \renewinversion[thanks to Jim Cline and Schremmer Alain
+% who reported a bug]{2.1}
%
% The optional argument \textttit{n} may be \texttt{0}, \texttt{1},
% \texttt{2}, \texttt{3} or \texttt{4} (the default is \texttt{2}).\footnote{%
@@ -1872,7 +1882,7 @@
% \begin{macrocode}
%<*calculator>
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{calculator}[2014/02/20 v.2.0]
+\ProvidesPackage{calculator}[2022/09/15 v.2.1]
% \end{macrocode}
% \subsection{Internal lengths and special numbers}
% \cs{cctr@lengtha} and \cs{cctr@lengthb}
@@ -1902,6 +1912,18 @@
% \end{macro}
% \subsection{Warning messages}
% \begin{macrocode}
+\def\cctr@Warntruncate#1#2{%
+ \PackageWarning{calculator}%
+ {The optional argument in truncate \MessageBreak
+ must be less than 5 \MessageBreak
+ I copy #1 to #2 \MessageBreak without truncating}}
+
+\def\cctr@Warnround#1#2{%
+ \PackageWarning{calculator}%
+ {The optional argument in round \MessageBreak
+ must be less than 5 \MessageBreak
+ I copy #1 to #2 \MessageBreak without rounding}}
+
\def\cctr@Warndivzero#1#2{%
\PackageWarning{calculator}%
{Division by 0.\MessageBreak
@@ -2347,7 +2369,7 @@
% returns the integer part of \textit{\#2}.
% \begin{macrocode}
\def\@@INTEGERPART#1.#2.#3)#4{\ifnum #11=1 \COPY{0}{#4}
- \else \COPY{#1}{#4}\fi}
+ \else \ADD{0}{#1}{#4}\fi}
\def\@INTEGERPART#1#2{\expandafter\@@INTEGERPART#1..){#2}}
\def\INTEGERPART#1#2{\begingroup
\ifdim #1\p@<\z@
@@ -2372,9 +2394,10 @@
% \cs{FRACTIONALPART}\marg{\#1}\marg{\#2}
% returns the fractional part of
% \textit{\#2}.
+% \changes{v2.1}{2022/09/15}{Bug fixed}
% \begin{macrocode}
-\def\@@FRACTIONALPART#1.#2.#3)#4{\ifnum #2=11 \COPY{0}{#4}
- \else \COPY{0.#2}{#4}\fi}
+\def\@@FRACTIONALPART#1.#2.#3)#4{\ifnum #21=1 \COPY{0}{#4}
+ \else \ADD{0}{0.#2}{#4}\fi}
\def\@FRACTIONALPART#1#2{\expandafter\@@FRACTIONALPART#1..){#2}}
\def\FRACTIONALPART#1#2{\begingroup
\ifdim #1\p@<\z@
@@ -2382,24 +2405,29 @@
\SUBTRACT{#1}{\cctr@tempA}{#2}
\else
\@FRACTIONALPART{#1}{#2}
- \fi\@OUTPUTSOL{#2}}
+ \fi\@OUTPUTSOL{#2}}
+
% \end{macrocode}
% \end{macro}
% \begin{macro}{\TRUNCATE}
% \cs{TRUNCATE}\oarg{\#1}\marg{\#2}\marg{\#3}
% truncates \textit{\#2} to \textit{\#1} (0, 1, 2 (default), 3 or 4) digits.
+% \changes{v2.1}{2022/09/15}{Bug fixed}
% \begin{macrocode}
\def\TRUNCATE{\@ifnextchar[\@@TRUNCATE\@TRUNCATE}
\def\@TRUNCATE#1#2{\@@TRUNCATE[2]{#1}{#2}}
\def\@@TRUNCATE[#1]#2#3{%
- \begingroup
+ \begingroup
+ \ifdim #1\p@ > 4\p@ \cctr@Warntruncate{#2}{\noexpand#3} \COPY{#2}{#3}
+ \else
\INTEGERPART{#2}{\cctr@tempa}
- \ifdim \cctr@tempa\p@ = #2\p@
- \expandafter\@@@TRUNCATE#2.00000)[#1]{#3}
+ \ifdim \cctr@tempa\p@ = #2\p@
+ \expandafter\@@@TRUNCATE\cctr@tempa.00000.)[#1]{#3}
\else
\expandafter\@@@TRUNCATE#200000.)[#1]{#3}
- \fi
- \@OUTPUTSOL{#3}}
+ \fi\fi
+ \@OUTPUTSOL{#3}}
+
\def\@@@TRUNCATE#1.#2#3#4#5#6.#7)[#8]#9{%
\ifcase #8
\COPY{#1}{#9}
@@ -2413,27 +2441,48 @@
% \begin{macro}{\ROUND}
% \cs{ROUND}\oarg{\#1}\marg{\#2}\marg{\#3}
% rounds \textit{\#2} to \textit{\#1} (0, 1, 2 (default), 3 or 4) digits.
+% \changes{v2.1}{2022/09/15}{Bug fixed}
% \begin{macrocode}
\def\ROUND{\@ifnextchar[\@@ROUND\@ROUND}
\def\@ROUND#1#2{\@@ROUND[2]{#1}{#2}}
\def\@@ROUND[#1]#2#3{%
- \begingroup
- \ifdim#2\p@<\z@
- \MULTIPLY{-1}{#2}{\cctr@temp}
- \@@ROUND[#1]{\cctr@temp}{#3}\COPY{-#3}{#3}
- \else
- \@@TRUNCATE[#1]{#2}{\cctr@tempe}
- \SUBTRACT{#2}{\cctr@tempe}{\cctr@tempc}
- \POWER{10}{#1}{\cctr@tempb}
- \MULTIPLY{\cctr@tempb}{\cctr@tempc}{\cctr@tempc}
- \ifdim\cctr@tempc\p@<0.5\p@
- \else
- \DIVIDE{1}{\cctr@tempb}{\cctr@tempb}
- \ADD{\cctr@tempe}{\cctr@tempb}{\cctr@tempe}
- \fi
- \@@TRUNCATE[#1]{\cctr@tempe}{#3}
- \fi
- \@OUTPUTSOL{#3}}
+ \begingroup
+ \ifdim #1\p@ > 4\p@ \cctr@Warnround{#2}{\noexpand#3} \COPY{#2}{#3}
+ \else
+ \INTEGERPART{#2}{\cctr@tempa}
+ \ifdim \cctr@tempa\p@ = #2\p@
+ \expandafter\@@@ROUND\cctr@tempa.00000.)[#1]{#3}
+ \else
+ \expandafter\@@@ROUND#200000.)[#1]{#3}
+ \fi
+ \fi
+ \@OUTPUTSOL{#3}}
+
+\def\@@@ROUND#1.#2#3#4#5#6.#7)[#8]#9{%
+ \ifcase #8
+ \COPY{#1}{#9} \ifnum #2>4 \ADD{#1}{1}{\cctr@tempp}\COPY{\cctr@tempp}{#9} \fi
+ \or\COPY{#1.#2}{#9} \ifnum #3>4 \ADD{#2}{1}\cctr@tempq\COPY{#1}{\cctr@tempp}
+ \ifnum\cctr@tempq=10\ADD{\cctr@tempp}{1}\cctr@tempp\COPY{0}{\cctr@tempq}\fi
+ \COPY{\cctr@tempp.\cctr@tempq}{#9}
+ \fi
+ \or\COPY{#1.#2#3}{#9} \ifnum #4>4 \ADD{#3}1\cctr@tempq\COPY{#2}{\cctr@tempp}\COPY{#1}{\cctr@tempo}
+ \ifnum\cctr@tempq=10\ADD{\cctr@tempp}{1}{\cctr@tempp}\COPY{0}{\cctr@tempq}\fi
+ \ifnum\cctr@tempp=10\ADD{\cctr@tempo}{1}\cctr@tempo\COPY{0}{\cctr@tempp}\fi
+ \COPY{\cctr@tempo.\cctr@tempp\cctr@tempq}{#9}
+ \fi
+ \or\COPY{#1.#2#3#4}{#9} \ifnum #5>4 \ADD{#4}1\cctr@tempq\COPY{#3}{\cctr@tempp}\COPY{#2}{\cctr@tempo}\COPY{#1}{\cctr@tempn}
+ \ifnum\cctr@tempq=10\ADD{\cctr@tempp}{1}{\cctr@tempp}\COPY{0}{\cctr@tempq}\fi
+ \ifnum\cctr@tempp=10\ADD{\cctr@tempo}{1}\cctr@tempo\COPY{0}{\cctr@tempp}\fi
+ \ifnum\cctr@tempo=10\ADD{\cctr@tempn}{1}\cctr@tempn\COPY{0}{\cctr@tempo}\fi
+ \COPY{\cctr@tempn.\cctr@tempo\cctr@tempp\cctr@tempq}{#9}
+ \fi
+ \or\COPY{#1.#2#3#4#5}{#9} \ifnum #6>4 \ADD{#5}1\cctr@tempq\COPY{#4}{\cctr@tempp}\COPY{#3}{\cctr@tempo}\COPY{#2}{\cctr@tempn}\COPY{#1}{\cctr@tempm}
+ \ifnum\cctr@tempq=10\ADD{\cctr@tempp}{1}{\cctr@tempp}\COPY{0}{\cctr@tempq}\fi
+ \ifnum\cctr@tempp=10\ADD{\cctr@tempo}{1}\cctr@tempo\COPY{0}{\cctr@tempp}\fi
+ \ifnum\cctr@tempo=10\ADD{\cctr@tempn}{1}\cctr@tempn\COPY{0}{\cctr@tempo}\fi
+ \ifnum\cctr@tempn=10\ADD{\cctr@tempm}{1}\cctr@tempm\COPY{0}{\cctr@tempn}\fi
+ \COPY{\cctr@tempm.\cctr@tempn\cctr@tempo\cctr@tempp\cctr@tempq}{#9}
+ \fi}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\GCD}
@@ -3196,9 +3245,11 @@
% \end{macrocode}
%
% We start with |\cctr@lengthb=5\p@| to ensure almost one iteration.
+% \changes{v2.1}{2022/09/15}{Changed stop criterion on iterations to 2sp}
% \begin{macrocode}
\cctr@lengthb=5\p@%
-% \end{macrocode}
+ \cctr@epsilon=2\cctr@epsilon%
+% \end{macrocode}
% Successive iterations
% \begin{macrocode}
\@whilenum \cctr@lengthb>\cctr@epsilon \do {%
@@ -4400,7 +4451,7 @@
\ProvidesPackage{calculus}[2014/02/20 v.2.0]
% \end{macrocode}
% This package requires the calculator package.
-% \begin{macrocode}
+% \begin{macrocode}
\RequirePackage{calculator}
% \end{macrocode}
% \subsection{Error and info messages}