Debian Codegraph @

texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round.code.tex

raw
1 % Copyright 2019 by Mark Wibrow
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10 % This file defines the mathematical functions and operators.
11 %
12 % Version 1.414213 29/9/2007
13
14 % round function. Uses asymmetric half-up rounding.
15 %
16 \pgfmathdeclarefunction{round}{1}{%
17 \begingroup%
18 \expandafter\pgfmath@x#1pt\relax%
19 \afterassignment\pgfmath@xa%
20 \expandafter\c@pgfmath@counta\the\pgfmath@x\relax%
21 \pgfmath@xb\pgfmath@x%
22 \ifdim\pgfmath@xb<0pt\relax%
23 \ifdim\pgfmath@xa<0.5pt\relax%
24 \else%
25 \advance\c@pgfmath@counta-1\relax%
26 \fi%
27 \else%
28 \ifdim\pgfmath@xa<0.5pt\relax%
29 \else%
30 \advance\c@pgfmath@counta1\relax%
31 \fi%
32 \fi%
33 \pgfmath@returnone\the\c@pgfmath@counta pt%
34 \endgroup%
35 }%
36
37 % floor function.
38 %
39 \pgfmathdeclarefunction{floor}{1}{%
40 \begingroup%
41 \expandafter\pgfmath@x#1pt\relax%
42 \afterassignment\pgfmathfloor@collect@remainder%
43 \expandafter\c@pgfmath@counta\the\pgfmath@x\pgfmath@%
44 \expandafter\pgfmath@x#1pt\relax%
45 \ifdim\pgfmath@x<0pt\relax%
46 \ifdim\pgfmathfloor@remainder>0pt
47 \advance\c@pgfmath@counta by -1\relax%
48 \else
49 % ok, we stripped only '0'.
50 \fi
51 \fi%
52 \pgfmath@x\c@pgfmath@counta pt\relax%
53 \pgfmath@returnone\pgfmath@x%
54 \endgroup%
55 }%
56
57 \def\pgfmathfloor@collect@remainder#1\pgfmath@{%
58 \def\pgfmathfloor@remainder{#1}%
59 \ifx\pgfmathfloor@remainder\pgfutil@empty
60 \def\pgfmathfloor@remainder{0}%
61 \fi
62 }%
63
64 % ceil function.
65 %
66 \pgfmathdeclarefunction{ceil}{1}{%
67 \begingroup%
68 \expandafter\pgfmath@x#1pt\relax%
69 \afterassignment\pgfmath@gobbletilpgfmath@%
70 \expandafter\c@pgfmath@counta\the\pgfmath@x\relax\pgfmath@%
71 \pgfmath@y\pgfmath@x%
72 \advance\pgfmath@y-\c@pgfmath@counta pt\relax%
73 \pgfmath@x\c@pgfmath@counta pt\relax%
74 \ifdim\pgfmath@y>0pt\relax%
75 \advance\pgfmath@x1pt\relax%
76 \fi%
77 \pgfmath@returnone\pgfmath@x%
78 \endgroup%
79 }%
80
81 % int function
82 %
83 \pgfmathdeclarefunction{int}{1}{%
84 \begingroup%
85 \expandafter\pgfmathint@@#1.\pgfmath@stop
86 \pgfmath@smuggleone\pgfmathresult%
87 \endgroup}
88
89 \def\pgfmathint@@#1.#2\pgfmath@stop{%
90 \def\pgfmath@temp{#1}%
91 \ifx\pgfmath@temp\pgfmath@empty%
92 \def\pgfmathresult{0}%
93 \else%
94 \pgfmath@in@{#1}{+-+0-0}%
95 \ifpgfmath@in@
96 \def\pgfmathresult{0}%
97 \else%
98 \def\pgfmathresult{#1}%
99 \fi%
100 \fi}
101
102 % frac function.
103 %
104 \pgfmathdeclarefunction{frac}{1}{%
105 \begingroup%
106 \expandafter\pgfmathfrac@@#1.\pgfmath@stop%
107 \pgfmath@smuggleone\pgfmathresult%
108 \endgroup}
109
110 \def\pgfmathfrac@@#1.{%
111 \pgfmath@ifnextchar\pgfmath@stop{\def\pgfmathresult{0.0}\pgfmath@gobbleone}{\pgfmathfrac@@@}%
112 }
113 \def\pgfmathfrac@@@#1.\pgfmath@stop{\def\pgfmathresult{0.#1}}
114
115 % real function.
116 %
117 \pgfmathdeclarefunction{real}{1}{%
118 \begingroup%
119 \pgfmath@x=#1pt\relax%
120 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}%
121 \pgfmath@smuggleone\pgfmathresult%
122 \endgroup%
123 }