summaryrefslogtreecommitdiff
path: root/graphics/pgf/base/tex/pgfmathfunctions.round.code.tex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/pgf/base/tex/pgfmathfunctions.round.code.tex
Initial commit
Diffstat (limited to 'graphics/pgf/base/tex/pgfmathfunctions.round.code.tex')
-rw-r--r--graphics/pgf/base/tex/pgfmathfunctions.round.code.tex123
1 files changed, 123 insertions, 0 deletions
diff --git a/graphics/pgf/base/tex/pgfmathfunctions.round.code.tex b/graphics/pgf/base/tex/pgfmathfunctions.round.code.tex
new file mode 100644
index 0000000000..4bd05c18c4
--- /dev/null
+++ b/graphics/pgf/base/tex/pgfmathfunctions.round.code.tex
@@ -0,0 +1,123 @@
+% Copyright 2007 by Mark Wibrow
+%
+% This file may be distributed and/or modified
+%
+% 1. under the LaTeX Project Public License and/or
+% 2. under the GNU Public License.
+%
+% See the file doc/generic/pgf/licenses/LICENSE for more details.
+
+% This file defines the mathematical functions and operators.
+%
+% Version 1.414213 29/9/2007
+
+% round function. Uses asymmetric half-up rounding.
+%
+\pgfmathdeclarefunction{round}{1}{%
+ \begingroup%
+ \expandafter\pgfmath@x#1pt\relax%
+ \afterassignment\pgfmath@xa%
+ \expandafter\c@pgfmath@counta\the\pgfmath@x\relax%
+ \pgfmath@xb\pgfmath@x%
+ \ifdim\pgfmath@xb<0pt\relax%
+ \ifdim\pgfmath@xa<0.5pt\relax%
+ \else%
+ \advance\c@pgfmath@counta-1\relax%
+ \fi%
+ \else%
+ \ifdim\pgfmath@xa<0.5pt\relax%
+ \else%
+ \advance\c@pgfmath@counta1\relax%
+ \fi%
+ \fi%
+ \pgfmath@returnone\the\c@pgfmath@counta pt%
+ \endgroup%
+}%
+
+% floor function.
+%
+\pgfmathdeclarefunction{floor}{1}{%
+ \begingroup%
+ \expandafter\pgfmath@x#1pt\relax%
+ \afterassignment\pgfmathfloor@collect@remainder%
+ \expandafter\c@pgfmath@counta\the\pgfmath@x\pgfmath@%
+ \expandafter\pgfmath@x#1pt\relax%
+ \ifdim\pgfmath@x<0pt\relax%
+ \ifdim\pgfmathfloor@remainder>0pt
+ \advance\c@pgfmath@counta by -1\relax%
+ \else
+ % ok, we stripped only '0'.
+ \fi
+ \fi%
+ \pgfmath@x\c@pgfmath@counta pt\relax%
+ \pgfmath@returnone\pgfmath@x%
+ \endgroup%
+}%
+
+\def\pgfmathfloor@collect@remainder#1\pgfmath@{%
+ \def\pgfmathfloor@remainder{#1}%
+ \ifx\pgfmathfloor@remainder\pgfutil@empty
+ \def\pgfmathfloor@remainder{0}%
+ \fi
+}%
+
+% ceil function.
+%
+\pgfmathdeclarefunction{ceil}{1}{%
+ \begingroup%
+ \expandafter\pgfmath@x#1pt\relax%
+ \afterassignment\pgfmath@gobbletilpgfmath@%
+ \expandafter\c@pgfmath@counta\the\pgfmath@x\relax\pgfmath@%
+ \pgfmath@y\pgfmath@x%
+ \advance\pgfmath@y-\c@pgfmath@counta pt\relax%
+ \pgfmath@x\c@pgfmath@counta pt\relax%
+ \ifdim\pgfmath@y>0pt\relax%
+ \advance\pgfmath@x1pt\relax%
+ \fi%
+ \pgfmath@returnone\pgfmath@x%
+ \endgroup%
+}%
+
+% int function
+%
+\pgfmathdeclarefunction{int}{1}{%
+ \begingroup%
+ \expandafter\pgfmathint@@#1.\pgfmath@stop
+ \pgfmath@smuggleone\pgfmathresult%
+ \endgroup}
+
+\def\pgfmathint@@#1.#2\pgfmath@stop{%
+ \def\pgfmath@temp{#1}%
+ \ifx\pgfmath@temp\pgfmath@empty%
+ \def\pgfmathresult{0}%
+ \else%
+ \pgfmath@in@{#1}{+-+0-0}%
+ \ifpgfmath@in@
+ \def\pgfmathresult{0}%
+ \else%
+ \def\pgfmathresult{#1}%
+ \fi%
+ \fi}
+
+% frac function.
+%
+\pgfmathdeclarefunction{frac}{1}{%
+ \begingroup%
+ \expandafter\pgfmathfrac@@#1.\pgfmath@stop%
+ \pgfmath@smuggleone\pgfmathresult%
+ \endgroup}
+
+\def\pgfmathfrac@@#1.{%
+ \pgfmath@ifnextchar\pgfmath@stop{\def\pgfmathresult{0.0}\pgfmath@gobbleone}{\pgfmathfrac@@@}%
+}
+\def\pgfmathfrac@@@#1.\pgfmath@stop{\def\pgfmathresult{0.#1}}
+
+% real function.
+%
+\pgfmathdeclarefunction{real}{1}{%
+ \begingroup%
+ \pgfmath@x=#1pt\relax%
+ \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}%
+ \pgfmath@smuggleone\pgfmathresult%
+ \endgroup%
+}