| 1 |
% This is (almost) exact copy of |
| 2 |
% fp-basic.sty package (Michael Mehlich) |
| 3 |
% |
| 4 |
% It is patched to work with multido.sty |
| 5 |
% FPadd -> FPfadd |
| 6 |
% FPsub -> FPfsub |
| 7 |
|
| 8 |
\NeedsTeXFormat{LaTeX2e} |
| 9 |
\ProvidesPackage{pstfp}[2003/05/10] |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
%version information |
| 14 |
\def\FP@basicversion{1.2d} |
| 15 |
\message{% |
| 16 |
`(Patched) Basic Fixed Point Arithmetic',\space\space% |
| 17 |
|
| 18 |
Version \FP@basicversion% |
| 19 |
\space(C) Michael Mehlich% |
| 20 |
|
| 21 |
\space Patched by R. Stepanyan% |
| 22 |
\space\space\space\space\space\space\space% |
| 23 |
\space\space\space\space\space\space% |
| 24 |
} |
| 25 |
|
| 26 |
%fixed point arithmetic with values between (including) |
| 27 |
% -999999999999999999.999999999999999999 |
| 28 |
% and +999999999999999999.999999999999999999 |
| 29 |
|
| 30 |
|
| 31 |
% to suppress messages |
| 32 |
\let\FP@save@message\message |
| 33 |
\def\message#1{} |
| 34 |
|
| 35 |
|
| 36 |
%%%public area (macros which may be used)%%% |
| 37 |
|
| 38 |
%introduce and print new values |
| 39 |
\def\FPset#1#2{\FP@set[#1|#2]} |
| 40 |
\def\FPprint#1{\FP@print[#1]} |
| 41 |
|
| 42 |
%binary operations |
| 43 |
\def\FPfadd#1#2#3{\FP@callc\FP@add#1{#2}{#3}+\relax} % #1 := #2+#3 |
| 44 |
\def\FPdiv#1#2#3{\FP@callc\FP@div#1{#2}{#3}} % #1 := #2/#3 |
| 45 |
\def\FPmul#1#2#3{\FP@callc\FP@mul#1{#2}{#3}} % #1 := #2*#3 |
| 46 |
\def\FPfsub#1#2#3{\FP@callc\FP@add#1{#2}{-#3}-\relax}% #1 := #2-#3 |
| 47 |
%unary operations |
| 48 |
\def\FPabs#1#2{\FP@calld\FP@abs#1{#2}} % #1 := abs(#2) |
| 49 |
\def\FPneg#1#2{\FP@calld\FP@neg#1{#2}} % #1 := -#2 |
| 50 |
\def\FPsgn#1#2{\FP@calld\FP@sgn#1{#2}} % #1 := sgn(#2) |
| 51 |
%binary relations |
| 52 |
\def\FPiflt#1#2{\FP@callb\FP@iflt{#1}{#2}+\relax} % #1 < #2 ? |
| 53 |
\def\FPifeq#1#2{\FP@callb\FP@ifeq{#1}{#2}} % #1 = #2 ? |
| 54 |
\def\FPifgt#1#2{\FP@callb\FP@iflt{#2}{#1}-\relax} % #1 > #2 ? |
| 55 |
%unary relations |
| 56 |
\def\FPifneg#1{\FP@calla\FP@ifneg{#1}} % #1 < 0 ? |
| 57 |
\def\FPifpos#1{\FP@calla\FP@ifpos{#1}} % #1 >= 0 ? |
| 58 |
\def\FPifzero#1{\FP@calla\FP@ifzero{#1}} % #1 = 0 ? |
| 59 |
\def\FPifint#1{\FP@calla\FP@ifint{#1}} % #1 is integer ? |
| 60 |
%repeat last test |
| 61 |
%\ifFPtest % repeat last test |
| 62 |
|
| 63 |
%%%private fp-area (don't use these macros)%%% |
| 64 |
|
| 65 |
% To debug FP functions (enable intermediate messages on computations) |
| 66 |
\newif\ifFPdebug |
| 67 |
\FPdebugfalse |
| 68 |
\def\FP@debug#1{\ifFPdebug\typeout{FP debug: #1}\fi} |
| 69 |
|
| 70 |
%conditional printing of messages (only if \FPmessagestrue defined) |
| 71 |
\newif\ifFPmessages |
| 72 |
\FPmessagestrue |
| 73 |
\def\FP@beginmessage#1{\ifFPmessages\message{( FP-#1}\fi} |
| 74 |
\def\FP@endmessage#1{\ifFPmessages\message{)}\fi} |
| 75 |
\def\FP@errmessage#1{\errmessage{FP error: #1!}} |
| 76 |
\def\FP@warnmessage#1{\message{FP warning: #1!}} |
| 77 |
|
| 78 |
%allocation of registers |
| 79 |
|
| 80 |
\countdef\FP@actcounter=10 % register 0 for counter |
| 81 |
\ifnum\FP@actcounter<60\relax% |
| 82 |
\FP@actcounter=60% |
| 83 |
\fi |
| 84 |
|
| 85 |
\newcount\FP@xs %sign of 1st value |
| 86 |
\newcount\FP@xia%integer part of 1st value |
| 87 |
\newcount\FP@xib%integer part of 1st value |
| 88 |
\newcount\FP@xfa%fractional part of 1st value |
| 89 |
\newcount\FP@xfb%fractional part of 1st value |
| 90 |
|
| 91 |
\countdef\FP@ys=5 %sign of 2nd value |
| 92 |
\countdef\FP@yia=6%integer part of 2nd value |
| 93 |
\countdef\FP@yib=7%integer part of 2nd value |
| 94 |
\countdef\FP@yfa=8%fractional part of 2nd value |
| 95 |
\countdef\FP@yfb=9%fractional part of 2nd value |
| 96 |
|
| 97 |
\countdef\FP@xk=10 %registers for splitting 1st value |
| 98 |
\countdef\FP@xl=11 |
| 99 |
\countdef\FP@xm=12 |
| 100 |
\countdef\FP@xn=13 |
| 101 |
\countdef\FP@xo=14 |
| 102 |
\countdef\FP@xp=15 |
| 103 |
\countdef\FP@xq=16 |
| 104 |
\countdef\FP@xr=17 |
| 105 |
\countdef\FP@xz=18 |
| 106 |
\countdef\FP@xt=19 |
| 107 |
\countdef\FP@xu=20 |
| 108 |
\countdef\FP@xv=21 |
| 109 |
|
| 110 |
\countdef\FP@yk=22 %registers for splitting 2nd value |
| 111 |
\countdef\FP@yl=23 |
| 112 |
\countdef\FP@ym=24 |
| 113 |
\countdef\FP@yn=25 |
| 114 |
\countdef\FP@yo=26 |
| 115 |
\countdef\FP@yp=27 |
| 116 |
\countdef\FP@yq=28 |
| 117 |
\countdef\FP@yr=29 |
| 118 |
\countdef\FP@yz=30 |
| 119 |
\countdef\FP@yt=31 |
| 120 |
\countdef\FP@yu=32 |
| 121 |
\countdef\FP@yv=33 |
| 122 |
|
| 123 |
\newcount\FP@rega %auxiliary registers |
| 124 |
\newcount\FP@regb |
| 125 |
\countdef\FP@regc=36 |
| 126 |
\countdef\FP@regd=37 |
| 127 |
\countdef\FP@rege=38 |
| 128 |
|
| 129 |
\countdef\FP@rs=39 %result registers |
| 130 |
\countdef\FP@ria=40 |
| 131 |
\countdef\FP@rib=41 |
| 132 |
\countdef\FP@rfa=42 |
| 133 |
\countdef\FP@rfb=43 |
| 134 |
|
| 135 |
\newcount\FP@regs %local auxiliary registers |
| 136 |
\countdef\FP@count=45 |
| 137 |
\countdef\FP@res=46 |
| 138 |
\countdef\FP@shift=47 |
| 139 |
\newcount\FP@times |
| 140 |
\countdef\FP@prod=49 |
| 141 |
|
| 142 |
%set values |
| 143 |
\def\FP@set[#1#2|#3#4]{% |
| 144 |
\ifx#3\@undefined% |
| 145 |
\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\FP@tmp\expandafter\expandafter\expandafter{\csname #3#4\endcsname}% |
| 146 |
\else\ifcat\noexpand#3\relax% |
| 147 |
\expandafter\def\expandafter\FP@tmp\expandafter{#3#4}% |
| 148 |
\else\ifcat#32\relax% |
| 149 |
\expandafter\def\expandafter\FP@tmp\expandafter{#3#4}% |
| 150 |
\else% |
| 151 |
\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\FP@tmp\expandafter\expandafter\expandafter{\csname #3#4\endcsname}% |
| 152 |
\fi\fi\fi% |
| 153 |
\ifx#1\@undefined% |
| 154 |
\let#1\FP@tmp% |
| 155 |
\else\ifcat\noexpand#1\relax% |
| 156 |
\let#1\FP@tmp% |
| 157 |
\else% |
| 158 |
\expandafter\let\csname #1#2\endcsname\FP@tmp% |
| 159 |
\fi\fi% |
| 160 |
} |
| 161 |
|
| 162 |
%print values |
| 163 |
\def\FP@print[#1#2]{% |
| 164 |
\ifx#1\@undefined% |
| 165 |
\csname #1#2\endcsname% |
| 166 |
\else\ifcat\noexpand#1\relax% |
| 167 |
#1#2% |
| 168 |
\else\ifcat#12\relax% |
| 169 |
#1#2% |
| 170 |
\else% |
| 171 |
\csname #1#2\endcsname% |
| 172 |
\fi\fi\fi% |
| 173 |
} |
| 174 |
|
| 175 |
%auxiliary macros which may be used in all of the following macros |
| 176 |
\newif\ifFP@test |
| 177 |
|
| 178 |
\def\FP@ignorenext#1{} |
| 179 |
\def\FP@first#1#2\relax{#1} |
| 180 |
\def\FP@swallow#1\relax{} |
| 181 |
|
| 182 |
\def\ifFP@zero#1{% |
| 183 |
\ifnum% |
| 184 |
\expandafter\ifnum\csname FP@#1ia\endcsname=0 0\else1\fi% |
| 185 |
\expandafter\ifnum\csname FP@#1ib\endcsname=0 0\else1\fi% |
| 186 |
\expandafter\ifnum\csname FP@#1fa\endcsname=0 0\else1\fi% |
| 187 |
\expandafter\ifnum\csname FP@#1fb\endcsname=0 0\else1\fi% |
| 188 |
=0\relax% |
| 189 |
} |
| 190 |
|
| 191 |
%read value |
| 192 |
|
| 193 |
\def\FP@correctintcounter#1\relax{% |
| 194 |
{\edef\FP@tmp{#1}% |
| 195 |
\FP@count=0\relax% |
| 196 |
\loop% |
| 197 |
\edef\FP@tmpa{\expandafter\FP@first\FP@tmp\noexpand\relax}% |
| 198 |
\expandafter\ifx\FP@tmpa0\relax% |
| 199 |
\advance\FP@count1\relax% |
| 200 |
\edef\FP@tmp{\expandafter\FP@ignorenext\FP@tmp}% |
| 201 |
\repeat% |
| 202 |
\ifnum\FP@count>18\relax% |
| 203 |
\FP@errmessage{Overflow}% |
| 204 |
\fi% |
| 205 |
\expandafter\if!\FP@tmp!% |
| 206 |
\advance\FP@count-18\relax% |
| 207 |
\FP@count=-\FP@count% |
| 208 |
\loop% |
| 209 |
\ifnum\FP@count>0\relax% |
| 210 |
\FP@regc=\FP@rega% |
| 211 |
\divide\FP@rega10\relax\multiply\FP@rega10\relax% |
| 212 |
\advance\FP@regc-\FP@rega\multiply\FP@regc100000000\relax% |
| 213 |
\divide\FP@rega10\relax% |
| 214 |
\divide\FP@regb10\relax\advance\FP@regb\FP@regc% |
| 215 |
\advance\FP@count-1\relax% |
| 216 |
\repeat% |
| 217 |
\global\FP@rega=\FP@rega% |
| 218 |
\global\FP@regb=\FP@regb% |
| 219 |
\else% |
| 220 |
\FP@errmessage{Number too big}% |
| 221 |
\fi% |
| 222 |
}% |
| 223 |
} |
| 224 |
\def\FP@@setintcounter#1#2#3#4#5#6#7#8#9{% |
| 225 |
\FP@regb=#1#2#3#4#5#6#7#8#9\relax% |
| 226 |
\FP@correctintcounter% |
| 227 |
} |
| 228 |
\def\FP@setintcounter#1#2#3#4#5#6#7#8#9{% |
| 229 |
\FP@rega=#1#2#3#4#5#6#7#8#9\relax% |
| 230 |
\FP@@setintcounter% |
| 231 |
} |
| 232 |
|
| 233 |
\def\FP@@setfractcounter#1#2#3#4#5#6#7#8#9{% |
| 234 |
\FP@regb=#1#2#3#4#5#6#7#8#9\relax% |
| 235 |
\FP@swallow% |
| 236 |
} |
| 237 |
\def\FP@setfractcounter#1#2#3#4#5#6#7#8#9{% |
| 238 |
\FP@rega=#1#2#3#4#5#6#7#8#9\relax% |
| 239 |
\FP@@setfractcounter% |
| 240 |
} |
| 241 |
|
| 242 |
\def\FP@getsign#1\relax{% |
| 243 |
{\FP@regs=1\relax% |
| 244 |
\edef\FP@tmp{#1}% |
| 245 |
\loop% |
| 246 |
\edef\FP@tmpa{\expandafter\FP@first\FP@tmp\noexpand\relax}% |
| 247 |
\expandafter\ifx\FP@tmpa-\relax% |
| 248 |
\multiply\FP@regs-1\relax% |
| 249 |
\fi% |
| 250 |
\ifnum\expandafter\ifx\FP@tmpa-1\else0\fi\expandafter\ifx\FP@tmpa+1\else0\fi>0% |
| 251 |
\edef\FP@tmp{\expandafter\FP@ignorenext\FP@tmp}% |
| 252 |
\repeat% |
| 253 |
\global\let\FP@tmp\FP@tmp% |
| 254 |
\global\FP@regs=\FP@regs% |
| 255 |
}% |
| 256 |
} |
| 257 |
|
| 258 |
\def\FP@removeleadingzeros#1\relax{% |
| 259 |
{\edef\FP@tmp{#1}% |
| 260 |
\loop% |
| 261 |
\edef\FP@tmpa{\expandafter\FP@first\FP@tmp\noexpand\relax}% |
| 262 |
\expandafter\ifx\FP@tmpa0\relax% |
| 263 |
\edef\FP@tmp{\expandafter\FP@ignorenext\FP@tmp}% |
| 264 |
\repeat% |
| 265 |
\global\let\FP@tmp\FP@tmp% |
| 266 |
}% |
| 267 |
} |
| 268 |
|
| 269 |
\newif\ifFP@nonstop |
| 270 |
\def\FP@strip#1{% |
| 271 |
{\edef\FP@tmp{#1}% |
| 272 |
\edef\FP@tmpb{}% |
| 273 |
\ifx\FP@tmp\@empty\else% |
| 274 |
\FP@nonstoptrue% |
| 275 |
\loop% |
| 276 |
\edef\FP@tmpa{\expandafter\FP@first\FP@tmp\noexpand\relax}% |
| 277 |
\expandafter\ifx\FP@tmpa-\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 278 |
\expandafter\ifx\FP@tmpa+\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 279 |
\expandafter\ifx\FP@tmpa0\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 280 |
\expandafter\ifx\FP@tmpa1\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 281 |
\expandafter\ifx\FP@tmpa2\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 282 |
\expandafter\ifx\FP@tmpa3\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 283 |
\expandafter\ifx\FP@tmpa4\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 284 |
\expandafter\ifx\FP@tmpa5\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 285 |
\expandafter\ifx\FP@tmpa6\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 286 |
\expandafter\ifx\FP@tmpa7\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 287 |
\expandafter\ifx\FP@tmpa8\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 288 |
\expandafter\ifx\FP@tmpa9\relax\edef\FP@tmpb{\FP@tmpb\FP@tmpa}\else% |
| 289 |
\ifx\FP@tmpa\@empty\FP@nonstopfalse\else% |
| 290 |
\ifx\FP@tmpa\space\FP@nonstopfalse\else% |
| 291 |
\FP@errmessage{Illegal character \FP@tmpa\space found in float number}% |
| 292 |
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi% |
| 293 |
\edef\FP@tmp{\expandafter\FP@ignorenext\FP@tmp}% |
| 294 |
\ifx\FP@tmp\@empty\FP@nonstopfalse\fi% |
| 295 |
\ifFP@nonstop% |
| 296 |
\repeat% |
| 297 |
\fi% |
| 298 |
\global\let\FP@tmp\FP@tmpb% |
| 299 |
}% |
| 300 |
} |
| 301 |
|
| 302 |
\def\FP@readvalue#1#2#3{% |
| 303 |
% #1 macro family to catch the value |
| 304 |
% #2.#3 value |
| 305 |
% |
| 306 |
% regular expression [+|-]*[d]_0^18.[d]* |
| 307 |
% |
| 308 |
\FP@strip{#2}% |
| 309 |
%sign |
| 310 |
\expandafter\FP@getsign\FP@tmp\relax% |
| 311 |
\csname FP@#1s\endcsname=\FP@regs% |
| 312 |
% |
| 313 |
%integer part |
| 314 |
\FP@removeleadingzeros\FP@tmp\relax% |
| 315 |
\expandafter\FP@setintcounter\FP@tmp000000000000000000\relax% |
| 316 |
\csname FP@#1ia\endcsname=\FP@rega% |
| 317 |
\csname FP@#1ib\endcsname=\FP@regb% |
| 318 |
% |
| 319 |
%fractional part |
| 320 |
\FP@strip{#3}% |
| 321 |
\expandafter\FP@setfractcounter\FP@tmp000000000000000000\relax% |
| 322 |
\csname FP@#1fa\endcsname=\FP@rega% |
| 323 |
\csname FP@#1fb\endcsname=\FP@regb% |
| 324 |
% |
| 325 |
%correct sign |
| 326 |
\ifnum\FP@rega=0\relax% |
| 327 |
\ifnum\FP@regb=0\relax% |
| 328 |
\expandafter\ifnum\csname FP@#1ib\endcsname=0\relax% |
| 329 |
\expandafter\ifnum\csname FP@#1ia\endcsname=0\relax% |
| 330 |
\csname FP@#1s\endcsname=1\relax% |
| 331 |
\fi% |
| 332 |
\fi% |
| 333 |
\fi% |
| 334 |
\fi% |
| 335 |
} |
| 336 |
|
| 337 |
%store value in macro |
| 338 |
|
| 339 |
\def\FP@store#1#2{% |
| 340 |
% #1 macro |
| 341 |
% #2 macro family (value) to store |
| 342 |
% |
| 343 |
\ifFP@zero{#2}% |
| 344 |
\csname FP@#2s\endcsname=1\relax% |
| 345 |
\fi% |
| 346 |
\expandafter\ifnum\csname FP@#2s\endcsname<0\relax% |
| 347 |
\edef#1{-}% |
| 348 |
\else% |
| 349 |
\edef#1{}% |
| 350 |
\fi% |
| 351 |
\expandafter\ifnum\csname FP@#2ia\endcsname=0\relax% |
| 352 |
\expandafter\ifnum\csname FP@#2ib\endcsname=0\relax% |
| 353 |
\edef#1{#10}% |
| 354 |
\else% |
| 355 |
\edef#1{#1\expandafter\the\csname FP@#2ib\endcsname}% |
| 356 |
\fi% |
| 357 |
\else% |
| 358 |
\expandafter\advance\csname FP@#2ib\endcsname1000000000\relax% |
| 359 |
\edef#1{#1\expandafter\the\csname FP@#2ia\endcsname\expandafter\FP@ignorenext\the\csname FP@#2ib\endcsname}% |
| 360 |
\fi% |
| 361 |
\expandafter\advance\csname FP@#2fa\endcsname1000000000\relax% |
| 362 |
\expandafter\advance\csname FP@#2fb\endcsname1000000000\relax% |
| 363 |
\edef#1{#1\noexpand.\expandafter\FP@ignorenext\the\csname FP@#2fa\endcsname\expandafter\FP@ignorenext\the\csname FP@#2fb\endcsname}% |
| 364 |
} |
| 365 |
|
| 366 |
%macros to expand some arguments |
| 367 |
|
| 368 |
\def\FP@calla#1#2{% |
| 369 |
% #1 macro to call |
| 370 |
% #2 value |
| 371 |
% expand the value and split them into the integer and the fractional part |
| 372 |
\edef\next{\noexpand#1#2..\noexpand\relax}% |
| 373 |
\next% |
| 374 |
} |
| 375 |
|
| 376 |
\def\FP@callb#1#2#3{% |
| 377 |
% #1 macro to call |
| 378 |
% #2 1st value |
| 379 |
% #3 2nd value |
| 380 |
% expand the values and split them into the integer and the fractional parts |
| 381 |
\edef\next{\noexpand#1#2..\noexpand\relax#3..\noexpand\relax}% |
| 382 |
\next% |
| 383 |
} |
| 384 |
|
| 385 |
\def\FP@callc#1#2#3#4{% |
| 386 |
% #1 macro to call |
| 387 |
% #2 macro, which gets the result |
| 388 |
% #3 1st value |
| 389 |
% #4 2nd value |
| 390 |
% expand the values and split them into the integer and the fractional parts |
| 391 |
\edef\next{\noexpand#1\noexpand#2#3..\noexpand\relax#4..\noexpand\relax}% |
| 392 |
\next% |
| 393 |
} |
| 394 |
|
| 395 |
\def\FP@calld#1#2#3{% |
| 396 |
% #1 macro to call |
| 397 |
% #2 macro, which gets the result |
| 398 |
% #3 value |
| 399 |
\edef\next{\noexpand#1\noexpand#2#3..\noexpand\relax}% |
| 400 |
\next% |
| 401 |
} |
| 402 |
|
| 403 |
\def\FP@calle#1#2#3#4{% |
| 404 |
% #1 macro to call |
| 405 |
% #2 macro, which gets the first result |
| 406 |
% #3 macro, which gets the second result |
| 407 |
% #4 value |
| 408 |
\edef\next{\noexpand#1\noexpand#2\noexpand#3#4..\noexpand\relax}% |
| 409 |
\next% |
| 410 |
} |
| 411 |
|
| 412 |
%add two values |
| 413 |
|
| 414 |
\def\FP@add#1#2.#3.#4\relax#5.#6.#7\relax#8\relax{% |
| 415 |
% #1 macro, which gets the result |
| 416 |
% #2 integer part of 1st value |
| 417 |
% #3 fractional part of 1st value |
| 418 |
% #4 dummy to swallow everthing after the 2nd '.' |
| 419 |
% #5 integer part of 2nd value |
| 420 |
% #6 fractional part of 2nd value |
| 421 |
% #7 dummy to swallow everthing after the 2nd '.' |
| 422 |
% |
| 423 |
{\ifx#8+\relax% |
| 424 |
\FP@beginmessage{ADD}% |
| 425 |
\else% |
| 426 |
\FP@beginmessage{SUB}% |
| 427 |
\fi% |
| 428 |
% |
| 429 |
\FP@readvalue{x}{#2}{#3}% |
| 430 |
\FP@readvalue{y}{#5}{#6}% |
| 431 |
% |
| 432 |
\ifnum\FP@xs=\FP@ys% |
| 433 |
\advance\FP@xfb\FP@yfb% |
| 434 |
\advance\FP@xfa\FP@yfa% |
| 435 |
\ifnum\FP@xfb<1000000000\relax\else% |
| 436 |
\advance\FP@xfb-1000000000\relax% |
| 437 |
\advance\FP@xfa1\relax% |
| 438 |
\fi% |
| 439 |
\advance\FP@xib\FP@yib% |
| 440 |
\ifnum\FP@xfa<1000000000\relax\else% |
| 441 |
\advance\FP@xfa-1000000000\relax% |
| 442 |
\advance\FP@xib1\relax% |
| 443 |
\fi% |
| 444 |
\advance\FP@xia\FP@yia% |
| 445 |
\ifnum\FP@xib<1000000000\relax\else% |
| 446 |
\advance\FP@xib-1000000000\relax% |
| 447 |
\advance\FP@xia1\relax% |
| 448 |
\fi% |
| 449 |
\ifnum\FP@xia<1000000000\relax\else% |
| 450 |
\FP@errmessage{Overflow}% |
| 451 |
\fi% |
| 452 |
\FP@store\FP@tmp{x}% |
| 453 |
\else% |
| 454 |
\advance\FP@xfb-\FP@yfb% |
| 455 |
\ifnum\FP@xfb<0\relax% |
| 456 |
\advance\FP@yfa1\relax% |
| 457 |
\advance\FP@xfb1000000000\relax% |
| 458 |
\fi% |
| 459 |
\advance\FP@xfa-\FP@yfa% |
| 460 |
\ifnum\FP@xfa<0\relax% |
| 461 |
\advance\FP@yib1\relax% |
| 462 |
\advance\FP@xfa1000000000\relax% |
| 463 |
\fi% |
| 464 |
\advance\FP@xib-\FP@yib% |
| 465 |
\ifnum\FP@xib<0\relax% |
| 466 |
\advance\FP@yia1\relax% |
| 467 |
\advance\FP@xib1000000000\relax% |
| 468 |
\fi% |
| 469 |
\advance\FP@xia-\FP@yia% |
| 470 |
\ifnum\FP@xia<0\relax% |
| 471 |
\FP@xs=-\FP@xs% |
| 472 |
\ifnum\FP@xfb=0\relax\else% |
| 473 |
\advance\FP@xfb-1000000000\relax\FP@xfb=-\FP@xfb% |
| 474 |
\advance\FP@xfa1\relax% |
| 475 |
\fi% |
| 476 |
\ifnum\FP@xfa=0\relax\else% |
| 477 |
\advance\FP@xfa-1000000000\relax\FP@xfa=-\FP@xfa% |
| 478 |
\advance\FP@xib1\relax% |
| 479 |
\fi% |
| 480 |
\ifnum\FP@xib=0\relax\else% |
| 481 |
\advance\FP@xib-1000000000\relax\FP@xib=-\FP@xib% |
| 482 |
\advance\FP@xia1\relax% |
| 483 |
\fi% |
| 484 |
\relax\FP@xia=-\FP@xia% |
| 485 |
\fi% |
| 486 |
\FP@store\FP@tmp{x}% |
| 487 |
\fi% |
| 488 |
% |
| 489 |
\global\let\FP@tmp\FP@tmp% |
| 490 |
% |
| 491 |
\FP@endmessage{}% |
| 492 |
}% |
| 493 |
\let#1\FP@tmp% |
| 494 |
} |
| 495 |
|
| 496 |
%multiply two values |
| 497 |
|
| 498 |
\def\FP@firstnine#1#2#3#4#5#6#7#8#9{% |
| 499 |
\FP@res=#1#2#3#4#5#6#7#8#9\relax% |
| 500 |
} |
| 501 |
\def\FP@@ninesplit#1\relax#2\end#3{% |
| 502 |
#1% |
| 503 |
\edef#3{#2}% |
| 504 |
} |
| 505 |
\def\FP@ninesplit#1{% |
| 506 |
\edef#1{\expandafter\FP@firstnine\FP@rd}% |
| 507 |
\expandafter\FP@@ninesplit#1\end#1\relax% |
| 508 |
} |
| 509 |
|
| 510 |
\def\FP@split#1#2#3#4{% |
| 511 |
% #1 highest three digits |
| 512 |
% #2 medium three digits |
| 513 |
% #3 least three digits |
| 514 |
% #4 counter |
| 515 |
\FP@regc=#4% |
| 516 |
\divide\FP@regc1000000\relax% |
| 517 |
#1=\FP@regc% |
| 518 |
\multiply\FP@regc-1000000\relax\advance\FP@regc#4% |
| 519 |
#3=\FP@regc% |
| 520 |
\divide\FP@regc1000\relax% |
| 521 |
#2=\FP@regc% |
| 522 |
\multiply\FP@regc-1000\relax\advance\FP@regc#3% |
| 523 |
#3=\FP@regc% |
| 524 |
} |
| 525 |
|
| 526 |
\def\FP@@mul#1#2#3{% |
| 527 |
\FP@regc=\csname FP@x#1\endcsname% |
| 528 |
\multiply\FP@regc\csname FP@y#2\endcsname% |
| 529 |
\advance\FP@prod\FP@regc% |
| 530 |
% |
| 531 |
\ifx#3\relax% |
| 532 |
\let\next=\relax% |
| 533 |
\else% |
| 534 |
\let\next=\FP@@mul% |
| 535 |
\fi% |
| 536 |
\next#3% |
| 537 |
} |
| 538 |
|
| 539 |
\def\FP@saveshift{% |
| 540 |
% save rightmost three digits |
| 541 |
\FP@regc=\FP@prod% |
| 542 |
\divide\FP@prod1000\relax% |
| 543 |
\multiply\FP@prod1000\relax% |
| 544 |
\advance\FP@regc-\FP@prod% |
| 545 |
\advance\FP@regc1000\relax% |
| 546 |
\edef\FP@rd{\expandafter\FP@ignorenext\the\FP@regc\FP@rd}% |
| 547 |
% |
| 548 |
\divide\FP@prod1000\relax% |
| 549 |
} |
| 550 |
|
| 551 |
\def\FP@mul#1#2.#3.#4\relax#5.#6.#7\relax{% |
| 552 |
% #1 macro, which gets the result |
| 553 |
% #2 integer part of 1st value |
| 554 |
% #3 fractional part of 1st value |
| 555 |
% #4 dummy to swallow everthing after the 2nd '.' |
| 556 |
% #5 integer part of 2nd value |
| 557 |
% #6 fractional part of 2nd value |
| 558 |
% #7 dummy to swallow everthing after the 2nd '.' |
| 559 |
% |
| 560 |
% split value in various parts |
| 561 |
% x y = 123 456 789 123 456 789 . 123 456 789 123 456 789 |
| 562 |
% -> xk xl xm xn xo xp xq xr xs xt xu xv |
| 563 |
% -> yk yl ym yn yo yp yq yr ys yt yu yv |
| 564 |
% multiply these parts and save the result wrt the necessary shifts |
| 565 |
% |
| 566 |
{\FP@beginmessage{MUL}% |
| 567 |
% |
| 568 |
\FP@readvalue{x}{#2}{#3}% |
| 569 |
\FP@readvalue{y}{#5}{#6}% |
| 570 |
% |
| 571 |
%sign |
| 572 |
\multiply\FP@xs\FP@ys% |
| 573 |
\FP@rs=\FP@xs% |
| 574 |
% |
| 575 |
% split parts |
| 576 |
\FP@split\FP@xk\FP@xl\FP@xm\FP@xia\FP@split\FP@xn\FP@xo\FP@xp\FP@xib% |
| 577 |
\FP@split\FP@xq\FP@xr\FP@xz\FP@xfa\FP@split\FP@xt\FP@xu\FP@xv\FP@xfb% |
| 578 |
\FP@split\FP@yk\FP@yl\FP@ym\FP@yia\FP@split\FP@yn\FP@yo\FP@yp\FP@yib% |
| 579 |
\FP@split\FP@yq\FP@yr\FP@yz\FP@yfa\FP@split\FP@yt\FP@yu\FP@yv\FP@yfb% |
| 580 |
% |
| 581 |
\FP@prod=0\relax% |
| 582 |
\edef\FP@rd{}% |
| 583 |
% |
| 584 |
%compute result |
| 585 |
\FP@@mul vv \relax\FP@saveshift% |
| 586 |
\FP@@mul vu uv \relax\FP@saveshift% |
| 587 |
\FP@@mul uu vt tv \relax\FP@saveshift% |
| 588 |
\FP@@mul ut tu vz zv \relax\FP@saveshift% |
| 589 |
\FP@@mul tt zu uz rv vr \relax\FP@saveshift% |
| 590 |
\FP@@mul zt tz ur ru vq qv \relax\FP@saveshift% |
| 591 |
\FP@@mul zz rt tr uq qu vp pv \relax\FP@saveshift% |
| 592 |
\FP@@mul zr rz tq qt up pu vo ov \relax\FP@saveshift% |
| 593 |
\FP@@mul rr qz zq tp pt uo ou vn nv \relax\FP@saveshift% |
| 594 |
\FP@@mul rq qr zp pz to ot un nu vm mv \relax\FP@saveshift% |
| 595 |
\FP@@mul qq rp pr zo oz tn nt um mu vl lv \relax\FP@saveshift% |
| 596 |
\FP@@mul qp pq ro or zn nz tm mt ul lu kv vk \relax\FP@saveshift% |
| 597 |
\FP@@mul pp oq qo rn nr zm mz tl lt ku uk \relax\FP@saveshift% |
| 598 |
\FP@@mul op po nq qn rm mr zl lz tk kt \relax\FP@saveshift% |
| 599 |
\FP@@mul oo pn np mq qm rl lr kz zk \relax\FP@saveshift% |
| 600 |
\FP@@mul no on mp pm lq ql kr rk \relax\FP@saveshift% |
| 601 |
\FP@@mul nn mo om pl lp qk kq \relax\FP@saveshift% |
| 602 |
\FP@@mul mn nm lo ok pk kp \relax\FP@saveshift% |
| 603 |
\FP@@mul mm ln nl ko ok \relax\FP@saveshift% |
| 604 |
\FP@@mul lm ml kn nk \relax\FP@saveshift% |
| 605 |
\FP@@mul ll km mk \relax\FP@saveshift% |
| 606 |
\FP@@mul kl lk \relax\FP@saveshift% |
| 607 |
\FP@@mul kk \relax\FP@saveshift\FP@saveshift% |
| 608 |
\FP@ninesplit\FP@rd% |
| 609 |
\ifnum\FP@res=0\relax% |
| 610 |
\FP@ninesplit\FP@rd% |
| 611 |
\ifnum\FP@res=0\relax% |
| 612 |
\FP@ninesplit\FP@rd\FP@ria=\FP@res% |
| 613 |
\FP@ninesplit\FP@rd\FP@rib=\FP@res% |
| 614 |
\FP@ninesplit\FP@rd\FP@rfa=\FP@res% |
| 615 |
\FP@ninesplit\FP@rd\FP@rfb=\FP@res% |
| 616 |
\FP@store\FP@tmp{r}% |
| 617 |
\else% |
| 618 |
\FP@errmessage{Overflow}% |
| 619 |
\fi% |
| 620 |
\else% |
| 621 |
\FP@errmessage{Overflow}% |
| 622 |
\fi% |
| 623 |
% |
| 624 |
\global\let\FP@tmp\FP@tmp% |
| 625 |
% |
| 626 |
\FP@endmessage{}% |
| 627 |
}% |
| 628 |
% |
| 629 |
\let#1\FP@tmp% |
| 630 |
} |
| 631 |
|
| 632 |
%divide one value by another one |
| 633 |
|
| 634 |
\def\FP@divten#1{% |
| 635 |
\expandafter\FP@regc\csname FP@#1ia\endcsname% |
| 636 |
\expandafter\divide\csname FP@#1ia\endcsname10\relax% |
| 637 |
\expandafter\FP@regb\csname FP@#1ia\endcsname% |
| 638 |
\multiply\FP@regb10\relax% |
| 639 |
\advance\FP@regc-\FP@regb% |
| 640 |
\multiply\FP@regc100000000\relax% |
| 641 |
% |
| 642 |
\expandafter\FP@rega\csname FP@#1ib\endcsname% |
| 643 |
\expandafter\divide\csname FP@#1ib\endcsname10\relax% |
| 644 |
\expandafter\FP@regb\csname FP@#1ib\endcsname% |
| 645 |
\multiply\FP@regb10\relax% |
| 646 |
\advance\FP@rega-\FP@regb% |
| 647 |
\multiply\FP@rega100000000\relax% |
| 648 |
\expandafter\advance\csname FP@#1ib\endcsname\FP@regc% |
| 649 |
% |
| 650 |
\expandafter\FP@regc\csname FP@#1fa\endcsname% |
| 651 |
\expandafter\divide\csname FP@#1fa\endcsname10\relax% |
| 652 |
\expandafter\FP@regb\csname FP@#1fa\endcsname% |
| 653 |
\multiply\FP@regb10\relax% |
| 654 |
\advance\FP@regc-\FP@regb% |
| 655 |
\multiply\FP@regc100000000\relax% |
| 656 |
\expandafter\advance\csname FP@#1fa\endcsname\FP@rega% |
| 657 |
% |
| 658 |
\expandafter\divide\csname FP@#1fb\endcsname10\relax% |
| 659 |
\expandafter\advance\csname FP@#1fb\endcsname\FP@regc% |
| 660 |
} |
| 661 |
|
| 662 |
\def\FP@multen#1{% |
| 663 |
\expandafter\multiply\csname FP@#1ia\endcsname10\relax% |
| 664 |
\expandafter\ifnum\csname FP@#1ib\endcsname<100000000\relax% |
| 665 |
\else% |
| 666 |
\expandafter\FP@regc\csname FP@#1ib\endcsname% |
| 667 |
\divide\FP@regc100000000% |
| 668 |
\expandafter\advance\csname FP@#1ia\endcsname\FP@regc% |
| 669 |
\multiply\FP@regc100000000% |
| 670 |
\expandafter\advance\csname FP@#1ib\endcsname-\FP@regc% |
| 671 |
\fi% |
| 672 |
\expandafter\multiply\csname FP@#1ib\endcsname10\relax% |
| 673 |
\expandafter\ifnum\csname FP@#1fa\endcsname<100000000\relax% |
| 674 |
\else% |
| 675 |
\expandafter\FP@regc\csname FP@#1fa\endcsname% |
| 676 |
\divide\FP@regc100000000% |
| 677 |
\expandafter\advance\csname FP@#1ib\endcsname\FP@regc% |
| 678 |
\multiply\FP@regc100000000% |
| 679 |
\expandafter\advance\csname FP@#1fa\endcsname-\FP@regc% |
| 680 |
\fi% |
| 681 |
\expandafter\multiply\csname FP@#1fa\endcsname10\relax% |
| 682 |
\expandafter\ifnum\csname FP@#1fb\endcsname<100000000\relax% |
| 683 |
\else% |
| 684 |
\expandafter\FP@regc\csname FP@#1fb\endcsname% |
| 685 |
\divide\FP@regc100000000% |
| 686 |
\expandafter\advance\csname FP@#1fa\endcsname\FP@regc% |
| 687 |
\multiply\FP@regc100000000% |
| 688 |
\expandafter\advance\csname FP@#1fb\endcsname-\FP@regc% |
| 689 |
\fi% |
| 690 |
\expandafter\multiply\csname FP@#1fb\endcsname10\relax% |
| 691 |
} |
| 692 |
|
| 693 |
\def\FP@counttimes{% |
| 694 |
{\global\FP@times=0\relax% |
| 695 |
\loop% |
| 696 |
\ifnum% |
| 697 |
\ifnum\FP@xia>\FP@yia1% |
| 698 |
\else\ifnum\FP@xia<\FP@yia0% |
| 699 |
\else% |
| 700 |
\ifnum\FP@xib>\FP@yib1% |
| 701 |
\else\ifnum\FP@xib<\FP@yib0% |
| 702 |
\else% |
| 703 |
\ifnum\FP@xfa>\FP@yfa1% |
| 704 |
\else\ifnum\FP@xfa<\FP@yfa0% |
| 705 |
\else% |
| 706 |
\ifnum\FP@xfb>\FP@yfb1% |
| 707 |
\else\ifnum\FP@xfb<\FP@yfb0% |
| 708 |
\else% |
| 709 |
1% |
| 710 |
\fi\fi% |
| 711 |
\fi\fi% |
| 712 |
\fi\fi% |
| 713 |
\fi\fi% |
| 714 |
=1\relax% |
| 715 |
\global\advance\FP@times1\relax% |
| 716 |
\global\advance\FP@xfb-\FP@yfb% |
| 717 |
\ifnum\FP@xfb<0\relax% |
| 718 |
\global\advance\FP@xfb1000000000\relax% |
| 719 |
\global\advance\FP@xfa-1\relax% |
| 720 |
\fi% |
| 721 |
\global\advance\FP@xfa-\FP@yfa% |
| 722 |
\ifnum\FP@xfa<0\relax% |
| 723 |
\global\advance\FP@xfa1000000000\relax% |
| 724 |
\global\advance\FP@xib-1\relax% |
| 725 |
\fi% |
| 726 |
\global\advance\FP@xib-\FP@yib% |
| 727 |
\ifnum\FP@xib<0\relax% |
| 728 |
\global\advance\FP@xib1000000000\relax% |
| 729 |
\global\advance\FP@xia-1\relax% |
| 730 |
\fi% |
| 731 |
\global\advance\FP@xia-\FP@yia% |
| 732 |
\repeat% |
| 733 |
}% |
| 734 |
} |
| 735 |
|
| 736 |
\def\FP@div#1#2.#3.#4\relax#5.#6.#7\relax{% |
| 737 |
% #1 macro, which gets the result |
| 738 |
% #2 integer part of 1st value |
| 739 |
% #3 fractional part of 1st value |
| 740 |
% #4 dummy to swallow everthing after the 2nd '.' |
| 741 |
% #5 integer part of 2nd value |
| 742 |
% #6 fractional part of 2nd value |
| 743 |
% #7 dummy to swallow everthing after the 2nd '.' |
| 744 |
% |
| 745 |
% algorithmic idea (for x>0, y>0) |
| 746 |
% - %determine \FP@shift such that y*10^\FP@shift <100000000<=y*10^(\FP@shift+1) |
| 747 |
% - %determine \FP@shift' such that x*10^\FP@shift'<100000000<=x*10^(\FP@shift+1) |
| 748 |
% - x=x*\FP@shift' |
| 749 |
% - y=y*\FP@shift |
| 750 |
% - \FP@shift=\FP@shift-\FP@shift' |
| 751 |
% - res=0 |
| 752 |
% - while y>0 %fixed-point representation! |
| 753 |
% - \FP@times=0 |
| 754 |
% - while x>y |
| 755 |
% - \FP@times=\FP@times+1 |
| 756 |
% - x=x-y |
| 757 |
% - end |
| 758 |
% - y=y/10 |
| 759 |
% - res=10*res+\FP@times/1000000000 |
| 760 |
% - end |
| 761 |
% - %shift the result according to \FP@shift |
| 762 |
% |
| 763 |
{\FP@beginmessage{DIV}% |
| 764 |
% |
| 765 |
\FP@readvalue{x}{#2}{#3}% |
| 766 |
\FP@readvalue{y}{#5}{#6}% |
| 767 |
% |
| 768 |
%sign |
| 769 |
\multiply\FP@xs\FP@ys% |
| 770 |
\FP@rs=\FP@xs% |
| 771 |
% |
| 772 |
%compute division |
| 773 |
\ifFP@zero{y}% |
| 774 |
\FP@errmessage{Division by zero}% |
| 775 |
\else% |
| 776 |
\ifFP@zero{x}\def\next##1{\edef\FP@tmp{0}}\else\def\next##1{##1}\fi% |
| 777 |
\next% |
| 778 |
{\FP@shift=0\relax% |
| 779 |
\loop% |
| 780 |
\ifnum\FP@yia<100000000\relax% |
| 781 |
\FP@multen{y}% |
| 782 |
\advance\FP@shift1\relax% |
| 783 |
\repeat% |
| 784 |
\loop% |
| 785 |
\ifnum\FP@xia<100000000\relax% |
| 786 |
\FP@multen{x}% |
| 787 |
\advance\FP@shift-1\relax% |
| 788 |
\repeat% |
| 789 |
\FP@ria=0\FP@rib=0\FP@rfa=0\FP@rfb=0\relax% |
| 790 |
\loop% |
| 791 |
\ifFP@zero{y}\else% |
| 792 |
\FP@counttimes%divides x by \FP@times*y |
| 793 |
\FP@divten{y}% |
| 794 |
\FP@multen{r}% |
| 795 |
\advance\FP@rfb\FP@times% |
| 796 |
\ifnum\FP@rfb<1000000000\relax\else% |
| 797 |
\advance\FP@rfa1\advance\FP@rfb-1000000000\relax% |
| 798 |
\ifnum\FP@rfa<1000000000\relax\else% |
| 799 |
\advance\FP@rib1\advance\FP@rfa-1000000000\relax% |
| 800 |
\ifnum\FP@rib<1000000000\relax\else% |
| 801 |
\advance\FP@ria1\advance\FP@rib-1000000000\relax% |
| 802 |
\fi% |
| 803 |
\fi% |
| 804 |
\fi% |
| 805 |
\repeat% |
| 806 |
\loop% |
| 807 |
\ifnum\FP@shift>17% |
| 808 |
\advance\FP@shift-1\relax% |
| 809 |
\ifnum\FP@ria<100000000\else\FP@ria=-1\fi% |
| 810 |
\ifnum\FP@ria<0\FP@ria=-1\fi% |
| 811 |
\FP@multen{r}% |
| 812 |
\repeat% |
| 813 |
\ifnum\FP@ria<1000000000\else\FP@ria=-1\fi% |
| 814 |
\loop% |
| 815 |
\ifnum\FP@shift<17% |
| 816 |
\advance\FP@shift1\relax% |
| 817 |
\FP@divten{r}% |
| 818 |
\repeat% |
| 819 |
\ifnum\FP@ria<0\relax% |
| 820 |
\FP@errmessage{Overflow}% |
| 821 |
\else% |
| 822 |
\FP@store\FP@tmp{r}% |
| 823 |
\fi% |
| 824 |
}% |
| 825 |
\fi% |
| 826 |
% |
| 827 |
\global\let\FP@tmp=\FP@tmp% |
| 828 |
% |
| 829 |
\FP@endmessage{}% |
| 830 |
}% |
| 831 |
\let#1\FP@tmp% |
| 832 |
} |
| 833 |
|
| 834 |
%absolute value |
| 835 |
|
| 836 |
\def\FP@abs#1#2.#3.#4\relax{% |
| 837 |
% #1 macro, which gets the result |
| 838 |
% #2 integer part of value |
| 839 |
% #3 fractional part of value |
| 840 |
% #4 dummy to swallow everthing after the 2nd '.' |
| 841 |
% |
| 842 |
{\FP@beginmessage{ABS}% |
| 843 |
% |
| 844 |
\FP@readvalue{x}{#2}{#3}% |
| 845 |
\FP@xs=1\relax% |
| 846 |
\FP@store\FP@tmp{x}% |
| 847 |
% |
| 848 |
\global\let\FP@tmp\FP@tmp% |
| 849 |
% |
| 850 |
\FP@endmessage{}% |
| 851 |
}% |
| 852 |
\let#1\FP@tmp% |
| 853 |
} |
| 854 |
|
| 855 |
%negate value |
| 856 |
|
| 857 |
\def\FP@neg#1#2.#3.#4\relax{% |
| 858 |
% #1 macro, which gets the result |
| 859 |
% #2 integer part of value |
| 860 |
% #3 fractional part of value |
| 861 |
% #4 dummy to swallow everthing after the 2nd '.' |
| 862 |
% |
| 863 |
{\FP@beginmessage{NEG}% |
| 864 |
% |
| 865 |
\FP@readvalue{x}{#2}{#3}% |
| 866 |
\multiply\FP@xs-1\relax% |
| 867 |
\FP@store\FP@tmp{x}% |
| 868 |
% |
| 869 |
\global\let\FP@tmp\FP@tmp% |
| 870 |
% |
| 871 |
\FP@endmessage{}% |
| 872 |
}% |
| 873 |
\let#1\FP@tmp% |
| 874 |
} |
| 875 |
|
| 876 |
%sign of value |
| 877 |
|
| 878 |
\def\FP@sgn#1#2.#3.#4\relax{% |
| 879 |
% #1 macro, which gets the result |
| 880 |
% #2 integer part of value |
| 881 |
% #3 fractional part of value |
| 882 |
% #4 dummy to swallow everthing after the 2nd '.' |
| 883 |
% |
| 884 |
{\FP@beginmessage{SGN}% |
| 885 |
% |
| 886 |
\FP@readvalue{x}{#2}{#3}% |
| 887 |
% |
| 888 |
\ifFP@zero{x}% |
| 889 |
\edef\FP@tmp{0}% |
| 890 |
\else% |
| 891 |
\edef\FP@tmp{\the\FP@xs}% |
| 892 |
\fi% |
| 893 |
% |
| 894 |
\global\let\FP@tmp\FP@tmp% |
| 895 |
% |
| 896 |
\FP@endmessage{}% |
| 897 |
}% |
| 898 |
\let#1\FP@tmp% |
| 899 |
} |
| 900 |
|
| 901 |
%test if 1st value is less than 2nd value |
| 902 |
|
| 903 |
\def\FP@iflt#1.#2.#3\relax#4.#5.#6\relax#7\relax{% |
| 904 |
% #1 integer part of 1st value |
| 905 |
% #2 fractional part of 1st value |
| 906 |
% #3 dummy to swallow everthing after the 2nd '.' |
| 907 |
% #4 integer part of 2nd value |
| 908 |
% #5 fractional part of 2nd value |
| 909 |
% #6 dummy to swallow everthing after the 2nd '.' |
| 910 |
% |
| 911 |
{\ifx#7+\relax% |
| 912 |
\FP@beginmessage{LT?}% |
| 913 |
\else% |
| 914 |
\FP@beginmessage{GT?}% |
| 915 |
\fi% |
| 916 |
% |
| 917 |
\FP@readvalue{x}{#1}{#2}% |
| 918 |
\FP@readvalue{y}{#4}{#5}% |
| 919 |
% |
| 920 |
\ifnum\FP@xs<\FP@ys% |
| 921 |
\FP@testtrue% |
| 922 |
\else\ifnum\FP@xs>\FP@ys% |
| 923 |
\FP@testfalse% |
| 924 |
\else% |
| 925 |
\ifnum\FP@xs>0\relax% |
| 926 |
\ifnum\FP@xia<\FP@yia% |
| 927 |
\FP@testtrue% |
| 928 |
\else\ifnum\FP@xia>\FP@yia% |
| 929 |
\FP@testfalse% |
| 930 |
\else% |
| 931 |
\ifnum\FP@xib<\FP@yib% |
| 932 |
\FP@testtrue% |
| 933 |
\else\ifnum\FP@xib>\FP@yib% |
| 934 |
\FP@testfalse% |
| 935 |
\else% |
| 936 |
\ifnum\FP@xfa<\FP@yfa% |
| 937 |
\FP@testtrue% |
| 938 |
\else\ifnum\FP@xfa>\FP@yfa% |
| 939 |
\FP@testfalse% |
| 940 |
\else% |
| 941 |
\ifnum\FP@xfb<\FP@yfb% |
| 942 |
\FP@testtrue% |
| 943 |
\else% |
| 944 |
\FP@testfalse% |
| 945 |
\fi% |
| 946 |
\fi\fi% |
| 947 |
\fi\fi% |
| 948 |
\fi\fi% |
| 949 |
\else% |
| 950 |
\ifnum\FP@xia>\FP@yia% |
| 951 |
\FP@testtrue% |
| 952 |
\else\ifnum\FP@xia<\FP@yia% |
| 953 |
\FP@testfalse% |
| 954 |
\else% |
| 955 |
\ifnum\FP@xib>\FP@yib% |
| 956 |
\FP@testtrue% |
| 957 |
\else\ifnum\FP@xib<\FP@yib% |
| 958 |
\FP@testfalse% |
| 959 |
\else% |
| 960 |
\ifnum\FP@xfa>\FP@yfa% |
| 961 |
\FP@testtrue% |
| 962 |
\else\ifnum\FP@xfa<\FP@yfa% |
| 963 |
\FP@testfalse% |
| 964 |
\else% |
| 965 |
\ifnum\FP@xfb>\FP@yfb% |
| 966 |
\FP@testtrue% |
| 967 |
\else% |
| 968 |
\FP@testfalse% |
| 969 |
\fi% |
| 970 |
\fi\fi% |
| 971 |
\fi\fi% |
| 972 |
\fi\fi% |
| 973 |
\fi% |
| 974 |
\fi\fi% |
| 975 |
% |
| 976 |
\global\let\ifFP@test\ifFP@test% |
| 977 |
% |
| 978 |
\FP@endmessage{}% |
| 979 |
}% |
| 980 |
\let\ifFPtest\ifFP@test% |
| 981 |
% |
| 982 |
\ifFPtest% |
| 983 |
} |
| 984 |
|
| 985 |
%test if two values are equal |
| 986 |
|
| 987 |
\def\FP@ifeq#1.#2.#3\relax#4.#5.#6\relax{% |
| 988 |
% #1 integer part of 1st value |
| 989 |
% #2 fractional part of 1st value |
| 990 |
% #3 dummy to swallow everthing after the 2nd '.' |
| 991 |
% #4 integer part of 2nd value |
| 992 |
% #5 fractional part of 2nd value |
| 993 |
% #6 dummy to swallow everthing after the 2nd '.' |
| 994 |
% |
| 995 |
{\FP@beginmessage{EQ?}% |
| 996 |
% |
| 997 |
\FP@readvalue{x}{#1}{#2}% |
| 998 |
\FP@readvalue{y}{#4}{#5}% |
| 999 |
% |
| 1000 |
\ifnum\FP@xs=\FP@ys% |
| 1001 |
\ifnum\FP@xia=\FP@yia% |
| 1002 |
\ifnum\FP@xib=\FP@yib% |
| 1003 |
\ifnum\FP@xfa=\FP@yfa% |
| 1004 |
\ifnum\FP@xfb=\FP@yfb% |
| 1005 |
\FP@testtrue% |
| 1006 |
\else% |
| 1007 |
\FP@testfalse% |
| 1008 |
\fi% |
| 1009 |
\else% |
| 1010 |
\FP@testfalse% |
| 1011 |
\fi% |
| 1012 |
\else% |
| 1013 |
\FP@testfalse% |
| 1014 |
\fi% |
| 1015 |
\else% |
| 1016 |
\FP@testfalse% |
| 1017 |
\fi% |
| 1018 |
\else% |
| 1019 |
\FP@testfalse% |
| 1020 |
\fi% |
| 1021 |
% |
| 1022 |
\global\let\ifFP@test\ifFP@test% |
| 1023 |
% |
| 1024 |
\FP@endmessage{}% |
| 1025 |
}% |
| 1026 |
\let\ifFPtest\ifFP@test% |
| 1027 |
% |
| 1028 |
\ifFPtest% |
| 1029 |
} |
| 1030 |
|
| 1031 |
%test if value is negative |
| 1032 |
|
| 1033 |
\def\FP@ifneg#1.#2.#3\relax{% |
| 1034 |
% #1 integer part of value |
| 1035 |
% #2 fractional part of value |
| 1036 |
% #3 dummy to swallow everthing after the 2nd '.' |
| 1037 |
% |
| 1038 |
{\FP@beginmessage{NEG?}% |
| 1039 |
% |
| 1040 |
\FP@readvalue{x}{#1}{#2}% |
| 1041 |
% |
| 1042 |
\ifnum\FP@xs<0\relax% |
| 1043 |
\FP@testtrue% |
| 1044 |
\else% |
| 1045 |
\FP@testfalse% |
| 1046 |
\fi% |
| 1047 |
% |
| 1048 |
\global\let\ifFP@test\ifFP@test% |
| 1049 |
% |
| 1050 |
\FP@endmessage{}% |
| 1051 |
}% |
| 1052 |
\let\ifFPtest\ifFP@test% |
| 1053 |
% |
| 1054 |
\ifFPtest% |
| 1055 |
} |
| 1056 |
|
| 1057 |
%test if value is positive |
| 1058 |
|
| 1059 |
\def\FP@ifpos#1.#2.#3\relax{% |
| 1060 |
% #1 integer part of value |
| 1061 |
% #2 fractional part of value |
| 1062 |
% #3 dummy to swallow everthing after the 2nd '.' |
| 1063 |
% |
| 1064 |
{\FP@beginmessage{POS?}% |
| 1065 |
% |
| 1066 |
\FP@readvalue{x}{#1}{#2}% |
| 1067 |
% |
| 1068 |
\ifnum\FP@xs<0\relax% |
| 1069 |
\FP@testfalse% |
| 1070 |
\else% |
| 1071 |
\FP@testtrue% |
| 1072 |
\fi% |
| 1073 |
% |
| 1074 |
\global\let\ifFP@test\ifFP@test% |
| 1075 |
% |
| 1076 |
\FP@endmessage{}% |
| 1077 |
}% |
| 1078 |
\let\ifFPtest\ifFP@test% |
| 1079 |
% |
| 1080 |
\ifFPtest% |
| 1081 |
} |
| 1082 |
|
| 1083 |
%test if value is equal to zero |
| 1084 |
|
| 1085 |
\def\FP@ifzero#1.#2.#3\relax{% |
| 1086 |
% #1 integer part of value |
| 1087 |
% #2 fractional part of value |
| 1088 |
% #3 dummy to swallow everthing after the 2nd '.' |
| 1089 |
% |
| 1090 |
{\FP@beginmessage{ZERO?}% |
| 1091 |
% |
| 1092 |
\FP@readvalue{x}{#1}{#2}% |
| 1093 |
% |
| 1094 |
\ifFP@zero{x}% |
| 1095 |
\FP@testtrue% |
| 1096 |
\else% |
| 1097 |
\FP@testfalse% |
| 1098 |
\fi% |
| 1099 |
% |
| 1100 |
\global\let\ifFP@test\ifFP@test% |
| 1101 |
% |
| 1102 |
\FP@endmessage{}% |
| 1103 |
}% |
| 1104 |
\let\ifFPtest\ifFP@test% |
| 1105 |
% |
| 1106 |
\ifFPtest% |
| 1107 |
} |
| 1108 |
|
| 1109 |
%test if value is an integer |
| 1110 |
|
| 1111 |
\def\FP@ifint#1.#2.#3\relax{% |
| 1112 |
% #1 integer part of value |
| 1113 |
% #2 fractional part of value |
| 1114 |
% #3 dummy to swallow everthing after the 2nd '.' |
| 1115 |
% |
| 1116 |
{\FP@beginmessage{INT?}% |
| 1117 |
% |
| 1118 |
\FP@readvalue{x}{#1}{#2}% |
| 1119 |
% |
| 1120 |
\ifnum\FP@xfa=0\relax% |
| 1121 |
\ifnum\FP@xfb=0\relax% |
| 1122 |
\FP@testtrue% |
| 1123 |
\else% |
| 1124 |
\FP@testfalse% |
| 1125 |
\fi% |
| 1126 |
\else% |
| 1127 |
\FP@testfalse% |
| 1128 |
\fi% |
| 1129 |
% |
| 1130 |
\global\let\ifFP@test\ifFP@test% |
| 1131 |
% |
| 1132 |
\FP@endmessage{}% |
| 1133 |
}% |
| 1134 |
\let\ifFPtest\ifFP@test% |
| 1135 |
% |
| 1136 |
\ifFPtest% |
| 1137 |
} |