| 1 |
% Copyright 2008/2019 by Christian Feuersaenger |
| 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 General Public License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\newif\ifpgfmathfloatparseactive |
| 11 |
\newif\ifpgfmathfloat@scaleactive |
| 12 |
|
| 13 |
% public macro which invokes '#1' if the fpu is installed and ready and '#2' |
| 14 |
% otherwise. |
| 15 |
\def\pgflibraryfpuifactive#1#2{% |
| 16 |
\ifpgfmathfloatparseactive |
| 17 |
#1% |
| 18 |
\else |
| 19 |
#2% |
| 20 |
\fi |
| 21 |
}% |
| 22 |
|
| 23 |
\pgfqkeys{/pgf}{ |
| 24 |
% enable the FPU parser if it is not yet active |
| 25 |
% |
| 26 |
% It will be deactivated after the current TeX group |
| 27 |
fpu/.is choice, |
| 28 |
fpu/true/.code={% |
| 29 |
\ifpgfmathfloatparseactive |
| 30 |
\else |
| 31 |
\pgfutil@ifundefined{pgfmathdeclarefunction}{% |
| 32 |
% Ohoh - we are running on a TeX distribution with |
| 33 |
% PGF 2.00 which doesn't have the new math engine. |
| 34 |
% I can provide special treatment here, provided that |
| 35 |
% all float commands are still able to run (that means |
| 36 |
% more information needs to be copied from the pgf cvs |
| 37 |
% to pgf 2.00 - for example pgfmathfloat.code.tex). |
| 38 |
% |
| 39 |
% I employ this to work with pgfplots and pgf 2.00 |
| 40 |
% using all new features. |
| 41 |
\pgfmathfloat@parser@install@pgf@two@null@null% |
| 42 |
}{% |
| 43 |
\pgfmathfloat@parser@install% |
| 44 |
}% |
| 45 |
\pgfmathfloatparseactivetrue |
| 46 |
% improve compatibility with Marks FP library: |
| 47 |
\pgfkeysalso{/pgf/fixed point arithmetic/.prefix style={/pgf/fpu=false}}% |
| 48 |
\fi |
| 49 |
},% |
| 50 |
fpu/false/.code={% |
| 51 |
\ifpgfmathfloatparseactive |
| 52 |
\pgfmathfloat@uninstall% |
| 53 |
\pgfmathfloatparseactivefalse |
| 54 |
\fi |
| 55 |
},% |
| 56 |
fpu/.default=true, |
| 57 |
% Use this to introduce a result scaling. |
| 58 |
% Every expression in which the prefix '*' occurs |
| 59 |
% will be multiplied with the result and converted to fixed point |
| 60 |
% representation. |
| 61 |
fpu/scale results/.code={% |
| 62 |
\ifpgfmathfloatparseactive |
| 63 |
\pgfmathparse{#1}% |
| 64 |
\else |
| 65 |
\pgfmathfloatparsenumber{#1}% |
| 66 |
\fi |
| 67 |
\let\pgfmathfloatscale=\pgfmathresult% |
| 68 |
},% |
| 69 |
% determines the output format of each complete expression parsing |
| 70 |
% process. If 'scale results' is active, 'fixed' is assumed |
| 71 |
% automatically. |
| 72 |
fpu/output format/.is choice, |
| 73 |
fpu/output format/float/.code= {% |
| 74 |
\def\pgfmathfloatparse@output@choice{Y}% |
| 75 |
\let\pgfmathfloatparse@output=\relax |
| 76 |
}, |
| 77 |
fpu/output format/sci/.code= {% |
| 78 |
\def\pgfmathfloatparse@output@choice{S}% |
| 79 |
\def\pgfmathfloatparse@output{\pgfmathfloattosci@{\pgfmathresult}}% |
| 80 |
}, |
| 81 |
fpu/output format/fixed/.code= {% |
| 82 |
\def\pgfmathfloatparse@output@choice{F}% |
| 83 |
\def\pgfmathfloatparse@output{\pgfmathfloattofixed@{\pgfmathresult}}% |
| 84 |
}, |
| 85 |
fpu/output format/float, |
| 86 |
fpu/rel thresh/.code={% |
| 87 |
\pgfmathfloatparsenumber{#1}% |
| 88 |
\let\pgfmathfloat@relthresh=\pgfmathresult |
| 89 |
}, |
| 90 |
fpu/rel thresh=1e-4, |
| 91 |
fpu/install only/.code={ |
| 92 |
\edef\pgf@list{#1}% |
| 93 |
\pgfutil@for\pgf@temp:=\pgf@list\do{% |
| 94 |
\expandafter\pgfmath@float@install@singlefunction\expandafter{% |
| 95 |
\romannumeral-`0\expandafter\pgfutil@trimspaces\expandafter{\pgf@temp}}% |
| 96 |
}% |
| 97 |
}, |
| 98 |
}% |
| 99 |
|
| 100 |
\pgfmathfloatcreate{1}{1.0}{0}\let\pgfmathfloatscale=\pgfmathresult |
| 101 |
|
| 102 |
\let\pgfmathfloatone=\pgfmathresult |
| 103 |
|
| 104 |
% This is the replacement parser invocation. |
| 105 |
% It does two things which are different to \pgfmathparse: |
| 106 |
% 1. it disables any dimension dependent scalings, |
| 107 |
% 2. it implements the 'scale results' feature. |
| 108 |
\def\pgfmathfloatparse{% |
| 109 |
\begingroup% |
| 110 |
% disable any dimension-dependant scalings: |
| 111 |
\let\pgfmathpostparse=\relax% |
| 112 |
\pgfmath@catcodes% |
| 113 |
\pgfmath@quickparsefalse% |
| 114 |
\ifpgfmathfloatparseactive\else |
| 115 |
\pgfmathfloat@parser@install |
| 116 |
\fi |
| 117 |
\pgfmathfloatparse@}% |
| 118 |
|
| 119 |
% for pgf 2.00 : |
| 120 |
\def\pgfmathfloatparse@pgf@two@null@null{% |
| 121 |
\pgfmath@quickparsefalse% |
| 122 |
\pgfmathfloatparse@}% |
| 123 |
|
| 124 |
\def\pgfmathfloatparse@#1{% |
| 125 |
\edef\pgfmathfloat@expression{#1}% |
| 126 |
\expandafter\pgfmathfloatparse@@\pgfmathfloat@expression\pgfmathfloat@ |
| 127 |
\ifpgfmathfloat@scaleactive |
| 128 |
\expandafter\pgfmathfloatmultiply@\expandafter{\pgfmathresult}{\pgfmathfloatscale}% |
| 129 |
\pgfmathfloattofixed{\pgfmathresult}% |
| 130 |
\else |
| 131 |
\pgfmathfloatparse@output |
| 132 |
\fi |
| 133 |
\ignorespaces |
| 134 |
}% |
| 135 |
|
| 136 |
\def\pgfmathfloat@char@asterisk{*}% |
| 137 |
\def\pgfmathfloatparse@@#1#2\pgfmathfloat@{% |
| 138 |
\def\pgfmathfloat@test{#1}% |
| 139 |
\ifx\pgfmathfloat@test\pgfmathfloat@char@asterisk% |
| 140 |
\def\pgfmathfloat@expression{#2}% |
| 141 |
\pgfmathfloat@scaleactivetrue |
| 142 |
\fi% |
| 143 |
\expandafter\pgfmathparse@\expandafter{\pgfmathfloat@expression}% |
| 144 |
% \endgroup provided by \pgfpathmarse@end |
| 145 |
}% |
| 146 |
|
| 147 |
% Crude handling of file plots |
| 148 |
% |
| 149 |
\pgfkeys{/pgf/fpu/.cd, |
| 150 |
scale file plot x/.code=\pgfmathfloatparse{#1}\edef\pgfmathfloatplotscalex{\pgfmathresult*}, |
| 151 |
scale file plot y/.code=\pgfmathfloatparse{#1}\edef\pgfmathfloatplotscaley{\pgfmathresult*}, |
| 152 |
scale file plot z/.code=\pgfmathfloatparse{#1}\edef\pgfmathfloatplotscalez{\pgfmathresult*} |
| 153 |
}% |
| 154 |
|
| 155 |
\def\pgfmathfloat@uninstall@appendcmd#1{% |
| 156 |
\expandafter\gdef\expandafter\pgfmathfloat@uninstall\expandafter{\pgfmathfloat@uninstall #1}% |
| 157 |
}% |
| 158 |
|
| 159 |
% If the uninstall command is already assembled, it will skip the |
| 160 |
% uninstall assemblation. |
| 161 |
\def\pgfmathfloat@plots@checkuninstallcmd{% |
| 162 |
\pgfutil@ifundefined{pgfmathfloat@uninstall}{% |
| 163 |
\global\let\pgfmathfloat@uninstall=\pgfutil@empty |
| 164 |
}{% |
| 165 |
% We already HAVE an uninstall command (prepared globally). |
| 166 |
% So: don't waste time assembling one! |
| 167 |
\def\pgfmathfloat@uninstall@appendcmd##1{}% |
| 168 |
\def\pgfmathfloat@prepareuninstallcmd##1{}% |
| 169 |
}% |
| 170 |
}% |
| 171 |
|
| 172 |
% This assembles an uninstall command globally ON FIRST USAGE. |
| 173 |
% See \pgfmathfloat@plots@checkuninstallcmd |
| 174 |
\def\pgfmathfloat@prepareuninstallcmd#1{% |
| 175 |
% and store backup information (globally - I don't want to do that |
| 176 |
% all the time when the FPU is used!): |
| 177 |
\expandafter\global\expandafter\let\csname pgfmathfloat@backup@\string#1\endcsname=#1% |
| 178 |
\expandafter\gdef\expandafter\pgfmathfloat@uninstall\expandafter{\pgfmathfloat@uninstall |
| 179 |
\expandafter\let\expandafter#1\csname pgfmathfloat@backup@\string#1\endcsname% |
| 180 |
}% |
| 181 |
}% |
| 182 |
|
| 183 |
\def\pgfmathfloat@install#1=#2{% |
| 184 |
\pgfmathfloat@prepareuninstallcmd{#1}% |
| 185 |
\let#1=#2% |
| 186 |
}% |
| 187 |
\def\pgfmathfloat@install@csname#1#2{% |
| 188 |
\expandafter\pgfmathfloat@prepareuninstallcmd\csname #1\endcsname% |
| 189 |
\pgfutil@namelet{#1}{#2}% |
| 190 |
}% |
| 191 |
\def\pgfmathfloat@install@unimplemented#1{% |
| 192 |
\expandafter\pgfmathfloat@prepareuninstallcmd\csname pgfmath#1@\endcsname% |
| 193 |
\expandafter\def\csname pgfmath#1@\endcsname##1{\pgfmathfloat@notimplemented{#1}}% |
| 194 |
}% |
| 195 |
\def\pgfmathfloat@plots@install{% |
| 196 |
\let\pgfmathfloatplotscalex=\pgfutil@empty |
| 197 |
\let\pgfmathfloatplotscaley=\pgfutil@empty |
| 198 |
\let\pgfmathfloatplotscalez=\pgfutil@empty |
| 199 |
\pgfmathfloat@install\pgf@parsexyline=\pgfmathfloat@parsexyline% |
| 200 |
\pgfmathfloat@install\pgf@parsexyzline=\pgfmathfloat@parsexyzline% |
| 201 |
}% |
| 202 |
\def\pgfmathfloat@parsexyline#1 #2 #3\pgf@stop{% |
| 203 |
\edef\pgfmathfloat@marshal{% |
| 204 |
\noexpand\pgfplotstreampoint{\noexpand\pgfpointxy{\pgfmathfloatplotscalex#1}{\pgfmathfloatplotscaley#2}}% |
| 205 |
}% |
| 206 |
\pgfmathfloat@marshal% |
| 207 |
}% |
| 208 |
\def\pgfmathfloat@parsexyzline#1 #2 #3 #4\pgf@stop{% |
| 209 |
\edef\pgfmathfloat@marshal{% |
| 210 |
\noexpand\pgfplotstreampoint{% |
| 211 |
\noexpand\pgfpointxyz{\pgfmathfloatplotscalex#1}{\pgfmathfloatplotscaley#2}{\pgfmathfloatplotscalez#3}% |
| 212 |
}% |
| 213 |
}% |
| 214 |
\pgfmathfloat@marshal% |
| 215 |
}% |
| 216 |
|
| 217 |
% |
| 218 |
\def\pgfmathfloat@parser@install@functions{% |
| 219 |
% Install float commands... |
| 220 |
% |
| 221 |
\pgfmathfloat@install\pgfmathadd@=\pgfmathfloatadd@% |
| 222 |
\pgfmathfloat@install\pgfmathsubtract@=\pgfmathfloatsubtract@% |
| 223 |
\pgfmathfloat@install\pgfmathneg@=\pgfmathfloatneg@% |
| 224 |
\pgfmathfloat@install\pgfmathmultiply@=\pgfmathfloatmultiply@% |
| 225 |
\pgfmathfloat@install\pgfmathdivide@=\pgfmathfloatdivide@% |
| 226 |
\pgfmathfloat@install\pgfmathabs@=\pgfmathfloatabs@% |
| 227 |
\pgfmathfloat@install\pgfmathsign@=\pgfmathfloatsign@% |
| 228 |
\pgfmathfloat@install\pgfmathround@=\pgfmathfloatround@% |
| 229 |
\pgfmathfloat@install\pgfmathfloor@=\pgfmathfloatfloor@% |
| 230 |
\pgfmathfloat@install\pgfmathceil@=\pgfmathfloatceil@ |
| 231 |
\pgfmathfloat@install\pgfmathint@=\pgfmathfloatint@ |
| 232 |
\pgfmathfloat@install\pgfmathmod@=\pgfmathfloatmod@% |
| 233 |
\pgfmathfloat@install\pgfmathmax@=\pgfmathfloatmax@% |
| 234 |
\pgfmathfloat@install\pgfmathmin@=\pgfmathfloatmin@% |
| 235 |
\pgfmathfloat@install\pgfmathsin@=\pgfmathfloatsin@% |
| 236 |
\pgfmathfloat@install\pgfmathcos@=\pgfmathfloatcos@% |
| 237 |
\pgfmathfloat@install\pgfmathtan@=\pgfmathfloattan@% |
| 238 |
\pgfmathfloat@install\pgfmathdeg@=\pgfmathfloatdeg@% |
| 239 |
\pgfmathfloat@install\pgfmathrad@=\pgfmathfloatrad@% |
| 240 |
\pgfmathfloat@install\pgfmathatan@=\pgfmathfloatatan@% |
| 241 |
\pgfmathfloat@install\pgfmathasin@=\pgfmathfloatasin@% |
| 242 |
\pgfmathfloat@install\pgfmathacos@=\pgfmathfloatacos@% |
| 243 |
\pgfmathfloat@install\pgfmathcot@=\pgfmathfloatcot@% |
| 244 |
\pgfmathfloat@install\pgfmathsec@=\pgfmathfloatsec@% |
| 245 |
\pgfmathfloat@install\pgfmathcosec@=\pgfmathfloatcosec@% |
| 246 |
\pgfmathfloat@install\pgfmathexp@=\pgfmathfloatexp@% |
| 247 |
\pgfmathfloat@install\pgfmathln@=\pgfmathfloatln@% |
| 248 |
\pgfmathfloat@install@csname{pgfmathlog10@}{pgfmathfloatlog10@}% |
| 249 |
\pgfmathfloat@install@csname{pgfmathlog2@}{pgfmathfloatlog2@}% |
| 250 |
\pgfmathfloat@install\pgfmathsqrt@=\pgfmathfloatsqrt@% |
| 251 |
\pgfmathfloat@install\pgfmath@pi=\pgfmathfloatpi@% |
| 252 |
\pgfmathfloat@install\pgfmathpi=\pgfmathfloatpi@% |
| 253 |
\pgfmathfloat@install\pgfmathe@=\pgfmathfloate@% |
| 254 |
\pgfmathfloat@install\pgfmathe=\pgfmathfloate@% |
| 255 |
\pgfmathfloat@install\pgfmathlessthan@=\pgfmathfloatlessthan@% |
| 256 |
\pgfmathfloat@install\pgfmathnotless@=\pgfmathfloatnotless@% |
| 257 |
\pgfmathfloat@install\pgfmathnotgreater@=\pgfmathfloatnotgreater@% |
| 258 |
\pgfmathfloat@install\pgfmathless@=\pgfmathfloatlessthan@% |
| 259 |
\pgfmathfloat@install\pgfmathgreaterthan@=\pgfmathfloatgreaterthan@% |
| 260 |
\pgfmathfloat@install\pgfmathgreater@=\pgfmathfloatgreaterthan@% |
| 261 |
\pgfmathfloat@install\pgfmathifthenelse@=\pgfmathfloatifthenelse@% |
| 262 |
\pgfmathfloat@install\pgfmathequal@=\pgfmathfloatequal@% |
| 263 |
\pgfmathfloat@install\pgfmathequalto@=\pgfmathfloatequal@% |
| 264 |
\pgfmathfloat@install\pgfmathnotequal@=\pgfmathfloatnotequal@% |
| 265 |
\pgfmathfloat@install\pgfmathnotequalto@=\pgfmathfloatnotequal@% |
| 266 |
\pgfmathfloat@install\pgfmathpow@=\pgfmathfloatpow@ |
| 267 |
\pgfmathfloat@install\pgfmathrand@=\pgfmathfloatrand@ |
| 268 |
\pgfmathfloat@install\pgfmathrand=\pgfmathfloatrand@ |
| 269 |
\pgfmathfloat@install\pgfmathrnd@=\pgfmathfloatrnd@ |
| 270 |
\pgfmathfloat@install\pgfmathrnd=\pgfmathfloatrnd@ |
| 271 |
\pgfmathfloat@install\pgfmathtrue@=\pgfmathfloattrue@ |
| 272 |
\pgfmathfloat@install\pgfmathfalse@=\pgfmathfloatfalse@ |
| 273 |
\pgfmathfloat@install\pgfmathnot@=\pgfmathfloatnot@ |
| 274 |
\pgfmathfloat@install\pgfmathhex@=\pgfmathfloathex@ |
| 275 |
\pgfmathfloat@install\pgfmathHex@=\pgfmathfloatHex@ |
| 276 |
\pgfmathfloat@install\pgfmathoct@=\pgfmathfloatoct@ |
| 277 |
\pgfmathfloat@install\pgfmathbin@=\pgfmathfloatbin@ |
| 278 |
\pgfmathfloat@install\pgfmathand@=\pgfmathfloatand@ |
| 279 |
\pgfmathfloat@install\pgfmathor@=\pgfmathfloator@ |
| 280 |
\pgfmathfloat@install\pgfmathfactorial@=\pgfmathfloatfactorial@ |
| 281 |
\pgfmathfloat@install\pgfmathveclen@=\pgfmathfloatveclen@ |
| 282 |
\pgfmathfloat@install\pgfmathcosh@=\pgfmathfloatcosh@ |
| 283 |
\pgfmathfloat@install\pgfmathsinh@=\pgfmathfloatsinh@ |
| 284 |
\pgfmathfloat@install\pgfmathtanh@=\pgfmathfloattanh@ |
| 285 |
\pgfmathfloat@install\pgfmath@iftrue=\pgfmathfloat@iftrue% |
| 286 |
\expandafter\pgfmathfloat@install\csname pgfmathatan2@\endcsname=\pgfmathfloatatantwo@ |
| 287 |
\pgfmathfloat@install@unimplemented{isprime}% |
| 288 |
\pgfmathfloat@install@unimplemented{iseven}% |
| 289 |
\pgfmathfloat@install@unimplemented{isodd}% |
| 290 |
\pgfmathfloat@install@unimplemented{gcd}% |
| 291 |
\pgfmathfloat@install@unimplemented{frac}% |
| 292 |
\pgfmathfloat@install@unimplemented{random}% |
| 293 |
\pgfmathfloat@install@unimplemented{setseed}% |
| 294 |
\pgfmathfloat@install@unimplemented{Mod}% |
| 295 |
\pgfmathfloat@install@unimplemented{div}% |
| 296 |
\pgfmathfloat@install@unimplemented{real}% |
| 297 |
% \pgfmathfloat@install@unimplemented{height}% |
| 298 |
% |
| 299 |
% |
| 300 |
\pgfmathfloat@install\pgfmathscientific=\pgfmathfloatscientific% |
| 301 |
}% |
| 302 |
|
| 303 |
\def\pgfmath@float@install@singlefunction#1{% |
| 304 |
\ifcsname pgfmath@function@#1\endcsname\else |
| 305 |
\pgfmath@error{The function `#1' does not exist}{}% |
| 306 |
\fi |
| 307 |
\pgfmath@toks={}% |
| 308 |
\pgfmathloop |
| 309 |
\ifnum\pgfmathcounter>\csname pgfmath@operation@#1@arity\endcsname\relax% |
| 310 |
\else |
| 311 |
\expandafter\pgfmath@addto@toks\expandafter{\pgfmath@char@hash}% |
| 312 |
\expandafter\pgfmath@addto@toks\expandafter{\pgfmathcounter}% |
| 313 |
\repeatpgfmathloop |
| 314 |
\edef\pgfmath@head{\noexpand\def\expandafter\noexpand\csname pgfmath#1@\endcsname\the\pgfmath@toks}% |
| 315 |
\pgfmath@toks={}% |
| 316 |
\def\pgfmath@arguments{}% |
| 317 |
\pgfmathloop |
| 318 |
\ifnum\pgfmathcounter>\csname pgfmath@operation@#1@arity\endcsname\relax% |
| 319 |
\else |
| 320 |
\pgfmath@addto@toks{\pgfmathfloatparsenumber}% |
| 321 |
\expandafter\expandafter\expandafter\pgfmath@addto@toks |
| 322 |
\expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter |
| 323 |
{\expandafter\pgfmath@char@hash\pgfmathcounter}}% |
| 324 |
\pgfmath@addto@toks{\let}% |
| 325 |
\expandafter\pgfmath@addto@toks\expandafter{% |
| 326 |
\csname pgfmath@argument@\pgfmathcounter\endcsname=\pgfmathresult}% |
| 327 |
\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter |
| 328 |
\pgfmath@arguments\expandafter\expandafter\expandafter{\expandafter |
| 329 |
\pgfmath@arguments\expandafter{\csname pgfmath@argument@\pgfmathcounter\endcsname}}% |
| 330 |
\repeatpgfmathloop |
| 331 |
\expandafter\pgfmath@addto@toks\expandafter{\csname pgfmathfloat#1@\expandafter\endcsname\pgfmath@arguments}% |
| 332 |
\pgfmath@addto@toks{\pgfmathfloattofixed{\pgfmathresult}}% |
| 333 |
\edef\pgfmath@body{{\the\pgfmath@toks}}% |
| 334 |
\expandafter\pgfmath@head\pgfmath@body |
| 335 |
} |
| 336 |
|
| 337 |
\def\pgfmathfloat@iftrue{% |
| 338 |
\if Y\pgfmathfloatparse@output@choice |
| 339 |
\let\pgfmathfloat@@iftrue@v=\pgfmathfloatone |
| 340 |
\let\pgfmathfloat@@iftrue@next=\pgfmathfloat@iftrue@ |
| 341 |
\else |
| 342 |
\if S\pgfmathfloatparse@output@choice |
| 343 |
\def\pgfmathfloat@@iftrue@v{1.0e0}% |
| 344 |
\let\pgfmathfloat@@iftrue@next=\pgfmathfloat@iftrue@ |
| 345 |
\else |
| 346 |
\def\pgfmath@next{\pgfutilifstartswith{1.0}}% |
| 347 |
\expandafter\pgfmath@next\expandafter{\pgfmathresult}{% |
| 348 |
\ifdim\pgfmathresult pt=1.0pt % |
| 349 |
\let\pgfmathfloat@@iftrue@next=\pgfutil@firstoftwo |
| 350 |
\else |
| 351 |
\let\pgfmathfloat@@iftrue@next=\pgfutil@secondoftwo |
| 352 |
\fi |
| 353 |
}{% |
| 354 |
\let\pgfmathfloat@@iftrue@next=\pgfutil@secondoftwo |
| 355 |
}% |
| 356 |
\fi |
| 357 |
\fi |
| 358 |
\pgfmathfloat@@iftrue@next% |
| 359 |
}% |
| 360 |
\def\pgfmathfloat@iftrue@{% |
| 361 |
\ifx\pgfmathresult\pgfmathfloat@@iftrue@v |
| 362 |
\let\pgfmath@next=\pgfutil@firstoftwo |
| 363 |
\else |
| 364 |
\let\pgfmath@next=\pgfutil@secondoftwo |
| 365 |
\fi |
| 366 |
\pgfmath@next% |
| 367 |
}% |
| 368 |
|
| 369 |
\def\pgfmathfloat@parser@install{% |
| 370 |
\pgfmathfloat@plots@checkuninstallcmd |
| 371 |
\pgfmathfloat@plots@install% |
| 372 |
\pgfmathfloat@parser@install@functions |
| 373 |
% |
| 374 |
% |
| 375 |
% |
| 376 |
% The following methods actually enable the parser to work with |
| 377 |
% the internal floating point number representation. |
| 378 |
% |
| 379 |
% The idea is as follows: |
| 380 |
% 1. Every operand must be given in internal float representation. |
| 381 |
% 2. The internal float repr can be distinguished by a normal |
| 382 |
% number. This is accomplished by introducing a new "exponent" |
| 383 |
% token. |
| 384 |
% 3. The stack-push-operation checks whether the argument is a |
| 385 |
% float. If not, it is parsed properly before pushing it. |
| 386 |
\pgfmath@tokens@make{exponent}{\pgfmathfloat@POSTFLAGSCHAR}% |
| 387 |
\pgfmathfloat@uninstall@appendcmd{% |
| 388 |
\expandafter\let\csname pgfmath@token@exponent@\pgfmathfloat@POSTFLAGSCHAR\endcsname=\relax |
| 389 |
}% |
| 390 |
\let\pgfmath@basic@parse@exponent=\pgfmath@parse@exponent% |
| 391 |
\let\pgfmath@basic@stack@push@operand=\pgfmath@stack@push@operand |
| 392 |
\pgfmathfloat@install\pgfmath@stack@push@operand=\pgfmathfloat@stack@push@operand |
| 393 |
\pgfmathfloat@install\pgfmath@parse@operand@quote=\pgfmathfloat@parse@operand@quote |
| 394 |
\pgfmathfloat@install\pgfmath@parse@exponent=\pgfmathfloat@parse@float@or@exponent |
| 395 |
% |
| 396 |
\pgfmathfloat@install\pgfmathparse=\pgfmathfloatparse% |
| 397 |
%\pgfmathfloat@install\pgfmathparse@trynumber@token=\pgfmathfloat@parse@trynumber@token |
| 398 |
\pgfmathfloat@install\pgfmathparse@expression@is@number=\pgfmathfloat@parse@expression@is@number |
| 399 |
}% |
| 400 |
|
| 401 |
% This here might bring speed improvements... if implemented |
| 402 |
% correctly. |
| 403 |
% However, this heuristics might fail in cases like "1+1" vs "1e+1" ... |
| 404 |
%\def\pgfmathfloat@parse@trynumber@token{numericfpu} |
| 405 |
%\pgfmath@tokens@make{numericfpu}{eE+-Y.0123456789} |
| 406 |
|
| 407 |
\def\pgfmathfloat@parse@expression@is@number{% |
| 408 |
\pgfmathfloatparsenumber{\pgfmath@expression}% |
| 409 |
\pgfmath@smuggleone\pgfmathresult% |
| 410 |
\endgroup |
| 411 |
\ignorespaces |
| 412 |
}% |
| 413 |
|
| 414 |
\def\pgfmathfloat@defineadapter@for@pgf@two@null@null@ONEARG#1{% |
| 415 |
\edef\pgfmathfloat@loc@TMPa{% |
| 416 |
\noexpand\def\expandafter\noexpand\csname pgfmath@parsefunction@#1\endcsname{% |
| 417 |
\noexpand\let\noexpand\pgfmath@parsepostgroup\expandafter\noexpand\csname pgfmath@parsefunction@#1@\endcsname% |
| 418 |
\noexpand\expandafter\noexpand\pgfmath@parse@}% |
| 419 |
\noexpand\def\expandafter\noexpand\csname pgfmath@parsefunction@#1@\endcsname{% |
| 420 |
\noexpand\expandafter\expandafter\noexpand\csname pgfmath#1@\endcsname\noexpand\expandafter{\noexpand\pgfmathresult}% |
| 421 |
\noexpand\pgfmath@postfunction% |
| 422 |
}% |
| 423 |
}% |
| 424 |
\pgfmathfloat@loc@TMPa |
| 425 |
}% |
| 426 |
\def\pgfmathfloat@parser@install@pgf@two@null@null{% |
| 427 |
\pgfmathfloat@plots@checkuninstallcmd |
| 428 |
\pgfmathfloat@plots@install% |
| 429 |
\pgfmathfloat@parser@install@functions |
| 430 |
\let\pgfmathrand@=\pgfmath@basic@rand@ |
| 431 |
\let\pgfmathrnd@=\pgfmath@basic@rnd@ |
| 432 |
\pgfmathfloat@install\pgfmathmax@=\pgfmathfloatmaxtwo% |
| 433 |
\pgfmathfloat@install\pgfmathmin@=\pgfmathfloatmintwo% |
| 434 |
\pgfmathfloat@defineadapter@for@pgf@two@null@null@ONEARG{factorial}% |
| 435 |
\pgfmathfloat@defineadapter@for@pgf@two@null@null@ONEARG{hex}% |
| 436 |
\pgfmathfloat@defineadapter@for@pgf@two@null@null@ONEARG{bin}% |
| 437 |
\pgfmathfloat@defineadapter@for@pgf@two@null@null@ONEARG{oct}% |
| 438 |
\pgfmathfloat@defineadapter@for@pgf@two@null@null@ONEARG{tanh}% |
| 439 |
\pgfmathfloat@defineadapter@for@pgf@two@null@null@ONEARG{sinh}% |
| 440 |
\pgfmathfloat@defineadapter@for@pgf@two@null@null@ONEARG{cosh}% |
| 441 |
% |
| 442 |
% The following methods actually enable the parser to work with |
| 443 |
% the internal floating point number representation. |
| 444 |
% |
| 445 |
% The idea is as follows: |
| 446 |
% 1. Every operand must be given in internal float representation. |
| 447 |
% 2. The internal float repr can be distinguished by a normal |
| 448 |
% number. This is accomplished by introducing a new "exponent" |
| 449 |
% token. |
| 450 |
% 3. The stack-push-operation checks whether the argument is a |
| 451 |
% float. If not, it is parsed properly before pushing it. |
| 452 |
\let\pgfmath@basic@parsedecimalpoint=\pgfmath@parsedecimalpoint% |
| 453 |
\let\pgfmath@basic@stack@push@operand=\pgfmath@stackpushoperand |
| 454 |
\pgfmathfloat@install\pgfmath@stackpushoperand=\pgfmathfloat@stack@push@operand |
| 455 |
\pgfmathfloat@install\pgfmath@parsedecimalpoint=\pgfmathfloat@parsedecimalpoint@pgf@two@null@null |
| 456 |
\pgfmathfloat@install\pgfmath@endparse=\pgfmathfloat@endparse@pgf@two@null@null |
| 457 |
\pgfmathfloat@install\pgfmath@endparsegroup=\pgfmathfloat@endparsegroup@pgf@two@null@null |
| 458 |
\pgfmathfloat@install\pgfmath@postfunction=\pgfmathfloat@postfunction@pgf@two@null@null |
| 459 |
\pgfmathfloat@install\pgfmath@@parseoperandgroup=\pgfmathfloat@@parseoperandgroup |
| 460 |
% |
| 461 |
\pgfmathfloat@install\pgfmathparse=\pgfmathfloatparse@pgf@two@null@null% |
| 462 |
}% |
| 463 |
|
| 464 |
\pgfutil@ifundefined{pgfmathdeclarefunction}{% |
| 465 |
% BACKWARDS COMPATIBILITY: We have PGF 2.00 : |
| 466 |
\def\pgfmathdeclarepseudoconstant#1#2{% |
| 467 |
\begingroup |
| 468 |
\toks0=\expandafter{\csname pgfmath#1@\endcsname}% |
| 469 |
\toks1={\pgfmath@postfunction}% |
| 470 |
\xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }% |
| 471 |
\xdef\pgfmathfloat@glob@TMPb{\the\toks0 }% |
| 472 |
\endgroup |
| 473 |
\expandafter\let\csname pgfmath@parsefunction@#1\endcsname=\pgfmathfloat@glob@TMP |
| 474 |
\expandafter\let\csname pgfmath#1\endcsname=\pgfmathfloat@glob@TMPb |
| 475 |
\expandafter\def\csname pgfmath#1@\endcsname{#2}% |
| 476 |
}% |
| 477 |
\let\pgfmathredeclarepseudoconstant=\pgfmathdeclarepseudoconstant |
| 478 |
}{% |
| 479 |
\pgfutil@ifundefined{pgfmathdeclarepseudoconstant}{% |
| 480 |
\def\pgfmathdeclarepseudoconstant#1#2{\pgfmathdeclarefunction*{#1}{0}{#2}} |
| 481 |
}{}% |
| 482 |
}% |
| 483 |
|
| 484 |
\pgfmathdeclarepseudoconstant{inf}{\def\pgfmathresult{inf}}% |
| 485 |
\pgfmathdeclarepseudoconstant{INF}{\def\pgfmathresult{inf}}% |
| 486 |
\pgfmathdeclarepseudoconstant{Inf}{\def\pgfmathresult{inf}}% |
| 487 |
\pgfmathdeclarepseudoconstant{infty}{\def\pgfmathresult{inf}}% |
| 488 |
\pgfmathdeclarepseudoconstant{nan}{\def\pgfmathresult{nan}}% |
| 489 |
\pgfmathdeclarepseudoconstant{NaN}{\def\pgfmathresult{nan}}% |
| 490 |
|
| 491 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 492 |
% |
| 493 |
% Hacks to the basic level pgf math engine: |
| 494 |
% |
| 495 |
% WARNING: These methods rely heavily on the internal float representation! |
| 496 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 497 |
|
| 498 |
% for pgf2.00 : |
| 499 |
\def\pgfmathfloat@parsedecimalpoint@pgf@two@null@null#1{% |
| 500 |
\expandafter\ifx\pgfmathfloat@POSTFLAGSCHAR#1% check whether it is a float |
| 501 |
\let\pgfmath@next=\pgfmathfloat@return@float@pgf@two@null@null% |
| 502 |
\else |
| 503 |
\def\pgfmath@next{\pgfmath@basic@parsedecimalpoint#1}% |
| 504 |
\fi |
| 505 |
\pgfmath@next |
| 506 |
}% |
| 507 |
% for pgf2.00: |
| 508 |
\def\pgfmathfloat@return@float@pgf@two@null@null#1]{% |
| 509 |
\edef\pgfmathresult{\the\c@pgfmath@parsecounta\pgfmathfloat@POSTFLAGSCHAR#1]}% |
| 510 |
\let\pgfmath@resulttemp=\pgfmathresult |
| 511 |
\pgfmath@parseoperator% |
| 512 |
}% |
| 513 |
% for pgf2.00: |
| 514 |
\def\pgfmathfloat@endparse@pgf@two@null@null#1\pgfmath@empty{% |
| 515 |
\pgfmath@processalloperations% |
| 516 |
\pgfmath@stackpop{\pgfmathresult}% |
| 517 |
% delete the final unit scalings |
| 518 |
\pgfmath@smuggleone{\pgfmathresult}% |
| 519 |
\endgroup% |
| 520 |
\ignorespaces% |
| 521 |
}% |
| 522 |
% for pgf2.00: |
| 523 |
\def\pgfmathfloat@endparsegroup@pgf@two@null@null{% |
| 524 |
\pgfmath@processalloperations% |
| 525 |
\pgfmath@stackpop{\pgfmathresult}% |
| 526 |
% eliminated register usage here... |
| 527 |
\pgfmath@smuggleone{\pgfmathresult}% |
| 528 |
\endgroup% |
| 529 |
\pgfmath@parsepostgroup% |
| 530 |
}% |
| 531 |
% for pgf2.00: |
| 532 |
\def\pgfmathfloat@postfunction@pgf@two@null@null{% |
| 533 |
\let\pgfmath@parsepostgroup\pgfmath@parseoperator% |
| 534 |
\ifnum\pgfmath@sign1<0 |
| 535 |
\pgfmathfloatneg@{\pgfmathresult}% |
| 536 |
\let\pgfmath@sign\pgfutil@empty |
| 537 |
\fi |
| 538 |
\pgfmath@parseoperator}% |
| 539 |
% for pgf2.00: |
| 540 |
\def\pgfmathfloat@@parseoperandgroup{% |
| 541 |
\let\pgfmath@postparsegroup\pgfmath@parseoperator% |
| 542 |
\ifnum\pgfmath@sign1<0 |
| 543 |
\pgfmathfloatneg@{\pgfmathresult}% |
| 544 |
\let\pgfmath@sign\pgfutil@empty |
| 545 |
\fi |
| 546 |
\pgfmath@parseoperator% |
| 547 |
}% |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
% PRECONDITION: |
| 555 |
% either |
| 556 |
% <number>e |
| 557 |
% ^ |
| 558 |
% -> read the exponent. |
| 559 |
% or |
| 560 |
% <sign>\pgfmathfloat@POSTFLAGSCHAR |
| 561 |
% ^ |
| 562 |
% -> we have a parsed floating point number -> read it. |
| 563 |
\def\pgfmathfloat@parse@float@or@exponent{% |
| 564 |
\if\pgfmath@token \pgfmathfloat@POSTFLAGSCHAR% |
| 565 |
% Ok, we actually HAVE a pre-parsed floating point number! |
| 566 |
% Return it. |
| 567 |
\expandafter\pgfmathfloat@return@float\expandafter\pgfmath@token@next |
| 568 |
\else |
| 569 |
% We have a standard number in scientific format. Parse it. |
| 570 |
\expandafter\pgfmath@basic@parse@exponent |
| 571 |
\fi |
| 572 |
}% |
| 573 |
\def\pgfmathfloat@return@float#1]{% |
| 574 |
\edef\pgfmathresult{\pgfmath@number \pgfmathfloat@POSTFLAGSCHAR#1]}% |
| 575 |
\expandafter\pgfmath@basic@stack@push@operand\expandafter{\pgfmathresult}% |
| 576 |
\pgfmath@parse@@operator% |
| 577 |
}% |
| 578 |
|
| 579 |
\def\pgfmathfloat@parse@operand@quote#1"{% |
| 580 |
\edef\pgfmathresult{\pgfmath@fpu@stringmarker #1}% |
| 581 |
\expandafter\pgfmath@basic@stack@push@operand\expandafter{\pgfmathresult}% |
| 582 |
\pgfmath@parse@@operator% |
| 583 |
} |
| 584 |
|
| 585 |
\def\pgfmath@fpu@stringmarker{@@str@@:}% |
| 586 |
|
| 587 |
% This extends the functionality of the basic level operand stack: it |
| 588 |
% assures every element on the stack is a float. |
| 589 |
\def\pgfmathfloat@stack@push@operand#1{% |
| 590 |
\pgfutil@ifnextchar\bgroup{% |
| 591 |
\let\pgfmathfloat@stack@push@operand@list@=\pgfutil@empty |
| 592 |
\pgfmathfloat@stack@push@operand@list |
| 593 |
}{% |
| 594 |
\pgfmathfloat@stack@push@operand@single |
| 595 |
}% |
| 596 |
#1\relax |
| 597 |
}% |
| 598 |
|
| 599 |
\def\pgfmathfloat@stack@push@operand@single#1\relax{% |
| 600 |
\expandafter\pgfutil@in@\pgfmathfloat@POSTFLAGSCHAR{#1}% |
| 601 |
\ifpgfutil@in@ |
| 602 |
\pgfmath@basic@stack@push@operand{#1}% |
| 603 |
\else |
| 604 |
\expandafter\pgfutil@in@\expandafter{\pgfmath@fpu@stringmarker}{#1}% |
| 605 |
\ifpgfutil@in@ |
| 606 |
\pgfmathfloat@stack@push@operand@single@str#1\relax |
| 607 |
\else |
| 608 |
\pgfmathfloatparsenumber{#1}% |
| 609 |
\expandafter\pgfmath@basic@stack@push@operand\expandafter{\pgfmathresult}% |
| 610 |
\fi |
| 611 |
\fi |
| 612 |
}% |
| 613 |
|
| 614 |
\expandafter\def\expandafter\pgfmathfloat@stack@push@operand@single@str\pgfmath@fpu@stringmarker #1\relax{% |
| 615 |
\pgfmath@basic@stack@push@operand{#1}% |
| 616 |
}% |
| 617 |
|
| 618 |
\def\pgfmathfloat@stack@push@operand@GOBBLE#1\relax{}% |
| 619 |
\def\pgfmathfloat@stack@push@operand@list#1{% |
| 620 |
\expandafter\pgfutil@in@ \pgfmathfloat@POSTFLAGSCHAR{#1}% |
| 621 |
\ifpgfutil@in@ |
| 622 |
\expandafter\def\expandafter\pgfmathfloat@stack@push@operand@list@\expandafter{% |
| 623 |
\pgfmathfloat@stack@push@operand@list@{#1}% |
| 624 |
}% |
| 625 |
\else |
| 626 |
\pgfmathfloatparsenumber{#1}% |
| 627 |
\begingroup |
| 628 |
\toks0=\expandafter{\pgfmathfloat@stack@push@operand@list@}% |
| 629 |
\toks1=\expandafter{\pgfmathresult}% |
| 630 |
\xdef\pgfmathfloat@glob@TMP{\the\toks0 {\the\toks1}}% |
| 631 |
\endgroup |
| 632 |
\let\pgfmathfloat@stack@push@operand@list@=\pgfmathfloat@glob@TMP |
| 633 |
\fi |
| 634 |
\pgfutil@ifnextchar\relax{% |
| 635 |
\expandafter\pgfmath@basic@stack@push@operand\expandafter{\pgfmathfloat@stack@push@operand@list@}% |
| 636 |
\pgfmathfloat@stack@push@operand@GOBBLE |
| 637 |
}{% |
| 638 |
\pgfmathfloat@stack@push@operand@list |
| 639 |
}% |
| 640 |
}% |
| 641 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 642 |
% |
| 643 |
% --- END --- Hacks to the basic level pgf math engine |
| 644 |
% |
| 645 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 650 |
% |
| 651 |
% Here starts the implementation of the floating point |
| 652 |
% routines. |
| 653 |
% |
| 654 |
% They can be used even if the FPU parser is not active. |
| 655 |
% |
| 656 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 657 |
|
| 658 |
% Remember the basic math commands. They will be invoked as subroutines in floating point routines. |
| 659 |
\let\pgfmath@basic@add@=\pgfmathadd@ |
| 660 |
\let\pgfmath@basic@subtract@=\pgfmathsubtract@ |
| 661 |
\let\pgfmath@basic@multiply@=\pgfmathmultiply@ |
| 662 |
\let\pgfmath@basic@divide@=\pgfmathdivide@ |
| 663 |
\let\pgfmath@basic@reciprocal@=\pgfmathreciprocal@ |
| 664 |
\let\pgfmath@basic@abs@=\pgfmathabs@ |
| 665 |
\let\pgfmath@basic@round@=\pgfmathround@ |
| 666 |
\let\pgfmath@basic@rand@=\pgfmathrand@ |
| 667 |
\let\pgfmath@basic@rnd@=\pgfmathrnd@ |
| 668 |
\let\pgfmath@basic@setseed@=\pgfmathsetseed@ |
| 669 |
\let\pgfmath@basic@random@=\pgfmathrandom@ |
| 670 |
\let\pgfmath@basic@floor@=\pgfmathfloor@ |
| 671 |
\let\pgfmath@basic@ceil@=\pgfmathceil@ |
| 672 |
\let\pgfmath@basic@mod@=\pgfmathmod@ |
| 673 |
\let\pgfmath@basic@max@=\pgfmathmax@ |
| 674 |
\let\pgfmath@basic@min@=\pgfmathmin@ |
| 675 |
\let\pgfmath@basic@sin@=\pgfmathsin@ |
| 676 |
\let\pgfmath@basic@cos@=\pgfmathcos@ |
| 677 |
\let\pgfmath@basic@tan@=\pgfmathtan@ |
| 678 |
\let\pgfmath@basic@deg@=\pgfmathdeg@ |
| 679 |
\let\pgfmath@basic@rad@=\pgfmathrad@ |
| 680 |
\let\pgfmath@basic@atan@=\pgfmathatan@ |
| 681 |
\let\pgfmath@basic@asin@=\pgfmathasin@ |
| 682 |
\let\pgfmath@basic@acos@=\pgfmathacos@ |
| 683 |
\let\pgfmath@basic@cot@=\pgfmathcot@ |
| 684 |
\let\pgfmath@basic@sec@=\pgfmathsec@ |
| 685 |
\let\pgfmath@basic@cosec@=\pgfmathcosec@ |
| 686 |
\let\pgfmath@basic@pow@=\pgfmathpow@ |
| 687 |
\let\pgfmath@basic@exp@=\pgfmathexp@ |
| 688 |
\let\pgfmath@basic@ln@=\pgfmathln@ |
| 689 |
\let\pgfmath@basic@sqrt@=\pgfmathsqrt@ |
| 690 |
\let\pgfmath@basic@@pi=\pgfmath@pi |
| 691 |
\let\pgfmath@basic@veclen@=\pgfmathveclen@ |
| 692 |
\let\pgfmath@basic@e@=\pgfmathe@ |
| 693 |
\let\pgfmath@basic@lessthan@=\pgfmathlessthan@ |
| 694 |
\let\pgfmath@basic@greaterthan@=\pgfmathgreaterthan@ |
| 695 |
\let\pgfmath@basic@equalto@=\pgfmathequalto@ |
| 696 |
\let\pgfmath@basic@equal@=\pgfmathequal@ |
| 697 |
\let\pgfmath@basic@true@=\pgfmathtrue@ |
| 698 |
\let\pgfmath@basic@false@=\pgfmathfalse@ |
| 699 |
|
| 700 |
\def\pgfmathfloatscientific#1#2{% |
| 701 |
\edef\pgfmathresult{#1e#2}% |
| 702 |
\expandafter\pgfmathfloatparsenumber\expandafter{\pgfmathresult}% |
| 703 |
}% |
| 704 |
% Compares #1 with #2 and sets \pgfmathresult either to 1.0 or 0.0. |
| 705 |
% |
| 706 |
% It also sets the boolean \ifpgfmathfloatcomparison (globally). |
| 707 |
\def\pgfmathfloatlessthan@#1#2{% |
| 708 |
%\def\pgfmathfloatlessthan#1#2#3\and#4#5#6{% |
| 709 |
\global\pgfmathfloatcomparisonfalse |
| 710 |
\begingroup |
| 711 |
\edef\pgfmathfloat@loc@TMPa{#1}% |
| 712 |
\edef\pgfmathfloat@loc@TMPb{#2}% |
| 713 |
\expandafter\pgfmathfloat@decompose\pgfmathfloat@loc@TMPa\relax\pgfmathfloat@a@S\pgfmathfloat@a@M\pgfmathfloat@a@E |
| 714 |
\expandafter\pgfmathfloat@decompose\pgfmathfloat@loc@TMPb\relax\pgfmathfloat@b@S\pgfmathfloat@b@M\pgfmathfloat@b@E |
| 715 |
\ifcase\pgfmathfloat@a@S |
| 716 |
% x = 0 -> (x<y <=> y >0) |
| 717 |
\ifcase\pgfmathfloat@b@S |
| 718 |
% y = 0 |
| 719 |
\or% y > 0 |
| 720 |
\global\pgfmathfloatcomparisontrue |
| 721 |
\or% y < 0 |
| 722 |
\or% y = nan |
| 723 |
\or% y = + infty |
| 724 |
\global\pgfmathfloatcomparisontrue |
| 725 |
\or% y = -infty |
| 726 |
\fi |
| 727 |
\or |
| 728 |
% x > 0 -> (x<y <=> ( y > 0 && |x| < |y|) ) |
| 729 |
\ifcase\pgfmathfloat@b@S |
| 730 |
% y = 0 |
| 731 |
\or% y>0: |
| 732 |
\pgfmathfloatlessthan@positive |
| 733 |
\or% y < 0 |
| 734 |
\or% y = nan |
| 735 |
\or% y = + infty |
| 736 |
\global\pgfmathfloatcomparisontrue |
| 737 |
\or% y = -infty |
| 738 |
\fi |
| 739 |
\or |
| 740 |
% x < 0 -> (x<y <=> (y >= 0 || |x| > |y|) ) |
| 741 |
\ifcase\pgfmathfloat@b@S |
| 742 |
% y = 0 |
| 743 |
\global\pgfmathfloatcomparisontrue |
| 744 |
\or%y > 0 |
| 745 |
\global\pgfmathfloatcomparisontrue |
| 746 |
\or% 'y<0': |
| 747 |
\pgfmathfloatgreaterthan@positive |
| 748 |
\or% y = nan |
| 749 |
\or% y = + infty |
| 750 |
\global\pgfmathfloatcomparisontrue |
| 751 |
\or% y = -infty |
| 752 |
\fi |
| 753 |
\or |
| 754 |
% x = nan. |
| 755 |
\or |
| 756 |
% x = +infty |
| 757 |
\or |
| 758 |
% x = -infty |
| 759 |
\ifnum\pgfmathfloat@b@S=3 |
| 760 |
\else |
| 761 |
\global\pgfmathfloatcomparisontrue |
| 762 |
\fi |
| 763 |
\fi |
| 764 |
\endgroup |
| 765 |
\ifpgfmathfloatcomparison |
| 766 |
\def\pgfmathresult{1.0}% |
| 767 |
\else |
| 768 |
\def\pgfmathresult{0.0}% |
| 769 |
\fi |
| 770 |
}% |
| 771 |
\let\pgfmathfloatlessthan=\pgfmathfloatlessthan@ |
| 772 |
\let\pgfmathfloatless@=\pgfmathfloatlessthan@ |
| 773 |
|
| 774 |
% ! (#1 < #2) <=> (#1 >= #2) |
| 775 |
\def\pgfmathfloatnotless@#1#2{% |
| 776 |
\pgfmathfloatless@{#1}{#2}% |
| 777 |
\ifpgfmathfloatcomparison |
| 778 |
\def\pgfmathresult{0.0}% |
| 779 |
\else |
| 780 |
\def\pgfmathresult{1.0}% |
| 781 |
\fi |
| 782 |
}% |
| 783 |
% ! (#1 > #2) <=> (#1 <= #2) |
| 784 |
\def\pgfmathfloatnotgreater@#1#2{% |
| 785 |
\pgfmathfloatless@{#2}{#1}% |
| 786 |
\ifpgfmathfloatcomparison |
| 787 |
\def\pgfmathresult{0.0}% |
| 788 |
\else |
| 789 |
\def\pgfmathresult{1.0}% |
| 790 |
\fi |
| 791 |
}% |
| 792 |
|
| 793 |
% compares \pgfmathfloat@a@[SME] < \pgfmathfloat@b@[SME] |
| 794 |
\def\pgfmathfloatlessthan@positive{% |
| 795 |
\ifnum\pgfmathfloat@a@E<\pgfmathfloat@b@E |
| 796 |
\global\pgfmathfloatcomparisontrue |
| 797 |
\else |
| 798 |
\ifnum\pgfmathfloat@a@E=\pgfmathfloat@b@E |
| 799 |
\ifdim\pgfmathfloat@a@M<\pgfmathfloat@b@M |
| 800 |
\global\pgfmathfloatcomparisontrue |
| 801 |
\fi |
| 802 |
\fi |
| 803 |
\fi |
| 804 |
}% |
| 805 |
|
| 806 |
% compares \pgfmathfloat@a@[SME] > \pgfmathfloat@b@[SME] |
| 807 |
\def\pgfmathfloatgreaterthan@positive{% |
| 808 |
\ifnum\pgfmathfloat@a@E>\pgfmathfloat@b@E |
| 809 |
\global\pgfmathfloatcomparisontrue |
| 810 |
\else |
| 811 |
\ifnum\pgfmathfloat@a@E=\pgfmathfloat@b@E |
| 812 |
\ifdim\pgfmathfloat@a@M>\pgfmathfloat@b@M |
| 813 |
\global\pgfmathfloatcomparisontrue |
| 814 |
\fi |
| 815 |
\fi |
| 816 |
\fi |
| 817 |
}% |
| 818 |
|
| 819 |
|
| 820 |
\def\pgfmathfloatgreaterthan@#1#2{\pgfmathfloatlessthan@{#2}{#1}}% |
| 821 |
\let\pgfmathfloatgreaterthan=\pgfmathfloatgreaterthan@ |
| 822 |
\let\pgfmathfloatgreater@=\pgfmathfloatgreaterthan@ |
| 823 |
|
| 824 |
\def\pgfmathfloatmax@#1{% |
| 825 |
\begingroup |
| 826 |
\pgfmathfloatcreate{2}{1.0}{2147483644}% |
| 827 |
\let\pgfmathmaxsofar=\pgfmathresult |
| 828 |
\pgfmathfloatmax@@#1{}% |
| 829 |
}% |
| 830 |
\def\pgfmathfloatmax@@#1{% |
| 831 |
\def\pgfmath@temp{#1}% |
| 832 |
\ifx\pgfmath@temp\pgfmath@empty% |
| 833 |
\expandafter\pgfmathfloatmax@@@% |
| 834 |
\else% |
| 835 |
\pgfmathfloatlessthan{\pgfmathmaxsofar}{#1}% |
| 836 |
\ifpgfmathfloatcomparison |
| 837 |
\edef\pgfmathmaxsofar{#1}% |
| 838 |
\fi |
| 839 |
\expandafter\pgfmathfloatmax@@% |
| 840 |
\fi% |
| 841 |
}% |
| 842 |
\def\pgfmathfloatmax@@@{% |
| 843 |
\let\pgfmathresult=\pgfmathmaxsofar |
| 844 |
\pgfmath@smuggleone{\pgfmathresult}% |
| 845 |
\endgroup |
| 846 |
}% |
| 847 |
\def\pgfmathfloatmin@#1{% |
| 848 |
\begingroup |
| 849 |
\pgfmathfloatcreate{1}{1.0}{2147483644}% |
| 850 |
\let\pgfmathminsofar=\pgfmathresult |
| 851 |
\pgfmathfloatmin@@#1{}% |
| 852 |
}% |
| 853 |
\def\pgfmathfloatmin@@#1{% |
| 854 |
\def\pgfmath@temp{#1}% |
| 855 |
\ifx\pgfmath@temp\pgfmath@empty% |
| 856 |
\expandafter\pgfmathfloatmin@@@% |
| 857 |
\else% |
| 858 |
\pgfmathfloatlessthan{#1}{\pgfmathminsofar}% |
| 859 |
\ifpgfmathfloatcomparison |
| 860 |
\edef\pgfmathminsofar{#1}% |
| 861 |
\fi |
| 862 |
\expandafter\pgfmathfloatmin@@% |
| 863 |
\fi% |
| 864 |
}% |
| 865 |
\def\pgfmathfloatmin@@@{% |
| 866 |
\let\pgfmathresult=\pgfmathminsofar |
| 867 |
\pgfmath@smuggleone{\pgfmathresult}% |
| 868 |
\endgroup |
| 869 |
}% |
| 870 |
|
| 871 |
\def\pgfmathfloatmaxtwo#1#2{% |
| 872 |
\pgfmathfloatlessthan{#1}{#2}% |
| 873 |
\ifpgfmathfloatcomparison |
| 874 |
\edef\pgfmathresult{#2}% |
| 875 |
\else |
| 876 |
\edef\pgfmathresult{#1}% |
| 877 |
\fi |
| 878 |
}% |
| 879 |
\let\pgfmathfloatmax=\pgfmathfloatmaxtwo |
| 880 |
|
| 881 |
\def\pgfmathfloatmintwo#1#2{% |
| 882 |
\pgfmathfloatlessthan{#1}{#2}% |
| 883 |
\ifpgfmathfloatcomparison |
| 884 |
\edef\pgfmathresult{#1}% |
| 885 |
\else |
| 886 |
\edef\pgfmathresult{#2}% |
| 887 |
\fi |
| 888 |
}% |
| 889 |
\let\pgfmathfloatmin=\pgfmathfloatmintwo |
| 890 |
|
| 891 |
% Renormalizes #1 to extended precision mantissa, meaning |
| 892 |
% 100 <= m < 1000 |
| 893 |
% instead of 1 <= m < 10. |
| 894 |
% |
| 895 |
% The 'extended precision' means we have higher accuracy when we apply pgfmath operations to mantissas. |
| 896 |
% |
| 897 |
% The input argument is expected to be a normalized floating point number; the output argument is a non-normalized floating point number (well, normalized to extended precision). |
| 898 |
% |
| 899 |
% The operation is supposed to be very fast. |
| 900 |
% |
| 901 |
% @see \pgfmathfloatsetextprecision |
| 902 |
% |
| 903 |
% There is a routine for internal usage, |
| 904 |
% \pgfmathfloattoextentedprecision@a. It also provides exponent and |
| 905 |
% sign of #1 in output arguments and may be used to increase speed. |
| 906 |
\def\pgfmathfloattoextentedprecision#1{% |
| 907 |
\begingroup |
| 908 |
\pgfmathfloattoextentedprecision@a{#1}% |
| 909 |
\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\pgfmathresult}{\the\pgfmathfloat@a@E}% |
| 910 |
\pgfmath@smuggleone\pgfmathresult |
| 911 |
\endgroup |
| 912 |
}% |
| 913 |
|
| 914 |
\def\pgfmathfloattoextentedprecision@@zero#1\pgfmathfloat@EOI{% |
| 915 |
\edef\pgfmathresult{#1}% |
| 916 |
}% |
| 917 |
\def\pgfmathfloattoextentedprecision@@one#1.#2#3\pgfmathfloat@EOI{% |
| 918 |
\edef\pgfmathresult{#1#2.#3}% |
| 919 |
}% |
| 920 |
\def\pgfmathfloattoextentedprecision@@two#1.#2#3#4\pgfmathfloat@EOI{% |
| 921 |
\edef\pgfmathresult{#1#2#3.#4}% |
| 922 |
}% |
| 923 |
\def\pgfmathfloattoextentedprecision@@three#1.#2#3#4#5\pgfmathfloat@EOI{% |
| 924 |
\edef\pgfmathresult{#1#2#3#4.#5}% |
| 925 |
}% |
| 926 |
|
| 927 |
% Sets extended precision to 10^#1. |
| 928 |
% |
| 929 |
% The different choices are |
| 930 |
% |
| 931 |
% - 0: normalization 0 <= m < 1 (disable extended precision) |
| 932 |
% - 1: normalization 10 <= m < 100 |
| 933 |
% - 2: normalization 100 <= m < 1000 (default) |
| 934 |
% - 3: normalization 1000 <= m < 10000 |
| 935 |
% |
| 936 |
% #1 is the exponent, #1 = 0,1,2 or 3. |
| 937 |
% |
| 938 |
% This setting applies to \pgfmathfloattoextentedprecision and friends. |
| 939 |
\def\pgfmathfloatsetextprecision#1{% |
| 940 |
\ifcase#1\relax |
| 941 |
\let\pgfmathfloattoextentedprecision@@=\pgfmathfloattoextentedprecision@@zero |
| 942 |
\def\pgfmathfloatextprec@shift{0}% |
| 943 |
\or |
| 944 |
\let\pgfmathfloattoextentedprecision@@=\pgfmathfloattoextentedprecision@@one |
| 945 |
\def\pgfmathfloatextprec@shift{1}% |
| 946 |
\or |
| 947 |
\let\pgfmathfloattoextentedprecision@@=\pgfmathfloattoextentedprecision@@two |
| 948 |
\def\pgfmathfloatextprec@shift{2}% |
| 949 |
\else |
| 950 |
\let\pgfmathfloattoextentedprecision@@=\pgfmathfloattoextentedprecision@@three |
| 951 |
\def\pgfmathfloatextprec@shift{3}% |
| 952 |
\fi |
| 953 |
}% |
| 954 |
\pgfmathfloatsetextprecision{2}% |
| 955 |
|
| 956 |
% Does the "hard" work for \pgfmathfloattoextentedprecision. It |
| 957 |
% provides additional outputs. |
| 958 |
% |
| 959 |
% INPUT: |
| 960 |
% #1 normalized floating point number. Maybe a macro (it will be expanded ONCE) |
| 961 |
% |
| 962 |
% OUTPUT: |
| 963 |
% - \pgfmathresult : the mantissa in extended precision |
| 964 |
% - \pgfmathfloat@a@S : the sign of #1 |
| 965 |
% - \pgfmathfloat@a@E : the exponent of #1, adjusted for extended precision |
| 966 |
% - \pgfmathfloat@a@Mtok : undefined (its contents will be destroyed. |
| 967 |
% |
| 968 |
\def\pgfmathfloattoextentedprecision@a#1{% |
| 969 |
\edef\pgfmathresult{#1}% |
| 970 |
\expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 971 |
\ifnum\pgfmathfloat@a@S<3 |
| 972 |
\advance\pgfmathfloat@a@E by-\pgfmathfloatextprec@shift\relax% compensate for shift |
| 973 |
\expandafter\pgfmathfloattoextentedprecision@@\the\pgfmathfloat@a@Mtok 000\pgfmathfloat@EOI |
| 974 |
\fi |
| 975 |
}% |
| 976 |
|
| 977 |
|
| 978 |
% Similar to \pgfmathfloattoextentedprecision@a, this one here fills the '@b' registers. |
| 979 |
\def\pgfmathfloattoextentedprecision@b#1{% |
| 980 |
\edef\pgfmathresult{#1}% |
| 981 |
\expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@b@S\pgfmathfloat@a@Mtok\pgfmathfloat@b@E |
| 982 |
\ifnum\pgfmathfloat@b@S<3 |
| 983 |
\advance\pgfmathfloat@b@E by-\pgfmathfloatextprec@shift\relax |
| 984 |
\expandafter\pgfmathfloattoextentedprecision@@\the\pgfmathfloat@a@Mtok 00\pgfmathfloat@EOI |
| 985 |
\fi |
| 986 |
}% |
| 987 |
|
| 988 |
% Addition of two floating point numbers using 8 significant digits. |
| 989 |
\def\pgfmathfloatadd@#1#2{% |
| 990 |
\begingroup |
| 991 |
% |
| 992 |
% renormalize argument to 100 <= m < 1000 for extended accuracy: |
| 993 |
\pgfmathfloattoextentedprecision@a{#1}% |
| 994 |
\let\pgfmathfloat@arga=\pgfmathresult |
| 995 |
% |
| 996 |
\pgfmathfloattoextentedprecision@b{#2}% |
| 997 |
\let\pgfmathfloat@argb=\pgfmathresult |
| 998 |
% |
| 999 |
\pgfmathfloatcomparisontrue% re-use this boolean here to handle special cases. |
| 1000 |
\ifcase\pgfmathfloat@a@S |
| 1001 |
\edef\pgfmathresult{#2}% |
| 1002 |
\pgfmathfloatcomparisonfalse |
| 1003 |
\or |
| 1004 |
\or |
| 1005 |
\edef\pgfmathfloat@arga{-\pgfmathfloat@arga}% |
| 1006 |
\else |
| 1007 |
\pgfmathfloatcomparisonfalse |
| 1008 |
\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{0.0}{0}% |
| 1009 |
\fi |
| 1010 |
\ifcase\pgfmathfloat@b@S |
| 1011 |
\edef\pgfmathresult{#1}% |
| 1012 |
\pgfmathfloatcomparisonfalse |
| 1013 |
\or |
| 1014 |
\or |
| 1015 |
\edef\pgfmathfloat@argb{-\pgfmathfloat@argb}% |
| 1016 |
\else |
| 1017 |
\pgfmathfloatcomparisonfalse |
| 1018 |
\pgfmathfloatcreate{\the\pgfmathfloat@b@S}{0.0}{0}% |
| 1019 |
\fi |
| 1020 |
\ifpgfmathfloatcomparison |
| 1021 |
% Shift lesser mantisse to fit the larger one: |
| 1022 |
\ifnum\pgfmathfloat@a@E<\pgfmathfloat@b@E |
| 1023 |
\pgfmathfloatadd@shift{\pgfmathfloat@arga}{\pgfmathfloat@a@E}{\pgfmathfloat@b@E}% |
| 1024 |
\else |
| 1025 |
\pgfmathfloatadd@shift{\pgfmathfloat@argb}{\pgfmathfloat@b@E}{\pgfmathfloat@a@E}% |
| 1026 |
\fi |
| 1027 |
% add them! |
| 1028 |
\pgfmath@basic@add@{\pgfmathfloat@arga}{\pgfmathfloat@argb}% |
| 1029 |
% renormalize sum. This is the only part were an expensive routine comes into play: |
| 1030 |
\edef\pgfmathresult{\pgfmathresult e\the\pgfmathfloat@a@E}% |
| 1031 |
\expandafter\pgfmathfloatqparsenumber\expandafter{\pgfmathresult}% |
| 1032 |
\fi |
| 1033 |
\pgfmath@smuggleone\pgfmathresult |
| 1034 |
\endgroup |
| 1035 |
}% |
| 1036 |
|
| 1037 |
% #1= floating point number |
| 1038 |
% #2= TeX code to execute if #1 == 0 |
| 1039 |
% #3= TeX code to execute if #1 != 0 |
| 1040 |
\def\pgfmathfloatifzero#1#2#3{% |
| 1041 |
\pgfmathfloatgetflagstomacro{#1}\pgfmathfloat@loc@TMPa |
| 1042 |
\if\pgfmathfloat@loc@TMPa0 #2\else#3\fi |
| 1043 |
}% |
| 1044 |
|
| 1045 |
\def\pgfmathfloatiffinite#1#2#3{% |
| 1046 |
\pgfmathfloatgetflagstomacro{#1}\pgfmathfloatiffinite@ |
| 1047 |
\ifnum\pgfmathfloatiffinite@>2 #3\else #2\fi |
| 1048 |
}% |
| 1049 |
|
| 1050 |
\def\pgfmathfloatifthenelse@#1#2#3{% |
| 1051 |
\pgfmathfloatifflags{#1}{0}{% |
| 1052 |
\edef\pgfmathresult{#3}%% |
| 1053 |
}{% |
| 1054 |
\edef\pgfmathresult{#2}% |
| 1055 |
}% |
| 1056 |
}% |
| 1057 |
\def\pgfmathfloatequal@#1#2{% |
| 1058 |
\pgfmathfloatifapproxequalrel{#1}{#2}{% |
| 1059 |
\def\pgfmathresult{1}% |
| 1060 |
\pgfmathfloatcomparisontrue |
| 1061 |
}{% |
| 1062 |
\def\pgfmathresult{0}% |
| 1063 |
\pgfmathfloatcomparisonfalse |
| 1064 |
}% |
| 1065 |
}% |
| 1066 |
\let\pgfmathfloatequalto@=\pgfmathfloatequal@ |
| 1067 |
|
| 1068 |
\def\pgfmathfloatnotequal@#1#2{% |
| 1069 |
\pgfmathfloatifapproxequalrel{#1}{#2}{% |
| 1070 |
\def\pgfmathresult{0}% |
| 1071 |
\pgfmathfloatcomparisonfalse |
| 1072 |
}{% |
| 1073 |
\def\pgfmathresult{1}% |
| 1074 |
\pgfmathfloatcomparisontrue |
| 1075 |
}% |
| 1076 |
}% |
| 1077 |
\let\pgfmathfloatnotequalto@=\pgfmathfloatnotequal@ |
| 1078 |
|
| 1079 |
% Computes the relative error between #1 and #2 (assuming #2 != 0) and |
| 1080 |
% invokes #3 if the relative error is below `/pgf/fpu/rel thresh' and |
| 1081 |
% #4 if that is not the case. |
| 1082 |
\long\def\pgfmathfloatifapproxequalrel#1#2#3#4{% |
| 1083 |
\begingroup |
| 1084 |
\pgfmathfloatparsenumber{#1}% |
| 1085 |
\let\pgfmathfloatarga=\pgfmathresult |
| 1086 |
\pgfmathfloatparsenumber{#2}% |
| 1087 |
\let\pgfmathfloatargb=\pgfmathresult |
| 1088 |
\pgfmathfloatrelerror@\pgfmathfloatarga\pgfmathfloatargb |
| 1089 |
\let\pgfmathfloatarga=\pgfmathresult |
| 1090 |
\pgfmathfloatlessthan@\pgfmathfloatarga\pgfmathfloat@relthresh |
| 1091 |
\ifpgfmathfloatcomparison |
| 1092 |
\def\pgfmathfloat@loc@TMPa{#3}% |
| 1093 |
\else |
| 1094 |
\def\pgfmathfloat@loc@TMPa{#4}% |
| 1095 |
\fi |
| 1096 |
\expandafter\endgroup |
| 1097 |
\pgfmathfloat@loc@TMPa |
| 1098 |
}% |
| 1099 |
|
| 1100 |
% Invokes code '#3' if the flags of the floating point number '#1' |
| 1101 |
% match the flag provided in '#2'. |
| 1102 |
% |
| 1103 |
% \pgfmathfloatcreate{1}{1.0}{2} |
| 1104 |
% \pgfmathfloatifflags{\pgfmathresult}{0}{It's zero!}{It's not zero!}% |
| 1105 |
% \pgfmathfloatifflags{\pgfmathresult}{1}{It's positive!}{It's not positive!}% |
| 1106 |
% \pgfmathfloatifflags{\pgfmathresult}{2}{It's negative!}{It's not negative!}% |
| 1107 |
% or, equivalently |
| 1108 |
% \pgfmathfloatifflags{\pgfmathresult}{+}{It's positive!}{It's not positive!}% |
| 1109 |
% \pgfmathfloatifflags{\pgfmathresult}{-}{It's negative!}{It's not negative!}% |
| 1110 |
% it also supports #2=u which means 'unbounded' |
| 1111 |
\def\pgfmathfloatifflags#1#2#3#4{% |
| 1112 |
\if#2-% |
| 1113 |
\pgfmathfloatifflags{#1}{2}{#3}{#4}% |
| 1114 |
\else |
| 1115 |
\if#2+% |
| 1116 |
\pgfmathfloatifflags{#1}{1}{#3}{#4}% |
| 1117 |
\else |
| 1118 |
\pgfmathfloatgetflagstomacro{#1}\pgfmathfloat@loc@TMPa |
| 1119 |
\if#2u% |
| 1120 |
\ifnum\pgfmathfloat@loc@TMPa>2 |
| 1121 |
#3\relax |
| 1122 |
\else |
| 1123 |
#4\relax |
| 1124 |
\fi |
| 1125 |
\else |
| 1126 |
\if\pgfmathfloat@loc@TMPa#2% |
| 1127 |
#3\relax |
| 1128 |
\else |
| 1129 |
#4\relax |
| 1130 |
\fi |
| 1131 |
\fi |
| 1132 |
\fi |
| 1133 |
\fi |
| 1134 |
}% |
| 1135 |
|
| 1136 |
% #1=mantissa which needs to be shifted (with smaller exponent) |
| 1137 |
% #2=smaller exponent |
| 1138 |
% #3=larger exponent |
| 1139 |
% |
| 1140 |
% ATTENTION: this helper method DESTROYS contents of \pgfmathfloat@a@S. |
| 1141 |
\def\pgfmathfloatadd@shift#1#2#3{% |
| 1142 |
\pgf@xa=#1 pt% |
| 1143 |
\pgfmathfloat@a@S=#3\relax |
| 1144 |
\advance\pgfmathfloat@a@S by-#2\relax |
| 1145 |
\ifcase\pgfmathfloat@a@S |
| 1146 |
\or |
| 1147 |
\divide\pgf@xa by10\relax |
| 1148 |
\or |
| 1149 |
\divide\pgf@xa by100\relax |
| 1150 |
\or |
| 1151 |
\divide\pgf@xa by1000\relax |
| 1152 |
\or |
| 1153 |
\divide\pgf@xa by10000\relax |
| 1154 |
\or |
| 1155 |
\divide\pgf@xa by10000\relax |
| 1156 |
\divide\pgf@xa by10\relax |
| 1157 |
\or |
| 1158 |
\divide\pgf@xa by10000\relax |
| 1159 |
\divide\pgf@xa by100\relax |
| 1160 |
\or |
| 1161 |
\divide\pgf@xa by10000\relax |
| 1162 |
\divide\pgf@xa by1000\relax |
| 1163 |
\or |
| 1164 |
\divide\pgf@xa by10000\relax |
| 1165 |
\divide\pgf@xa by10000\relax |
| 1166 |
\else |
| 1167 |
\pgf@xa=0pt% |
| 1168 |
\fi |
| 1169 |
#2=#3\relax |
| 1170 |
\edef#1{\pgf@sys@tonumber\pgf@xa}% |
| 1171 |
}% |
| 1172 |
|
| 1173 |
\let\pgfmathfloatadd=\pgfmathfloatadd@ |
| 1174 |
|
| 1175 |
|
| 1176 |
% Subtracts two floating point numbers. |
| 1177 |
\def\pgfmathfloatsubtract@#1#2{% |
| 1178 |
\begingroup |
| 1179 |
\edef\pgfmathresult{#2}% |
| 1180 |
\expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@b@S\pgfmathfloat@a@Mtok\pgfmathfloat@b@E |
| 1181 |
\ifcase\pgfmathfloat@b@S |
| 1182 |
\edef\pgfmathresult{#1}% |
| 1183 |
\or |
| 1184 |
\pgfmathfloatcreate{2}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@b@E}% |
| 1185 |
\let\pgfmathfloatsub@arg=\pgfmathresult |
| 1186 |
\pgfmathfloatadd@{#1}{\pgfmathfloatsub@arg}% |
| 1187 |
\or |
| 1188 |
\pgfmathfloatcreate{1}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@b@E}% |
| 1189 |
\let\pgfmathfloatsub@arg=\pgfmathresult |
| 1190 |
\pgfmathfloatadd@{#1}{\pgfmathfloatsub@arg}% |
| 1191 |
\else |
| 1192 |
\pgfmathfloatcreate{\the\pgfmathfloat@b@S}{0.0}{0}% |
| 1193 |
\fi |
| 1194 |
\pgfmath@smuggleone\pgfmathresult |
| 1195 |
\endgroup |
| 1196 |
}% |
| 1197 |
|
| 1198 |
\let\pgfmathfloatsubtract=\pgfmathfloatsubtract@ |
| 1199 |
|
| 1200 |
% Scales a floating point number #1 with a fixed point number #2 using pgfmathmultiply. |
| 1201 |
% |
| 1202 |
% Use this method if #2 is small number. |
| 1203 |
\def\pgfmathfloatmultiplyfixed@#1#2{% |
| 1204 |
\begingroup |
| 1205 |
% |
| 1206 |
% renormalize argument to 100 <= m < 1000 for extended accuracy: |
| 1207 |
\pgfmathfloattoextentedprecision@a{#1}% |
| 1208 |
\let\pgfmathfloat@arga=\pgfmathresult |
| 1209 |
% |
| 1210 |
\pgfmathfloatcomparisontrue% re-use this boolean here to handle special cases. |
| 1211 |
\ifcase\pgfmathfloat@a@S |
| 1212 |
\edef\pgfmathresult{#1}% |
| 1213 |
\pgfmathfloatcomparisonfalse |
| 1214 |
\or |
| 1215 |
\or |
| 1216 |
\edef\pgfmathfloat@arga{-\pgfmathfloat@arga}% |
| 1217 |
\else |
| 1218 |
\pgfmathfloatcomparisonfalse |
| 1219 |
\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{0.0}{0}% |
| 1220 |
\fi |
| 1221 |
\ifpgfmathfloatcomparison |
| 1222 |
\pgfmath@basic@multiply@{\pgfmathfloat@arga}{#2}% |
| 1223 |
% renormalize product. This is the only part were an expensive routine comes into play: |
| 1224 |
\edef\pgfmathresult{\pgfmathresult e\the\pgfmathfloat@a@E}% |
| 1225 |
\expandafter\pgfmathfloatqparsenumber\expandafter{\pgfmathresult}% |
| 1226 |
\fi |
| 1227 |
\pgfmath@smuggleone\pgfmathresult |
| 1228 |
\endgroup |
| 1229 |
}% |
| 1230 |
|
| 1231 |
\let\pgfmathfloatmultiplyfixed=\pgfmathfloatmultiplyfixed@ |
| 1232 |
|
| 1233 |
|
| 1234 |
\def\pgfmathfloatmultiply@#1#2{% |
| 1235 |
\begingroup |
| 1236 |
\pgfmathfloatsetextprecision{1}% |
| 1237 |
\pgfmathfloattoextentedprecision@a{#1}% |
| 1238 |
\let\pgfmathfloat@arga=\pgfmathresult |
| 1239 |
% |
| 1240 |
\pgfmathfloattoextentedprecision@b{#2}% |
| 1241 |
\let\pgfmathfloat@argb=\pgfmathresult |
| 1242 |
% |
| 1243 |
\pgfmathfloatcomparisontrue% re-use this boolean here to handle special cases. |
| 1244 |
\ifcase\pgfmathfloat@a@S |
| 1245 |
% 0 |
| 1246 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1247 |
\pgfmathfloatcomparisonfalse |
| 1248 |
\or% + |
| 1249 |
\ifcase\pgfmathfloat@b@S |
| 1250 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1251 |
\pgfmathfloatcomparisonfalse |
| 1252 |
\or |
| 1253 |
\def\pgfmathresult@S{1}% |
| 1254 |
\or |
| 1255 |
\def\pgfmathresult@S{2}% |
| 1256 |
\else |
| 1257 |
\expandafter\pgfmathfloatcreate\the\pgfmathfloat@b@S{0.0}{0}% |
| 1258 |
\pgfmathfloatcomparisonfalse |
| 1259 |
\fi |
| 1260 |
\or% - |
| 1261 |
\ifcase\pgfmathfloat@b@S |
| 1262 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1263 |
\pgfmathfloatcomparisonfalse |
| 1264 |
\or |
| 1265 |
\def\pgfmathresult@S{2}% |
| 1266 |
\or |
| 1267 |
\def\pgfmathresult@S{1}% |
| 1268 |
\or |
| 1269 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1270 |
\pgfmathfloatcomparisonfalse |
| 1271 |
\or |
| 1272 |
\pgfmathfloatcreate{5}{0.0}{0}% |
| 1273 |
\pgfmathfloatcomparisonfalse |
| 1274 |
\or |
| 1275 |
\pgfmathfloatcreate{4}{0.0}{0}% |
| 1276 |
\pgfmathfloatcomparisonfalse |
| 1277 |
\fi |
| 1278 |
\or% nan |
| 1279 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1280 |
\pgfmathfloatcomparisonfalse |
| 1281 |
\or% +infty |
| 1282 |
\ifcase\pgfmathfloat@b@S |
| 1283 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1284 |
\pgfmathfloatcomparisonfalse |
| 1285 |
\or |
| 1286 |
\pgfmathfloatcreate{4}{0.0}{0}% |
| 1287 |
\pgfmathfloatcomparisonfalse |
| 1288 |
\or |
| 1289 |
\pgfmathfloatcreate{5}{0.0}{0}% |
| 1290 |
\pgfmathfloatcomparisonfalse |
| 1291 |
\or |
| 1292 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1293 |
\pgfmathfloatcomparisonfalse |
| 1294 |
\or |
| 1295 |
\pgfmathfloatcreate{4}{0.0}{0}% |
| 1296 |
\pgfmathfloatcomparisonfalse |
| 1297 |
\or |
| 1298 |
\pgfmathfloatcreate{5}{0.0}{0}% |
| 1299 |
\pgfmathfloatcomparisonfalse |
| 1300 |
\fi |
| 1301 |
\or% -infty |
| 1302 |
\ifcase\pgfmathfloat@b@S |
| 1303 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1304 |
\pgfmathfloatcomparisonfalse |
| 1305 |
\or |
| 1306 |
\pgfmathfloatcreate{5}{0.0}{0}% |
| 1307 |
\pgfmathfloatcomparisonfalse |
| 1308 |
\or |
| 1309 |
\pgfmathfloatcreate{4}{0.0}{0}% |
| 1310 |
\pgfmathfloatcomparisonfalse |
| 1311 |
\or |
| 1312 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1313 |
\pgfmathfloatcomparisonfalse |
| 1314 |
\or |
| 1315 |
\pgfmathfloatcreate{5}{0.0}{0}% |
| 1316 |
\pgfmathfloatcomparisonfalse |
| 1317 |
\or |
| 1318 |
\pgfmathfloatcreate{4}{0.0}{0}% |
| 1319 |
\pgfmathfloatcomparisonfalse |
| 1320 |
\fi |
| 1321 |
\fi |
| 1322 |
\ifpgfmathfloatcomparison |
| 1323 |
\pgfmath@basic@multiply@{\pgfmathfloat@arga}{\pgfmathfloat@argb}% |
| 1324 |
\advance\pgfmathfloat@a@E by\pgfmathfloat@b@E |
| 1325 |
% renormalize sum. This is the only part were an expensive routine comes into play: |
| 1326 |
\edef\pgfmathresult{\pgfmathresult e\the\pgfmathfloat@a@E}% |
| 1327 |
\expandafter\pgfmathfloatqparsenumber\expandafter{\pgfmathresult}% |
| 1328 |
\expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 1329 |
\pgfmathfloatcreate{\pgfmathresult@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% |
| 1330 |
\fi |
| 1331 |
\pgfmath@smuggleone\pgfmathresult |
| 1332 |
\endgroup |
| 1333 |
}% |
| 1334 |
\let\pgfmathfloatmultiply=\pgfmathfloatmultiply@ |
| 1335 |
|
| 1336 |
% Defines \pgfmathresult to be #1 / #2 for two floating point numbers. |
| 1337 |
% |
| 1338 |
% It employs the basic math engine internally to divide mantissas. |
| 1339 |
\def\pgfmathfloatdivide@#1#2{% |
| 1340 |
\begingroup |
| 1341 |
\pgfmathfloatsetextprecision{1}% is not too important, I think. After all, 0.1 <= #1/#2 < 10 or so due to normalization (no matter, which) |
| 1342 |
\edef\pgfmathfloat@arga{#1}% |
| 1343 |
\pgfmathfloattoextentedprecision@a{\pgfmathfloat@arga}% |
| 1344 |
\let\pgfmathfloat@arga=\pgfmathresult |
| 1345 |
% |
| 1346 |
\edef\pgfmathfloat@argb{#2}% |
| 1347 |
\pgfmathfloattoextentedprecision@b{\pgfmathfloat@argb}% |
| 1348 |
\let\pgfmathfloat@argb=\pgfmathresult |
| 1349 |
% |
| 1350 |
\pgfmathfloatcomparisontrue% re-use this boolean here to handle special cases. |
| 1351 |
\ifcase\pgfmathfloat@a@S |
| 1352 |
% 0 |
| 1353 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1354 |
\pgfmathfloatcomparisonfalse |
| 1355 |
\or% + |
| 1356 |
\ifcase\pgfmathfloat@b@S |
| 1357 |
\pgfmathfloatcreate{4}{0.0}{0}% |
| 1358 |
\pgfmathfloatcomparisonfalse |
| 1359 |
\or |
| 1360 |
\def\pgfmathresult@S{1}% |
| 1361 |
\or |
| 1362 |
\def\pgfmathresult@S{2}% |
| 1363 |
\or |
| 1364 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1365 |
\pgfmathfloatcomparisonfalse |
| 1366 |
\else |
| 1367 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1368 |
\pgfmathfloatcomparisonfalse |
| 1369 |
\fi |
| 1370 |
\or% - |
| 1371 |
\ifcase\pgfmathfloat@b@S |
| 1372 |
\pgfmathfloatcreate{5}{0.0}{0}% |
| 1373 |
\pgfmathfloatcomparisonfalse |
| 1374 |
\or |
| 1375 |
\def\pgfmathresult@S{2}% |
| 1376 |
\or |
| 1377 |
\def\pgfmathresult@S{1}% |
| 1378 |
\or |
| 1379 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1380 |
\pgfmathfloatcomparisonfalse |
| 1381 |
\else |
| 1382 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1383 |
\pgfmathfloatcomparisonfalse |
| 1384 |
\fi |
| 1385 |
\or% nan |
| 1386 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1387 |
\pgfmathfloatcomparisonfalse |
| 1388 |
\or% +infty |
| 1389 |
\ifcase\pgfmathfloat@b@S |
| 1390 |
\pgfmathfloatcreate{4}{0.0}{0}% |
| 1391 |
\pgfmathfloatcomparisonfalse |
| 1392 |
\or |
| 1393 |
\pgfmathfloatcreate{4}{0.0}{0}% |
| 1394 |
\pgfmathfloatcomparisonfalse |
| 1395 |
\or |
| 1396 |
\pgfmathfloatcreate{5}{0.0}{0}% |
| 1397 |
\pgfmathfloatcomparisonfalse |
| 1398 |
\or |
| 1399 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1400 |
\pgfmathfloatcomparisonfalse |
| 1401 |
\or |
| 1402 |
\pgfmathfloatcreate{4}{0.0}{0}% what is inf/inf ? |
| 1403 |
\pgfmathfloatcomparisonfalse |
| 1404 |
\or |
| 1405 |
\pgfmathfloatcreate{5}{0.0}{0}% or inf/-inf ? |
| 1406 |
\pgfmathfloatcomparisonfalse |
| 1407 |
\fi |
| 1408 |
\or% -infty |
| 1409 |
\ifcase\pgfmathfloat@b@S |
| 1410 |
\pgfmathfloatcreate{5}{0.0}{0}% |
| 1411 |
\pgfmathfloatcomparisonfalse |
| 1412 |
\or |
| 1413 |
\pgfmathfloatcreate{5}{0.0}{0}% |
| 1414 |
\pgfmathfloatcomparisonfalse |
| 1415 |
\or |
| 1416 |
\pgfmathfloatcreate{4}{0.0}{0}% |
| 1417 |
\pgfmathfloatcomparisonfalse |
| 1418 |
\or |
| 1419 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1420 |
\pgfmathfloatcomparisonfalse |
| 1421 |
\or |
| 1422 |
\pgfmathfloatcreate{5}{0.0}{0}% |
| 1423 |
\pgfmathfloatcomparisonfalse |
| 1424 |
\or |
| 1425 |
\pgfmathfloatcreate{4}{0.0}{0}% |
| 1426 |
\pgfmathfloatcomparisonfalse |
| 1427 |
\fi |
| 1428 |
\fi |
| 1429 |
\ifpgfmathfloatcomparison |
| 1430 |
\pgfmath@basic@divide@{\pgfmathfloat@arga}{\pgfmathfloat@argb}% |
| 1431 |
\advance\pgfmathfloat@a@E by-\pgfmathfloat@b@E |
| 1432 |
% renormalize. This is the only part were an expensive float routine comes into play: |
| 1433 |
\edef\pgfmathresult{\pgfmathresult e\the\pgfmathfloat@a@E}% |
| 1434 |
\expandafter\pgfmathfloatqparsenumber\expandafter{\pgfmathresult}% |
| 1435 |
% And re-insert the proper sign: |
| 1436 |
\expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 1437 |
\pgfmathfloatcreate{\pgfmathresult@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% |
| 1438 |
\fi |
| 1439 |
\pgfmath@smuggleone\pgfmathresult |
| 1440 |
\endgroup |
| 1441 |
}% |
| 1442 |
\let\pgfmathfloatdivide=\pgfmathfloatdivide@ |
| 1443 |
|
| 1444 |
\def\pgfmathfloatreciprocal@#1{% |
| 1445 |
\begingroup |
| 1446 |
% FIXME optimize |
| 1447 |
\edef\pgfmathfloat@loc@TMPa{#1}% |
| 1448 |
\pgfmathfloatcreate{1}{1.0}{0}% |
| 1449 |
\pgfmathfloatdivide@{\pgfmathresult}{\pgfmathfloat@loc@TMPa}% |
| 1450 |
\pgfmath@smuggleone\pgfmathresult |
| 1451 |
\endgroup |
| 1452 |
}% |
| 1453 |
|
| 1454 |
% Computes sqrt(#1) in floating point arithmetics. |
| 1455 |
% |
| 1456 |
% It employs sqrt( m * 10^e ) = sqrt(m) * sqrt(10^e). |
| 1457 |
\def\pgfmathfloatsqrt@#1{% |
| 1458 |
\begingroup |
| 1459 |
\pgfmathfloatsetextprecision{3}% |
| 1460 |
\edef\pgfmathfloat@arga{#1}% |
| 1461 |
\pgfmathfloattoextentedprecision@a{\pgfmathfloat@arga}% |
| 1462 |
\let\pgfmathfloat@arga=\pgfmathresult |
| 1463 |
% |
| 1464 |
\ifcase\pgfmathfloat@a@S |
| 1465 |
% 0 |
| 1466 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1467 |
\or% + |
| 1468 |
\pgfmath@basic@sqrt@{\pgfmathfloat@arga}% |
| 1469 |
\ifodd\pgfmathfloat@a@E |
| 1470 |
\ifnum\pgfmathfloat@a@E>0 |
| 1471 |
\expandafter\pgfmath@basic@multiply@\expandafter{\pgfmathresult}{3.16227766}% * sqrt(10) |
| 1472 |
\else |
| 1473 |
\expandafter\pgfmath@basic@multiply@\expandafter{\pgfmathresult}{0.316227766}% * sqrt(0.1) |
| 1474 |
\fi |
| 1475 |
\fi |
| 1476 |
\divide\pgfmathfloat@a@E by2 % sqrt(10^e) = 10^{e/2} (see above for odd e) |
| 1477 |
% renormalize sum. This is the only part were an expensive routine comes into play: |
| 1478 |
\edef\pgfmathfloat@arga{\pgfmathresult e\the\pgfmathfloat@a@E}% |
| 1479 |
\pgfmathfloatqparsenumber{\pgfmathfloat@arga}% |
| 1480 |
\or% - |
| 1481 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1482 |
\or% nan |
| 1483 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1484 |
\or% +infty |
| 1485 |
\pgfmathfloatcreate{4}{0.0}{0}% |
| 1486 |
\or% -infty |
| 1487 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1488 |
\fi |
| 1489 |
\pgfmath@smuggleone\pgfmathresult |
| 1490 |
\endgroup |
| 1491 |
}% |
| 1492 |
\let\pgfmathfloatsqrt=\pgfmathfloatsqrt@ |
| 1493 |
|
| 1494 |
% Returns the integer part of the floating point number #1. |
| 1495 |
% |
| 1496 |
% The result is returned as floating point as well. |
| 1497 |
% |
| 1498 |
% This operation is not limited to TeX's range of count registers (it |
| 1499 |
% works symbolly) |
| 1500 |
% |
| 1501 |
% @see \pgfmathfloattoint |
| 1502 |
% POSTCONDITION: \pgfmathresult contains the result and |
| 1503 |
% \pgfmathfloatintwasnoop=1 if there was nothing to do |
| 1504 |
% \pgfmathfloatintwasnoop=0 if there where non-zero digits after the period |
| 1505 |
% \pgfmathfloatintwasnoop=2 if there where digits after the period. The digits will be stored in \pgfmathfloatintremainder in this case. |
| 1506 |
\def\pgfmathfloatint@#1{% |
| 1507 |
\begingroup |
| 1508 |
\edef\pgfmathfloatint@input{#1}% |
| 1509 |
\expandafter\pgfmathfloat@decompose@tok\pgfmathfloatint@input\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 1510 |
\gdef\pgfmathfloatintwasnoop{1}% |
| 1511 |
\gdef\pgfmathfloatintremainder{}% |
| 1512 |
\ifcase\pgfmathfloat@a@S |
| 1513 |
% 0: nothing to do. |
| 1514 |
\or% + |
| 1515 |
\expandafter\pgfmathfloatint@@\the\pgfmathfloat@a@Mtok\pgfmathfloat@EOI |
| 1516 |
\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% |
| 1517 |
\or% - |
| 1518 |
\expandafter\pgfmathfloatint@@\the\pgfmathfloat@a@Mtok\pgfmathfloat@EOI |
| 1519 |
\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% |
| 1520 |
\else |
| 1521 |
% nothing to do |
| 1522 |
\fi |
| 1523 |
%\message{ XXXXX int(\pgfmathfloatint@input) = \pgfmathresult -> was no op = \pgfmathfloatintwasnoop\space (remainder \pgfmathfloatintremainder)^^J}% |
| 1524 |
\pgfmath@smuggleone\pgfmathresult |
| 1525 |
\endgroup |
| 1526 |
}% |
| 1527 |
\def\pgfmathfloatint@@#1.{% |
| 1528 |
\ifnum\pgfmathfloat@a@E<0 |
| 1529 |
\pgfmathfloat@a@S=0 |
| 1530 |
\pgfmathfloat@a@Mtok={0.0}% |
| 1531 |
\pgfmathfloat@a@E=0 |
| 1532 |
\gdef\pgfmathfloatintwasnoop{0}% |
| 1533 |
\expandafter\pgfmathfloatint@@loop@gobble |
| 1534 |
\else |
| 1535 |
\pgfmathfloat@a@Mtok={#1.}% |
| 1536 |
\pgfmathfloat@b@E=\pgfmathfloat@a@E |
| 1537 |
\expandafter\pgfmathfloatint@@loop |
| 1538 |
\fi |
| 1539 |
}% |
| 1540 |
\def\pgfmathfloatint@@loop#1{% |
| 1541 |
\def\pgfmathfloatint@@loop@{#1}% |
| 1542 |
\ifx\pgfmathfloatint@@loop@\pgfmathfloat@EOI |
| 1543 |
\gdef\pgfmathfloatintwasnoop{1}% |
| 1544 |
\let\pgfmathfloatint@@loop@next=\relax |
| 1545 |
\else |
| 1546 |
\ifnum\pgfmathfloat@b@E=0 |
| 1547 |
\def\pgfmathfloatint@@loop@next{\pgfmathfloatint@@loop@gobble#1}% |
| 1548 |
\else |
| 1549 |
\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}% |
| 1550 |
\advance\pgfmathfloat@b@E by-1 |
| 1551 |
\let\pgfmathfloatint@@loop@next=\pgfmathfloatint@@loop |
| 1552 |
\fi |
| 1553 |
\fi |
| 1554 |
\pgfmathfloatint@@loop@next |
| 1555 |
}% |
| 1556 |
\def\pgfmathfloatint@@loop@gobble#1\pgfmathfloat@EOI{% |
| 1557 |
\if0\pgfmathfloatintwasnoop |
| 1558 |
\else |
| 1559 |
\gdef\pgfmathfloatintwasnoop{2}% |
| 1560 |
\gdef\pgfmathfloatintremainder{#1}% |
| 1561 |
\fi |
| 1562 |
}% |
| 1563 |
\let\pgfmathfloatint=\pgfmathfloatint@ |
| 1564 |
|
| 1565 |
\def\pgfmathfloatfloor#1{% |
| 1566 |
\edef\pgfmath@orig{#1}% |
| 1567 |
\pgfmathfloatint@{#1}% |
| 1568 |
\pgfmathfloatifflags{\pgfmath@orig}{2}{% |
| 1569 |
\let\pgfmath@trunc=\pgfmathresult |
| 1570 |
\ifcase\pgfmathfloatintwasnoop\relax |
| 1571 |
% ah - we stripped something! Round DOWN |
| 1572 |
\pgfmathfloatcreate{2}{1.0}{0}% -1 |
| 1573 |
\expandafter\pgfmathfloatadd@\expandafter{\pgfmathresult}{\pgfmath@trunc}% |
| 1574 |
\or |
| 1575 |
% was no-op |
| 1576 |
\let\pgfmathresult=\pgfmath@trunc |
| 1577 |
\else |
| 1578 |
% ok, we have to inspect the remainder: |
| 1579 |
\pgfmathfloatparsenumber{0.\pgfmathfloatintremainder}% |
| 1580 |
\pgfmathfloatifflags{\pgfmathresult}{1}{% |
| 1581 |
% ah - we stripped a non-zero remainder! Round DOWN |
| 1582 |
\pgfmathfloatcreate{2}{1.0}{0}% -1 |
| 1583 |
\expandafter\pgfmathfloatadd@\expandafter{\pgfmathresult}{\pgfmath@trunc}% |
| 1584 |
}{% |
| 1585 |
% was no-op |
| 1586 |
\let\pgfmathresult=\pgfmath@trunc |
| 1587 |
}% |
| 1588 |
\fi |
| 1589 |
}{}% |
| 1590 |
}% |
| 1591 |
\let\pgfmathfloatfloor@=\pgfmathfloatfloor |
| 1592 |
|
| 1593 |
\def\pgfmathfloatceil#1{% |
| 1594 |
\edef\pgfmath@orig{#1}% |
| 1595 |
\pgfmathfloatint@{#1}% |
| 1596 |
\pgfmathfloatifflags{\pgfmath@orig}{1}{% |
| 1597 |
\let\pgfmath@trunc=\pgfmathresult |
| 1598 |
\ifcase\pgfmathfloatintwasnoop\relax |
| 1599 |
% ah - we stripped something! Round UP |
| 1600 |
\pgfmathfloatcreate{1}{1.0}{0}% +1 |
| 1601 |
\expandafter\pgfmathfloatadd@\expandafter{\pgfmathresult}{\pgfmath@trunc}% |
| 1602 |
\or |
| 1603 |
% was no-op |
| 1604 |
\let\pgfmathresult=\pgfmath@trunc |
| 1605 |
\else |
| 1606 |
% ok, we have to inspect the remainder: |
| 1607 |
\pgfmathfloatparsenumber{0.\pgfmathfloatintremainder}% |
| 1608 |
\pgfmathfloatifflags{\pgfmathresult}{1}{% |
| 1609 |
% ah - we stripped a non-zero remainder! Round UP |
| 1610 |
\pgfmathfloatcreate{1}{1.0}{0}% +1 |
| 1611 |
\expandafter\pgfmathfloatadd@\expandafter{\pgfmathresult}{\pgfmath@trunc}% |
| 1612 |
}{% |
| 1613 |
% was no-op |
| 1614 |
\let\pgfmathresult=\pgfmath@trunc |
| 1615 |
}% |
| 1616 |
\fi |
| 1617 |
}{}% |
| 1618 |
}% |
| 1619 |
\let\pgfmathfloatceil@=\pgfmathfloatceil |
| 1620 |
|
| 1621 |
\def\pgfmathfloat@notimplemented#1{% |
| 1622 |
\pgfmath@error{Sorry, the operation '#1' has not yet been implemented in the floating point unit}{}% |
| 1623 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1624 |
}% |
| 1625 |
|
| 1626 |
% Divides or multiplies the input number by 10^#4 using an arithmetic |
| 1627 |
% left/right shift. |
| 1628 |
% |
| 1629 |
% Input: |
| 1630 |
% #1 a normalised floating point number. |
| 1631 |
% #2 a positive or negative integer number denoting the shift. |
| 1632 |
% |
| 1633 |
% Example: |
| 1634 |
% \pgfmathfloatshift{11e3}{4}% |
| 1635 |
% -> pgfmathresult = 11e7 |
| 1636 |
\def\pgfmathfloatshift@#1#2{% |
| 1637 |
\begingroup |
| 1638 |
\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 1639 |
\advance\pgfmathfloat@a@E by#2\relax |
| 1640 |
\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% |
| 1641 |
\pgfmath@smuggleone\pgfmathresult |
| 1642 |
\endgroup |
| 1643 |
}% |
| 1644 |
\let\pgfmathfloatshift=\pgfmathfloatshift@ |
| 1645 |
|
| 1646 |
% Defines \pgfmathresult to be |#1|, the absolute value of the |
| 1647 |
% normalized floating point number #1. |
| 1648 |
\def\pgfmathfloatabs@#1{% |
| 1649 |
\begingroup |
| 1650 |
\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 1651 |
\ifcase\pgfmathfloat@a@S |
| 1652 |
% 0: do nothing. |
| 1653 |
\or |
| 1654 |
% +: ok, is positive. |
| 1655 |
\or |
| 1656 |
% -: multiply with -1: |
| 1657 |
\pgfmathfloat@a@S=1 |
| 1658 |
\or |
| 1659 |
% nan: do nothing. |
| 1660 |
\or |
| 1661 |
% +infty: ok. |
| 1662 |
\or |
| 1663 |
% -infty: multiply with -1: |
| 1664 |
\pgfmathfloat@a@S=4 |
| 1665 |
\fi |
| 1666 |
\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% |
| 1667 |
\pgfmath@smuggleone\pgfmathresult |
| 1668 |
\endgroup |
| 1669 |
}% |
| 1670 |
% |
| 1671 |
% Defines \pgfmathresult to be sign(#1) |
| 1672 |
\def\pgfmathfloatsign@#1{% |
| 1673 |
\begingroup |
| 1674 |
\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 1675 |
\ifcase\pgfmathfloat@a@S |
| 1676 |
% 0: |
| 1677 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1678 |
\or |
| 1679 |
% +: ok, is positive. |
| 1680 |
\pgfmathfloatcreate{1}{1.0}{0}% |
| 1681 |
\or |
| 1682 |
% -: |
| 1683 |
\pgfmathfloatcreate{2}{1.0}{0}% |
| 1684 |
\or |
| 1685 |
% nan: do nothing. |
| 1686 |
\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% |
| 1687 |
\or |
| 1688 |
% +infty:. |
| 1689 |
\pgfmathfloatcreate{1}{1.0}{0}% |
| 1690 |
\or |
| 1691 |
% -infty: |
| 1692 |
\pgfmathfloatcreate{2}{1.0}{0}% |
| 1693 |
\fi |
| 1694 |
\pgfmath@smuggleone\pgfmathresult |
| 1695 |
\endgroup |
| 1696 |
}% |
| 1697 |
\let\pgfmathfloatsign=\pgfmathfloatsign@ |
| 1698 |
|
| 1699 |
% Computes the absolute error |#1 - #2| into \pgfmathresult. |
| 1700 |
\def\pgfmathfloatabserror@#1#2{% |
| 1701 |
\pgfmathfloatsubtract@{#1}{#2}% |
| 1702 |
\pgfmathfloatabs@{\pgfmathresult}% |
| 1703 |
}% |
| 1704 |
\let\pgfmathfloatabserror=\pgfmathfloatabserror@ |
| 1705 |
|
| 1706 |
% Computes the relative error |#1 - #2|/|#2| into \pgfmathresult, |
| 1707 |
% assuming #2 != 0. |
| 1708 |
\def\pgfmathfloatrelerror@#1#2{% |
| 1709 |
\pgfmathfloatsubtract@{#1}{#2}% |
| 1710 |
\let\pgfmathfloat@subtract=\pgfmathresult |
| 1711 |
\pgfmathfloatifflags{#2}{0}{% |
| 1712 |
\let\pgfmathresult=\pgfmathfloat@subtract |
| 1713 |
}{% |
| 1714 |
\pgfmathfloatdivide@{\pgfmathfloat@subtract}{#2}% |
| 1715 |
}% |
| 1716 |
\pgfmathfloatabs@{\pgfmathresult}% |
| 1717 |
}% |
| 1718 |
\let\pgfmathfloatrelerror=\pgfmathfloatrelerror@ |
| 1719 |
|
| 1720 |
% Computes \pgfmathresult = #1 mod #2 using truncated division. |
| 1721 |
% |
| 1722 |
\def\pgfmathfloatmod@#1#2{% |
| 1723 |
\begingroup |
| 1724 |
\pgfmathfloattoint{#1}% |
| 1725 |
\let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 1726 |
\pgfmathfloattoint{#2}% |
| 1727 |
\let\pgfmathfloat@loc@TMPb=\pgfmathresult |
| 1728 |
\c@pgfmath@counta=\pgfmathfloat@loc@TMPa\relax |
| 1729 |
\divide\c@pgfmath@counta by\pgfmathfloat@loc@TMPb\relax |
| 1730 |
\expandafter\pgfmathfloatparsenumber\expandafter{\the\c@pgfmath@counta}% |
| 1731 |
% |
| 1732 |
\let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 1733 |
\pgfmathfloatmultiply@{\pgfmathfloat@loc@TMPa}{#2}% |
| 1734 |
\let\pgfmathfloat@loc@TMPb=\pgfmathresult |
| 1735 |
\pgfmathfloatsubtract@{#1}{\pgfmathfloat@loc@TMPb}% |
| 1736 |
\pgfmath@smuggleone\pgfmathresult |
| 1737 |
\endgroup |
| 1738 |
}% |
| 1739 |
\let\pgfmathfloatmod=\pgfmathfloatmod@ |
| 1740 |
|
| 1741 |
|
| 1742 |
% A modification of \pgfmathfloatmod@ where #3 = 1/#2 is already |
| 1743 |
% known. This may be faster. |
| 1744 |
\def\pgfmathfloatmodknowsinverse@#1#2#3{% |
| 1745 |
\pgfmathfloatmod@{#1}{#2}% |
| 1746 |
%-------------------------------------------------- |
| 1747 |
% \begingroup |
| 1748 |
% % FIXME : is this function correct? \pgfmathfloatmod had a |
| 1749 |
% % rounding flaw... |
| 1750 |
% \pgfmathfloatmultiply@{#1}{#3}% |
| 1751 |
% \pgfmathfloatint@{\pgfmathresult}% |
| 1752 |
% \let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 1753 |
% \pgfmathfloatmultiply@{\pgfmathfloat@loc@TMPa}{#2}% |
| 1754 |
% \let\pgfmathfloat@loc@TMPb=\pgfmathresult |
| 1755 |
% \pgfmathfloatsubtract@{#1}{\pgfmathfloat@loc@TMPb}% |
| 1756 |
% \pgfmath@smuggleone\pgfmathresult |
| 1757 |
% \endgroup |
| 1758 |
%-------------------------------------------------- |
| 1759 |
}% |
| 1760 |
\let\pgfmathfloatmodknowsinverse=\pgfmathfloatmodknowsinverse@ |
| 1761 |
|
| 1762 |
\def\pgfmathfloatpi@{% |
| 1763 |
\pgfmathfloatcreate{1}{3.14159265358979}{0}% |
| 1764 |
}% |
| 1765 |
\let\pgfmathfloatpi=\pgfmathfloatpi@ |
| 1766 |
|
| 1767 |
\def\pgfmathfloate@{% |
| 1768 |
\pgfmathfloatcreate{1}{2.71828182845905}{0}% |
| 1769 |
}% |
| 1770 |
\let\pgfmathfloate=\pgfmathfloate@ |
| 1771 |
|
| 1772 |
% Converts #1 from radians to degrees. |
| 1773 |
\def\pgfmathfloatdeg@#1{% |
| 1774 |
\expandafter\ifx\csname pgfmfltdeg@factor\endcsname\relax |
| 1775 |
% Lazy evaluation: |
| 1776 |
\pgfmathfloatcreate{1}{5.72957795130823}{1}% |
| 1777 |
\global\let\pgfmfltdeg@factor=\pgfmathresult |
| 1778 |
\fi |
| 1779 |
\pgfmathfloatmultiply@{#1}\pgfmfltdeg@factor% |
| 1780 |
}% |
| 1781 |
\let\pgfmathfloatdeg=\pgfmathfloatdeg@ |
| 1782 |
|
| 1783 |
% Converts #1 from degree to radians. |
| 1784 |
\def\pgfmathfloatrad@#1{% |
| 1785 |
\expandafter\ifx\csname pgfmfltrad@factor\endcsname\relax |
| 1786 |
% Lazy evaluation: |
| 1787 |
\pgfmathfloatcreate{1}{1.74532925199433}{-2}% |
| 1788 |
\global\let\pgfmfltrad@factor=\pgfmathresult |
| 1789 |
\fi |
| 1790 |
\pgfmathfloatmultiply@{#1}\pgfmfltrad@factor% |
| 1791 |
}% |
| 1792 |
\let\pgfmathfloatrad=\pgfmathfloatrad@ |
| 1793 |
|
| 1794 |
% Computes #1(#2) where #1 is a trigonometric function, i.e. |
| 1795 |
% #1(#2) = #1( #2 + r*360 ) |
| 1796 |
% |
| 1797 |
% #1 is a one-argument macro which assigns \pgfmathresult. |
| 1798 |
\def\pgfmathfloatTRIG@#1#2{% |
| 1799 |
\if0\pgfmath@trig@format@choice |
| 1800 |
% trig format=deg |
| 1801 |
\expandafter\ifx\csname pgfmathfloatTRIG@NUM\endcsname\relax% |
| 1802 |
% Lazy evaluation: |
| 1803 |
\pgfmathfloatcreate{1}{3.6}{2}% |
| 1804 |
\global\let\pgfmathfloatTRIG@NUM=\pgfmathresult |
| 1805 |
\pgfmathfloatcreate{1}{2.77777777777778}{-3}% |
| 1806 |
\global\let\pgfmathfloatTRIG@NUM@INV=\pgfmathresult |
| 1807 |
\fi |
| 1808 |
\pgfmathfloatmodknowsinverse@{#2}{\pgfmathfloatTRIG@NUM}{\pgfmathfloatTRIG@NUM@INV}% |
| 1809 |
\else |
| 1810 |
% trig format=rad |
| 1811 |
\expandafter\ifx\csname pgfmathfloatTRIG@rad@NUM\endcsname\relax% |
| 1812 |
% Lazy evaluation: |
| 1813 |
\pgfmathfloatcreate{1}{6.28318530717959}{0}% |
| 1814 |
\global\let\pgfmathfloatTRIG@rad@NUM=\pgfmathresult |
| 1815 |
\pgfmathfloatcreate{1}{1.59154943091895}{-1}% |
| 1816 |
\global\let\pgfmathfloatTRIG@rad@NUM@INV=\pgfmathresult |
| 1817 |
\fi |
| 1818 |
\pgfmathfloatmodknowsinverse@{#2}{\pgfmathfloatTRIG@rad@NUM}{\pgfmathfloatTRIG@rad@NUM@INV}% |
| 1819 |
\fi |
| 1820 |
\pgfmathfloattofixed@{\pgfmathresult}% |
| 1821 |
\expandafter#1\expandafter{\pgfmathresult}% |
| 1822 |
\pgfmathfloatparsenumber{\pgfmathresult}% |
| 1823 |
}% |
| 1824 |
|
| 1825 |
\def\pgfmathfloatsin@#1{\pgfmathfloatTRIG@\pgfmath@basic@sin@{#1}}% |
| 1826 |
\let\pgfmathfloatsin=\pgfmathfloatsin@ |
| 1827 |
\def\pgfmathfloatcos@#1{\pgfmathfloatTRIG@\pgfmath@basic@cos@{#1}}% |
| 1828 |
\let\pgfmathfloatcos=\pgfmathfloatcos@ |
| 1829 |
\def\pgfmathfloattan@#1{% |
| 1830 |
% compute sin(#1) / cos(#1) |
| 1831 |
\begingroup |
| 1832 |
\pgfmathfloatcos@{#1}% |
| 1833 |
\let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 1834 |
\pgfmathfloatsin@{#1}% |
| 1835 |
\expandafter\pgfmathfloatdivide@\expandafter{\pgfmathresult}{\pgfmathfloat@loc@TMPa}% |
| 1836 |
\pgfmath@smuggleone\pgfmathresult |
| 1837 |
\endgroup |
| 1838 |
}% |
| 1839 |
\let\pgfmathfloattan=\pgfmathfloattan@ |
| 1840 |
|
| 1841 |
\def\pgfmathfloatcot@#1{% |
| 1842 |
% compute cos(#1) / sin(#1) |
| 1843 |
\begingroup |
| 1844 |
\pgfmathfloatsin@{#1}% |
| 1845 |
\let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 1846 |
\pgfmathfloatcos@{#1}% |
| 1847 |
\expandafter\pgfmathfloatdivide@\expandafter{\pgfmathresult}{\pgfmathfloat@loc@TMPa}% |
| 1848 |
\pgfmath@smuggleone\pgfmathresult |
| 1849 |
\endgroup |
| 1850 |
}% |
| 1851 |
\let\pgfmathfloatcot=\pgfmathfloatcot@ |
| 1852 |
|
| 1853 |
\def\pgfmathfloatatan@#1{% |
| 1854 |
\begingroup |
| 1855 |
\expandafter\ifx\csname pgfmathfloatatan@TMP\endcsname\relax% |
| 1856 |
\pgfmathfloatcreate{1}{1.6}{4}% |
| 1857 |
\global\let\pgfmathfloatatan@TMP=\pgfmathresult |
| 1858 |
\pgfmathfloatcreate{2}{1.6}{4}% |
| 1859 |
\global\let\pgfmathfloatatan@TMPB=\pgfmathresult |
| 1860 |
\fi |
| 1861 |
\pgfmathfloatgreaterthan@{#1}{\pgfmathfloatatan@TMP}% |
| 1862 |
\ifpgfmathfloatcomparison |
| 1863 |
\pgfmathiftrigonometricusesdeg{% |
| 1864 |
\pgfmathfloatcreate{1}{9.0}{1}% |
| 1865 |
}{% |
| 1866 |
\pgfmathfloatcreate{1}{1.570796326794}{0}% |
| 1867 |
}% |
| 1868 |
\else |
| 1869 |
\pgfmathfloatlessthan{#1}{\pgfmathfloatatan@TMPB}% |
| 1870 |
\ifpgfmathfloatcomparison |
| 1871 |
\pgfmathiftrigonometricusesdeg{% |
| 1872 |
\pgfmathfloatcreate{2}{9.0}{1}% |
| 1873 |
}{% |
| 1874 |
\pgfmathfloatcreate{2}{1.570796326794}{0}% |
| 1875 |
}% |
| 1876 |
\else |
| 1877 |
\pgfmathfloattofixed@{#1}% |
| 1878 |
\expandafter\pgfmath@basic@atan@\expandafter{\pgfmathresult}% |
| 1879 |
\pgfmathfloatparsenumber{\pgfmathresult}% |
| 1880 |
\fi |
| 1881 |
\fi |
| 1882 |
\pgfmath@smuggleone\pgfmathresult |
| 1883 |
\endgroup |
| 1884 |
}% |
| 1885 |
\let\pgfmathfloatatan=\pgfmathfloatatan@ |
| 1886 |
|
| 1887 |
\def\pgfmathfloatatantwo#1#2{% |
| 1888 |
% Note: first parameter is y (!), second is x (!) |
| 1889 |
\begingroup% |
| 1890 |
\let\pgfmath@trig@format@choice@@=\pgfmath@trig@format@choice |
| 1891 |
\def\pgfmath@trig@format@choice{0}% |
| 1892 |
% |
| 1893 |
\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 1894 |
\expandafter\pgfmathfloat@decompose#2\relax\pgfmathfloat@b@S\pgfmathfloat@b@M\pgfmathfloat@b@E |
| 1895 |
\ifnum\pgfmathfloat@a@S=0 |
| 1896 |
% ok, #1 = 0. Substitute by 1e-16 such that the next \ifnum catches it: |
| 1897 |
\pgfmathfloat@a@E=-16 % |
| 1898 |
\fi |
| 1899 |
% |
| 1900 |
\ifnum\pgfmathfloat@a@E<-3 % |
| 1901 |
\ifnum\pgfmathfloat@b@S=2 % |
| 1902 |
% #2 < 0 |
| 1903 |
\pgfmathfloatcreate{1}{1.8}{2}% +180 |
| 1904 |
\else |
| 1905 |
\ifnum\pgfmathfloat@b@S=1 % |
| 1906 |
% #2 >0 |
| 1907 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 1908 |
\else |
| 1909 |
% + or - 90, just use the sign of #1: |
| 1910 |
\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{9.0}{1}% |
| 1911 |
\fi |
| 1912 |
\fi |
| 1913 |
\else% |
| 1914 |
\pgfmathfloatabs@{#1}\let\pgfmath@tempa\pgfmathresult% |
| 1915 |
\pgfmathfloatabs@{#2}\let\pgfmath@tempb\pgfmathresult% |
| 1916 |
\pgfmathfloatgreaterthan@{\pgfmath@tempa}{\pgfmath@tempb}% |
| 1917 |
\ifpgfmathfloatcomparison |
| 1918 |
\pgfmathfloatdivide@{#2}{\pgfmath@tempa}% |
| 1919 |
\expandafter\pgfmathfloatatan@\expandafter{\pgfmathresult}% |
| 1920 |
\let\pgfmath@tempa=\pgfmathresult |
| 1921 |
\pgfmathfloatcreate{1}{9.0}{1}% |
| 1922 |
\let\pgfmath@tempb=\pgfmathresult |
| 1923 |
\pgfmathfloatsubtract@{\pgfmath@tempb}{\pgfmath@tempa}% |
| 1924 |
\else% |
| 1925 |
\pgfmathfloatdivide@{\pgfmath@tempa}{#2}% |
| 1926 |
\expandafter\pgfmathfloatatan@\expandafter{\pgfmathresult}% |
| 1927 |
\expandafter\pgfmathfloatifflags\expandafter{\pgfmathresult}{2}{% |
| 1928 |
\let\pgfmath@tempa=\pgfmathresult |
| 1929 |
\pgfmathfloatcreate{1}{1.8}{2}% |
| 1930 |
\let\pgfmath@tempb=\pgfmathresult |
| 1931 |
\pgfmathfloatadd@{\pgfmath@tempa}{\pgfmath@tempb}% |
| 1932 |
}{}% |
| 1933 |
\fi% |
| 1934 |
% |
| 1935 |
\pgfmathfloatifflags{#1}{-}{% |
| 1936 |
% #1 < 0: |
| 1937 |
\pgfmathfloatmultiplyfixed@{\pgfmathresult}{-1}% |
| 1938 |
}{}% |
| 1939 |
\fi% |
| 1940 |
\if1\pgfmath@trig@format@choice@@ |
| 1941 |
% trig format=rad |
| 1942 |
\pgfmathfloat@scale@deg@to@rad\pgfmathresult |
| 1943 |
\fi |
| 1944 |
\pgfmath@smuggleone\pgfmathresult% |
| 1945 |
\endgroup% |
| 1946 |
}% |
| 1947 |
\let\pgfmathfloatatantwo@=\pgfmathfloatatantwo |
| 1948 |
\expandafter\let\csname pgfmathfloatatan2\endcsname=\pgfmathfloatatantwo |
| 1949 |
\expandafter\let\csname pgfmathfloatatan2@\endcsname=\pgfmathfloatatantwo@ |
| 1950 |
|
| 1951 |
\def\pgfmathfloat@scale@deg@to@rad#1{% |
| 1952 |
\edef\pgfmathfloat@loc@TMPb{#1}% |
| 1953 |
\pgfmathfloatcreate{1}{1.74532925199433}{-2}% = pi / 180 |
| 1954 |
\pgfmathfloatmultiply@{\pgfmathresult}{\pgfmathfloat@loc@TMPb}% |
| 1955 |
}% |
| 1956 |
|
| 1957 |
\def\pgfmathfloatsec@#1{\pgfmathfloatTRIG@\pgfmath@basic@cos@{#1}\pgfmathfloatreciprocal@{\pgfmathresult}}% |
| 1958 |
\let\pgfmathfloatsec=\pgfmathfloatsec@ |
| 1959 |
\def\pgfmathfloatcosec@#1{\pgfmathfloatTRIG@\pgfmath@basic@sin@{#1}\pgfmathfloatreciprocal@{\pgfmathresult}}% |
| 1960 |
\let\pgfmathfloatcosec=\pgfmathfloatcosec@ |
| 1961 |
|
| 1962 |
% Expands #2 using \edef and invokes #1 with the resulting string. |
| 1963 |
% |
| 1964 |
% DEPRECATED |
| 1965 |
% Example: |
| 1966 |
% \pgfmath@y=7.9pt |
| 1967 |
% \pgfmathlog@invoke@expanded\pgfmathexp@{{\pgf@sys@tonumber{\pgfmath@y}}}% |
| 1968 |
% will invoke |
| 1969 |
% \pgfmathexp@{7.9} |
| 1970 |
\def\pgfmathlog@invoke@expanded#1#2{% |
| 1971 |
\edef\pgfmath@resulttemp{#2}% |
| 1972 |
\expandafter#1\pgfmath@resulttemp |
| 1973 |
}% |
| 1974 |
|
| 1975 |
\def\pgfmathfloatln@#1{% |
| 1976 |
\pgfmathlog@float{#1}% |
| 1977 |
\ifx\pgfmathresult\pgfutil@empty |
| 1978 |
\pgfmathfloatcreate{3}{0.0}{0}% |
| 1979 |
\else |
| 1980 |
\pgfmathfloatparsenumber{\pgfmathresult}% |
| 1981 |
\fi |
| 1982 |
}% |
| 1983 |
\let\pgfmathfloatln=\pgfmathfloatln@ |
| 1984 |
|
| 1985 |
\expandafter\def\csname pgfmathfloatlog10@\endcsname#1{% |
| 1986 |
\pgfmathfloatln@{#1}% |
| 1987 |
\let\pgfmathfloat@log@e=\pgfmathresult |
| 1988 |
\pgfmathfloatcreate{1}{4.34294481903252}{-1}% 1/ln(10) |
| 1989 |
\pgfmathfloatmultiply@{\pgfmathresult}{\pgfmathfloat@log@e}% |
| 1990 |
}% |
| 1991 |
\pgfutil@namelet{pgfmathfloatlog10}{pgfmathfloatlog10@}% |
| 1992 |
|
| 1993 |
\expandafter\def\csname pgfmathfloatlog2@\endcsname#1{% |
| 1994 |
\pgfmathfloatln@{#1}% |
| 1995 |
\let\pgfmathfloat@log@e=\pgfmathresult |
| 1996 |
\pgfmathfloatcreate{1}{1.44269504088896}{0}% 1/ln(2) |
| 1997 |
\pgfmathfloatmultiply@{\pgfmathresult}{\pgfmathfloat@log@e}% |
| 1998 |
}% |
| 1999 |
\pgfutil@namelet{pgfmathfloatlog2}{pgfmathfloatlog2@}% |
| 2000 |
|
| 2001 |
\expandafter\let\expandafter\pgfmathfloatlogtwo\csname pgfmathfloatlog2\endcsname |
| 2002 |
\expandafter\let\expandafter\pgfmathfloatlogtwo@\csname pgfmathfloatlog2@\endcsname |
| 2003 |
\expandafter\let\expandafter\pgfmathfloatlogten\csname pgfmathfloatlog10\endcsname |
| 2004 |
\expandafter\let\expandafter\pgfmathfloatlogten@\csname pgfmathfloatlog10@\endcsname |
| 2005 |
|
| 2006 |
% Computes log(x) into \pgfmathresult. |
| 2007 |
% |
| 2008 |
% This allows numbers such at 10000000 or 5.23e-10 to be represented |
| 2009 |
% properly, although TeX-registers would produce overflow/underflow |
| 2010 |
% errors in these cases. |
| 2011 |
% |
| 2012 |
% The natural logarithm is computed using log(X*10^Y) = log(X) + log(10)*Y |
| 2013 |
% |
| 2014 |
% FIXME This routine is only kept for backwards compatibility! |
| 2015 |
% It does not work as expected because |
| 2016 |
% 1. it calls \pgfmathfloatparsenumber |
| 2017 |
% 2. it returns the result as fixed point number |
| 2018 |
% Use \pgfmathln@ instead! |
| 2019 |
\def\pgfmathlog@#1{% |
| 2020 |
\pgfmathfloatparsenumber{#1}% |
| 2021 |
\pgfmathlog@float{\pgfmathresult}% |
| 2022 |
}% |
| 2023 |
\let\pgfmathlog=\pgfmathlog@ |
| 2024 |
\def\pgfmathlog@float#1{% |
| 2025 |
\begingroup% |
| 2026 |
% compute #1 = M*10^E with normalised mantissa M = [+-]*[1-9].XXXXX |
| 2027 |
\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 2028 |
\ifnum\pgfmathfloat@a@S=1 |
| 2029 |
% Now, compute log(#1) = log(M) + E*log(10) |
| 2030 |
\expandafter\pgfmath@basic@ln@\expandafter{\the\pgfmathfloat@a@Mtok}% |
| 2031 |
\pgfmathfloat@b@M=\pgfmathresult pt% |
| 2032 |
\pgfmathfloat@a@M=2.302585pt% = log(10) |
| 2033 |
\multiply\pgfmathfloat@a@M by\pgfmathfloat@a@E\relax |
| 2034 |
\advance\pgfmathfloat@b@M by\pgfmathfloat@a@M |
| 2035 |
\edef\pgfmathresult{\pgf@sys@tonumber{\pgfmathfloat@b@M}}% |
| 2036 |
\else |
| 2037 |
\let\pgfmathresult=\pgfutil@empty% |
| 2038 |
\fi |
| 2039 |
\pgfmath@smuggleone\pgfmathresult |
| 2040 |
\endgroup% |
| 2041 |
}% |
| 2042 |
|
| 2043 |
|
| 2044 |
% Computes exp(#1) in floating point. |
| 2045 |
% |
| 2046 |
% The algorithm employs the identity |
| 2047 |
% exp(x) = exp(x - log(10^k) + log(10^k) |
| 2048 |
% = 10^k exp( x - k*log 10 ) |
| 2049 |
% with k chosen such that exp( x - k*log10) can be computed with the |
| 2050 |
% basic level math engine. |
| 2051 |
% |
| 2052 |
% The precision (relative error) is between 10^{-4} and 10^{-6}. For |
| 2053 |
% #1 = 700, it is even 10^{-3}. I will need to improve that someday. |
| 2054 |
\def\pgfmathfloatexp@#1{% |
| 2055 |
\begingroup |
| 2056 |
\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 2057 |
\ifcase\pgfmathfloat@a@S |
| 2058 |
% #1 = 0: |
| 2059 |
\pgfmathfloatcreate{1}{1.0}{0}% |
| 2060 |
\or% #1 > 0 |
| 2061 |
\pgfmathfloatexp@@{#1}% |
| 2062 |
\or% #1 < 0 |
| 2063 |
\pgfmathfloatexp@@{#1}% |
| 2064 |
\else |
| 2065 |
\edef\pgfmathresult{#1}% |
| 2066 |
\fi |
| 2067 |
\pgfmath@smuggleone\pgfmathresult |
| 2068 |
\endgroup |
| 2069 |
}% |
| 2070 |
\def\pgfmathfloatexp@@#1{% |
| 2071 |
% Employ the identity |
| 2072 |
% exp(x) = exp(x - log(10^k) + log(10^k)) = 10^k exp( x - k *log(10)) |
| 2073 |
% |
| 2074 |
% I'd like to have x - k*log(10) <= 1 |
| 2075 |
% => compute k := int( (x - 1) * 1/log(10) ) |
| 2076 |
% that should suffice since \pgfmathexp@ should be |
| 2077 |
% accurate enough for those numbers. |
| 2078 |
% |
| 2079 |
% please note that we can do all this in TeX registers. |
| 2080 |
% exp(700) is almost the maximum of double precision |
| 2081 |
% anyway, and exp(16000) is certainly the largest we will |
| 2082 |
% ever need. |
| 2083 |
\pgfmathfloattofixed@{#1}% |
| 2084 |
\pgf@xa=\pgfmathresult pt |
| 2085 |
\pgf@xa=0.434294481\pgf@xa\relax |
| 2086 |
\edef\pgfmathfloat@loc@TMPa{\pgf@sys@tonumber{\pgf@xa}}% |
| 2087 |
\expandafter\pgfmathfloatexp@@toint\pgfmathfloat@loc@TMPa\relax |
| 2088 |
\pgf@xa=2.302585092pt |
| 2089 |
\multiply\pgf@xa by-\pgfmathfloat@k\relax |
| 2090 |
\advance\pgf@xa by\pgfmathresult pt |
| 2091 |
\edef\pgfmathfloat@loc@TMPa{\pgf@sys@tonumber{\pgf@xa}}% |
| 2092 |
%\message{computing exp(\pgfmathresult) = 10^\pgfmathfloat@k * exp(\pgfmathfloat@loc@TMPa)...}% |
| 2093 |
\pgfmath@basic@exp@{\pgfmathfloat@loc@TMPa}% |
| 2094 |
\let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 2095 |
\pgfmathfloatparsenumber{\pgfmathfloat@loc@TMPa}% |
| 2096 |
\let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 2097 |
\pgfmathfloatshift@{\pgfmathfloat@loc@TMPa}{\pgfmathfloat@k}% |
| 2098 |
}% |
| 2099 |
% determine 'k'. This is a heuristics. The exponential series |
| 2100 |
% converges best for |x| <= 1. However, the fixed point arithmetic |
| 2101 |
% for tex results in best results for large |x|. Well, I'll need to |
| 2102 |
% tune this here. |
| 2103 |
\def\pgfmathfloatexp@@toint#1.#2\relax{% |
| 2104 |
\c@pgf@counta=#1\relax |
| 2105 |
\ifnum\c@pgf@counta<0 |
| 2106 |
\advance\c@pgf@counta by-1 % FIXME . this is a test for optimizations. |
| 2107 |
\c@pgf@countb=#2\relax |
| 2108 |
\ifnum\c@pgf@countb>0 |
| 2109 |
\advance\c@pgf@counta by-1 |
| 2110 |
\fi |
| 2111 |
\fi |
| 2112 |
\edef\pgfmathfloat@k{\the\c@pgf@counta}% |
| 2113 |
}% |
| 2114 |
\let\pgfmathfloatexp=\pgfmathfloatexp@ |
| 2115 |
|
| 2116 |
\def\pgfmathfloatround@#1{% |
| 2117 |
\begingroup |
| 2118 |
\pgfkeysvalueof{/pgf/number format/precision/.@cmd}0\pgfeov |
| 2119 |
\pgfmathfloattofixed{#1}% |
| 2120 |
\pgfmathroundto{\pgfmathresult}% |
| 2121 |
\pgfmathfloatparsenumber{\pgfmathresult}% |
| 2122 |
\pgfmath@smuggleone\pgfmathresult |
| 2123 |
\endgroup |
| 2124 |
}% |
| 2125 |
|
| 2126 |
|
| 2127 |
\def\pgfmathfloatneg@#1{% |
| 2128 |
\begingroup |
| 2129 |
\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 2130 |
\ifcase\pgfmathfloat@a@S\relax |
| 2131 |
% 0: |
| 2132 |
\edef\pgfmathresult{#1}% |
| 2133 |
\or |
| 2134 |
% +: |
| 2135 |
\pgfmathfloatcreate{2}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% |
| 2136 |
\or |
| 2137 |
% -: |
| 2138 |
\pgfmathfloatcreate{1}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% |
| 2139 |
\or |
| 2140 |
% nan: |
| 2141 |
\edef\pgfmathresult{#1}% |
| 2142 |
\or |
| 2143 |
% +infty: |
| 2144 |
\pgfmathfloatcreate{5}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% |
| 2145 |
\or |
| 2146 |
% -infty: |
| 2147 |
\pgfmathfloatcreate{4}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% |
| 2148 |
\fi |
| 2149 |
\pgfmath@smuggleone\pgfmathresult |
| 2150 |
\endgroup |
| 2151 |
}% |
| 2152 |
|
| 2153 |
|
| 2154 |
\def\pgfmathfloatpow@#1#2{% |
| 2155 |
\begingroup% |
| 2156 |
\expandafter\pgfmathfloat@decompose@tok#2\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E |
| 2157 |
\ifcase\pgfmathfloat@a@S\relax |
| 2158 |
% #1 ^ 0 = 1 |
| 2159 |
\pgfmathfloatcreate{1}{1.0}{0}% |
| 2160 |
\or |
| 2161 |
% #2 > 0 |
| 2162 |
\pgfmathfloatpow@@{#1}{#2}% |
| 2163 |
\or |
| 2164 |
% #2 < 0 |
| 2165 |
\pgfmathfloatpow@@{#1}{#2}% |
| 2166 |
\or |
| 2167 |
% #2 = nan |
| 2168 |
\edef\pgfmathresult{#2}% |
| 2169 |
\or |
| 2170 |
% #2 = inf |
| 2171 |
\edef\pgfmathresult{#2}% |
| 2172 |
\or |
| 2173 |
% #2 = -inf |
| 2174 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 2175 |
\fi |
| 2176 |
\pgfmath@smuggleone\pgfmathresult |
| 2177 |
\endgroup |
| 2178 |
}% |
| 2179 |
|
| 2180 |
% computes #1^#2 |
| 2181 |
% PRECONDITIONS |
| 2182 |
% - #2 is positive. |
| 2183 |
\def\pgfmathfloatpow@@#1#2{% |
| 2184 |
\pgfmathfloattofixed@{#2}% |
| 2185 |
\afterassignment\pgfmath@x% |
| 2186 |
\expandafter\c@pgfmath@counta\pgfmathresult pt\relax% |
| 2187 |
\ifdim\pgfmath@x=0pt % |
| 2188 |
% loop "manually"; we have an integer exponent! |
| 2189 |
\ifnum\c@pgfmath@counta<0 |
| 2190 |
\pgfmathfloatreciprocal@{#1}% |
| 2191 |
\let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 2192 |
\c@pgfmath@counta=-\c@pgfmath@counta |
| 2193 |
\else |
| 2194 |
\edef\pgfmathfloat@loc@TMPa{#1}% |
| 2195 |
\fi |
| 2196 |
\pgfmathfloatcreate{1}{1.0}{0}% |
| 2197 |
\let\pgfmathfloat@loc@TMPb=\pgfmathresult |
| 2198 |
\pgfmathloop |
| 2199 |
\ifnum\c@pgfmath@counta>0\relax% |
| 2200 |
\ifodd\c@pgfmath@counta% |
| 2201 |
\pgfmathfloatmultiply@{\pgfmathfloat@loc@TMPb}{\pgfmathfloat@loc@TMPa}% |
| 2202 |
\let\pgfmathfloat@loc@TMPb=\pgfmathresult |
| 2203 |
\fi |
| 2204 |
\ifnum\c@pgfmath@counta>1\relax% |
| 2205 |
\pgfmathfloatmultiply@{\pgfmathfloat@loc@TMPa}{\pgfmathfloat@loc@TMPa}% |
| 2206 |
\let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 2207 |
\fi% |
| 2208 |
\divide\c@pgfmath@counta by2\relax% |
| 2209 |
\repeatpgfmathloop% |
| 2210 |
\else |
| 2211 |
\pgfmathfloatgetflags{#1}\c@pgfmath@counta |
| 2212 |
\ifnum0=\c@pgfmath@counta |
| 2213 |
% ah: 0^x |
| 2214 |
\pgfmathfloatgetflags{#2}\c@pgfmath@counta |
| 2215 |
\ifnum0=\c@pgfmath@counta |
| 2216 |
% ah: 0^0 |
| 2217 |
\pgfmathfloatcreate{1}{1.0}{0}% |
| 2218 |
\else |
| 2219 |
% ah: 0^x with x!=0: |
| 2220 |
\pgfmathfloatcreate{0}{0.0}{0}% |
| 2221 |
\fi |
| 2222 |
\else |
| 2223 |
% employ #1^#2 = exp( #2 * ln(#1) ) |
| 2224 |
\pgfmathfloatln@{#1}% |
| 2225 |
\let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 2226 |
\edef\pgfmathfloat@loc@TMPb{#2}% |
| 2227 |
\pgfmathfloatmultiply@{\pgfmathfloat@loc@TMPa}{\pgfmathfloat@loc@TMPb}% |
| 2228 |
\pgfmathfloatexp@{\pgfmathresult}% |
| 2229 |
\fi |
| 2230 |
\fi |
| 2231 |
}% |
| 2232 |
|
| 2233 |
\def\pgfmathfloat@definemethodfrombasic@NOARG#1{% |
| 2234 |
\pgfutil@ifundefined{pgfmath@basic@#1@}{% |
| 2235 |
\pgfutil@namelet{pgfmath@basic@#1@}{pgfmath#1@}% |
| 2236 |
}{}% |
| 2237 |
\edef\pgfmathfloat@glob@TMP{% |
| 2238 |
\expandafter\noexpand\csname pgfmath@basic@#1@\endcsname |
| 2239 |
\noexpand\pgfmathfloatparsenumber{\noexpand\pgfmathresult}% |
| 2240 |
}% |
| 2241 |
\expandafter\let\csname pgfmathfloat#1@\endcsname=\pgfmathfloat@glob@TMP% |
| 2242 |
\expandafter\let\csname pgfmathfloat#1\endcsname=\pgfmathfloat@glob@TMP% |
| 2243 |
}% |
| 2244 |
\def\pgfmathfloat@definemethodfrombasic@ONEARG#1{% |
| 2245 |
\pgfutil@ifundefined{pgfmath@basic@#1@}{% |
| 2246 |
\pgfutil@namelet{pgfmath@basic@#1@}{pgfmath#1@}% |
| 2247 |
}{}% |
| 2248 |
\edef\pgfmathfloat@glob@TMP##1{% |
| 2249 |
\noexpand\pgfmathfloattofixed{##1}% |
| 2250 |
\noexpand\expandafter |
| 2251 |
\expandafter\noexpand\csname pgfmath@basic@#1@\endcsname\noexpand\expandafter% |
| 2252 |
{\noexpand\pgfmathresult}% |
| 2253 |
\noexpand\pgfmathfloatparsenumber{\noexpand\pgfmathresult}% |
| 2254 |
}% |
| 2255 |
\expandafter\let\csname pgfmathfloat#1@\endcsname=\pgfmathfloat@glob@TMP% |
| 2256 |
\expandafter\let\csname pgfmathfloat#1\endcsname=\pgfmathfloat@glob@TMP% |
| 2257 |
}% |
| 2258 |
\def\pgfmathfloat@definemethodfrombasic@TWOARGS#1{% |
| 2259 |
\pgfutil@ifundefined{pgfmath@basic@#1@}{% |
| 2260 |
\pgfutil@namelet{pgfmath@basic@#1@}{pgfmath#1@}% |
| 2261 |
}{}% |
| 2262 |
\edef\pgfmathfloat@glob@TMP##1##2{% |
| 2263 |
\noexpand\pgfmathfloattofixed{##2}% |
| 2264 |
\noexpand\let\noexpand\pgfmathfloat@loc@TMPa=\noexpand\pgfmathresult |
| 2265 |
\noexpand\pgfmathfloattofixed{##1}% |
| 2266 |
\noexpand\expandafter |
| 2267 |
\expandafter\noexpand\csname pgfmath@basic@#1@\endcsname\noexpand\expandafter% |
| 2268 |
{\noexpand\pgfmathresult}{\noexpand\pgfmathfloat@loc@TMPa}% |
| 2269 |
\noexpand\pgfmathfloatparsenumber{\noexpand\pgfmathresult}% |
| 2270 |
}% |
| 2271 |
\expandafter\let\csname pgfmathfloat#1@\endcsname=\pgfmathfloat@glob@TMP% |
| 2272 |
\expandafter\let\csname pgfmathfloat#1\endcsname=\pgfmathfloat@glob@TMP% |
| 2273 |
}% |
| 2274 |
\pgfmathfloat@definemethodfrombasic@NOARG{rand}% |
| 2275 |
\pgfmathfloat@definemethodfrombasic@NOARG{rnd}% |
| 2276 |
\pgfmathfloat@definemethodfrombasic@NOARG{false}% |
| 2277 |
\pgfmathfloat@definemethodfrombasic@NOARG{true}% |
| 2278 |
% arcsin, arccos |
| 2279 |
\pgfmathfloat@definemethodfrombasic@ONEARG{asin}% |
| 2280 |
\pgfmathfloat@definemethodfrombasic@ONEARG{acos}% |
| 2281 |
\pgfmathfloat@definemethodfrombasic@ONEARG{not}% |
| 2282 |
\pgfmathfloat@definemethodfrombasic@ONEARG{hex}% |
| 2283 |
\pgfmathfloat@definemethodfrombasic@ONEARG{Hex}% |
| 2284 |
\pgfmathfloat@definemethodfrombasic@ONEARG{oct}% |
| 2285 |
\pgfmathfloat@definemethodfrombasic@ONEARG{bin}% |
| 2286 |
\pgfmathfloat@definemethodfrombasic@TWOARGS{and}% |
| 2287 |
\pgfmathfloat@definemethodfrombasic@TWOARGS{or}% |
| 2288 |
|
| 2289 |
\pgfutil@ifundefined{pgfmathdeclarefunction}{% |
| 2290 |
% special treatment: \pgfmathrand@ was not properly defined for pgf 2.00: |
| 2291 |
\let\pgfmath@basic@rand=\pgfmathrand |
| 2292 |
\let\pgfmath@basic@rand@=\pgfmathrand@ |
| 2293 |
\def\pgfmathfloatrand@{% |
| 2294 |
\pgfmath@basic@rand |
| 2295 |
\pgfmathfloatparsenumber{\pgfmathresult}% |
| 2296 |
}% |
| 2297 |
\let\pgfmathfloatrand=\pgfmathfloatrand@% |
| 2298 |
% |
| 2299 |
% special treatment: \pgfmathrnd@ was not properly defined for pgf 2.00: |
| 2300 |
\let\pgfmath@basic@rnd=\pgfmathrnd |
| 2301 |
\let\pgfmath@basic@rnd@=\pgfmathrnd@ |
| 2302 |
\def\pgfmathfloatrnd@{% |
| 2303 |
\pgfmath@basic@rnd |
| 2304 |
\pgfmathfloatparsenumber{\pgfmathresult}% |
| 2305 |
}% |
| 2306 |
\let\pgfmathfloatrnd=\pgfmathfloatrnd@% |
| 2307 |
}{}% |
| 2308 |
|
| 2309 |
% Implements the factorial of '#1'. |
| 2310 |
% This does only work if '#1 < 2^32'. |
| 2311 |
\def\pgfmathfloatfactorial@#1{% |
| 2312 |
\begingroup |
| 2313 |
\pgfmathfloattofixed{#1}% |
| 2314 |
% collect integer part into a 32 bit register: |
| 2315 |
\afterassignment\pgfmath@gobbletilpgfmath@% |
| 2316 |
\expandafter\c@pgfmath@counta\pgfmathresult\relax\pgfmath@% |
| 2317 |
\pgfmathfloatcreate{1}{1.0}{0}% |
| 2318 |
\let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 2319 |
\pgfmathloop |
| 2320 |
\ifnum\c@pgfmath@counta<2 % |
| 2321 |
\else |
| 2322 |
\expandafter\pgfmathfloatparsenumber\expandafter{\the\c@pgfmath@counta}% |
| 2323 |
\expandafter\pgfmathfloatmultiply@\expandafter{\pgfmathresult}{\pgfmathfloat@loc@TMPa}% |
| 2324 |
\let\pgfmathfloat@loc@TMPa=\pgfmathresult |
| 2325 |
\advance\c@pgfmath@counta by-1\relax% |
| 2326 |
\repeatpgfmathloop |
| 2327 |
\pgfmath@smuggleone\pgfmathresult |
| 2328 |
\endgroup |
| 2329 |
}% |
| 2330 |
|
| 2331 |
% Implements the vector length of a 2D vector. |
| 2332 |
% |
| 2333 |
% ATTENTION: this does NOT use the improved code of the basic layer! |
| 2334 |
% It simply computed sqrt( #1^2 + #2^2 )! |
| 2335 |
\def\pgfmathfloatveclen@#1#2{% |
| 2336 |
\begingroup |
| 2337 |
\edef\pgfmathfloat@@a{#1}% |
| 2338 |
\pgfmathfloatmultiply@{\pgfmathfloat@@a}{\pgfmathfloat@@a}% |
| 2339 |
\let\pgfmathfloat@@a=\pgfmathresult |
| 2340 |
% |
| 2341 |
\edef\pgfmathfloat@@b{#2}% |
| 2342 |
\pgfmathfloatmultiply@{\pgfmathfloat@@b}{\pgfmathfloat@@b}% |
| 2343 |
\let\pgfmathfloat@@b=\pgfmathresult |
| 2344 |
% |
| 2345 |
\pgfmathfloatadd@{\pgfmathfloat@@a}{\pgfmathfloat@@b}% |
| 2346 |
\pgfmathfloatsqrt@{\pgfmathresult}% |
| 2347 |
\pgfmath@smuggleone\pgfmathresult |
| 2348 |
\endgroup |
| 2349 |
}% |
| 2350 |
|
| 2351 |
\def\pgfmathfloatcosh@#1{% |
| 2352 |
\begingroup |
| 2353 |
\pgfmathfloatexp@{#1}% |
| 2354 |
\let\pgfmathfloat@@a=\pgfmathresult |
| 2355 |
% |
| 2356 |
\pgfmathfloatneg@{#1}% |
| 2357 |
\pgfmathfloatexp@{\pgfmathresult}% |
| 2358 |
% |
| 2359 |
\pgfmathfloatadd@{\pgfmathresult}{\pgfmathfloat@@a}% |
| 2360 |
\expandafter\pgfmathfloatmultiplyfixed@\expandafter{\pgfmathresult}{0.5}% |
| 2361 |
% |
| 2362 |
\pgfmath@smuggleone\pgfmathresult |
| 2363 |
\endgroup |
| 2364 |
}% |
| 2365 |
\def\pgfmathfloatsinh@#1{% |
| 2366 |
\begingroup |
| 2367 |
\pgfmathfloatexp@{#1}% |
| 2368 |
\let\pgfmathfloat@@a=\pgfmathresult |
| 2369 |
% |
| 2370 |
\pgfmathfloatneg@{#1}% |
| 2371 |
\pgfmathfloatexp@{\pgfmathresult}% |
| 2372 |
% |
| 2373 |
\pgfmathfloatsubtract@{\pgfmathfloat@@a}{\pgfmathresult}% |
| 2374 |
\expandafter\pgfmathfloatmultiplyfixed@\expandafter{\pgfmathresult}{0.5}% |
| 2375 |
% |
| 2376 |
\pgfmath@smuggleone\pgfmathresult |
| 2377 |
\endgroup |
| 2378 |
}% |
| 2379 |
\def\pgfmathfloattanh@#1{% |
| 2380 |
\begingroup |
| 2381 |
\pgfmathfloatsinh@{#1}% |
| 2382 |
\let\pgfmathfloat@@a=\pgfmathresult |
| 2383 |
% |
| 2384 |
\pgfmathfloatcosh@{#1}% |
| 2385 |
\let\pgfmathfloat@@b=\pgfmathresult |
| 2386 |
% |
| 2387 |
\pgfmathfloatdivide@{\pgfmathfloat@@a}{\pgfmathfloat@@b}% |
| 2388 |
% |
| 2389 |
\pgfmath@smuggleone\pgfmathresult |
| 2390 |
\endgroup |
| 2391 |
}% |
| 2392 |
\endinput |