summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round.code.tex
blob: 4bd05c18c4127295b2b65876c2ca5adf60adbfb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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%
}