diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/libraries/pgflibraryfpu.code.tex')
-rw-r--r-- | Master/texmf-dist/tex/generic/pgf/libraries/pgflibraryfpu.code.tex | 212 |
1 files changed, 180 insertions, 32 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/libraries/pgflibraryfpu.code.tex b/Master/texmf-dist/tex/generic/pgf/libraries/pgflibraryfpu.code.tex index dbaf9847cd1..00ce27705f8 100644 --- a/Master/texmf-dist/tex/generic/pgf/libraries/pgflibraryfpu.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/libraries/pgflibraryfpu.code.tex @@ -157,24 +157,13 @@ \expandafter\let\expandafter#1\csname pgfmathfloat@backup@\string#1\endcsname% }% } -\def\pgfmathfloat@prepareuninstallcmd@csname#1{% - % and store backup information (globally - I don't want to do that - % all the time when the FPU is used!): - {% - \globaldefs=1 - \pgfutil@namelet{pgfmathfloat@backup@#1}{#1}% - \expandafter\gdef\expandafter\pgfmathfloat@uninstall\expandafter{\pgfmathfloat@uninstall - \pgfutil@namelet{#1}{pgfmathfloat@backup@#1}% - }% - }% -} \def\pgfmathfloat@install#1=#2{% \pgfmathfloat@prepareuninstallcmd{#1}% \let#1=#2% } \def\pgfmathfloat@install@csname#1#2{% - \pgfmathfloat@prepareuninstallcmd@csname{#1}% + \expandafter\pgfmathfloat@prepareuninstallcmd\csname #1\endcsname% \pgfutil@namelet{#1}{#2}% } \def\pgfmathfloat@install@unimplemented#1{% @@ -213,8 +202,11 @@ \pgfmathfloat@install\pgfmathmultiply@=\pgfmathfloatmultiply@% \pgfmathfloat@install\pgfmathdivide@=\pgfmathfloatdivide@% \pgfmathfloat@install\pgfmathabs@=\pgfmathfloatabs@% + \pgfmathfloat@install\pgfmathsign@=\pgfmathfloatsign@% \pgfmathfloat@install\pgfmathround@=\pgfmathfloatround@% \pgfmathfloat@install\pgfmathfloor@=\pgfmathfloatfloor@% + \pgfmathfloat@install\pgfmathceil@=\pgfmathfloatceil@ + \pgfmathfloat@install\pgfmathint@=\pgfmathfloatint@ \pgfmathfloat@install\pgfmathmod@=\pgfmathfloatmod@% \pgfmathfloat@install\pgfmathmax@=\pgfmathfloatmax@% \pgfmathfloat@install\pgfmathmin@=\pgfmathfloatmin@% @@ -268,13 +260,12 @@ \pgfmathfloat@install\pgfmathcosh@=\pgfmathfloatcosh@ \pgfmathfloat@install\pgfmathsinh@=\pgfmathfloatsinh@ \pgfmathfloat@install\pgfmathtanh@=\pgfmathfloattanh@ - \pgfmathfloat@install@unimplemented{ceil}% + \expandafter\pgfmathfloat@install\csname pgfmathatan2@\endcsname=\pgfmathfloatatantwo@ \pgfmathfloat@install@unimplemented{frac}% \pgfmathfloat@install@unimplemented{random}% \pgfmathfloat@install@unimplemented{setseed}% \pgfmathfloat@install@unimplemented{Mod}% \pgfmathfloat@install@unimplemented{real}% -% \pgfmathfloat@install@unimplemented{atan2}% % \pgfmathfloat@install@unimplemented{height}% % % @@ -308,6 +299,21 @@ \pgfmathfloat@install\pgfmath@parse@exponent=\pgfmathfloat@parse@float@or@exponent % \pgfmathfloat@install\pgfmathparse=\pgfmathfloatparse% + %\pgfmathfloat@install\pgfmathparse@trynumber@token=\pgfmathfloat@parse@trynumber@token + \pgfmathfloat@install\pgfmathparse@expression@is@number=\pgfmathfloat@parse@expression@is@number +}% + +% This here might bring speed improvements... if implemented +% correctly. +% However, this heuristics might fail in cases like "1+1" vs "1e+1" ... +%\def\pgfmathfloat@parse@trynumber@token{numericfpu} +%\pgfmath@tokens@make{numericfpu}{eE+-Y.0123456789} + +\def\pgfmathfloat@parse@expression@is@number{% + \pgfmathfloatparsenumber{\pgfmath@expression}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup + \ignorespaces }% \def\pgfmathfloat@defineadapter@for@pgf@two@null@null@ONEARG#1{% @@ -993,7 +999,7 @@ \if#2+% \pgfmathfloatifflags{#1}{1}{#3}{#4}% \else - \pgfmathfloatgetflagstomacro#1\pgfmathfloat@loc@TMPa + \pgfmathfloatgetflagstomacro{#1}\pgfmathfloat@loc@TMPa \if#2u% \ifnum\pgfmathfloat@loc@TMPa>2 #3\relax @@ -1424,8 +1430,24 @@ }% \def\pgfmathfloatint@@loop@gobble#1\pgfmathfloat@EOI{}% \let\pgfmathfloatint=\pgfmathfloatint@ -\let\pgfmathfloatfloor=\pgfmathfloatint -\let\pgfmathfloatfloor@=\pgfmathfloatint@ + +\def\pgfmathfloatfloor#1{% + \edef\pgfmathfloat@loc@TMPa{#1}% + \pgfmathfloatcreate{2}{5.0}{-1}% -0.5 + \let\pgfmathfloat@loc@TMPb=\pgfmathresult + \pgfmathfloatadd@{\pgfmathfloat@loc@TMPa}{\pgfmathfloat@loc@TMPb}% + \expandafter\pgfmathfloatround@\expandafter{\pgfmathresult}% +} +\let\pgfmathfloatfloor@=\pgfmathfloatfloor + +\def\pgfmathfloatceil#1{% + \edef\pgfmathfloat@loc@TMPa{#1}% + \pgfmathfloatcreate{1}{5.0}{-1}% +0.5 + \let\pgfmathfloat@loc@TMPb=\pgfmathresult + \pgfmathfloatadd@{\pgfmathfloat@loc@TMPa}{\pgfmathfloat@loc@TMPb}% + \expandafter\pgfmathfloatround@\expandafter{\pgfmathresult}% +} +\let\pgfmathfloatceil@=\pgfmathfloatceil \def\pgfmathfloat@notimplemented#1{% \pgfmath@error{Sorry, the operation '#1' has not yet been implemented in the floating point unit :-(}{}% @@ -1476,7 +1498,34 @@ \pgfmath@smuggleone\pgfmathresult \endgroup }% -\let\pgfmathfloatabs=\pgfmathfloatabs@ +% +% Defines \pgfmathresult to be sign(#1) +\def\pgfmathfloatsign@#1{% + \begingroup + \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E + \ifcase\pgfmathfloat@a@S + % 0: + \pgfmathfloatcreate{0}{0.0}{0}% + \or + % +: ok, is positive. + \pgfmathfloatcreate{1}{1.0}{0}% + \or + % -: + \pgfmathfloatcreate{2}{1.0}{0}% + \or + % nan: do nothing. + \pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% + \or + % +infty:. + \pgfmathfloatcreate{1}{1.0}{0}% + \or + % -infty: + \pgfmathfloatcreate{2}{1.0}{0}% + \fi + \pgfmath@smuggleone\pgfmathresult + \endgroup +}% +\let\pgfmathfloatsign=\pgfmathfloatsign@ % Computes the absolute error |#1 - #2| into \pgfmathresult. \def\pgfmathfloatabserror@#1#2{% @@ -1494,8 +1543,8 @@ \let\pgfmathresult=\pgfmathfloat@subtract }{% \pgfmathfloatdivide@{\pgfmathfloat@subtract}{#2}% - \pgfmathfloatabs@{\pgfmathresult}% }% + \pgfmathfloatabs@{\pgfmathresult}% }% \let\pgfmathfloatrelerror=\pgfmathfloatrelerror@ @@ -1567,14 +1616,27 @@ % % #1 is a one-argument macro which assigns \pgfmathresult. \def\pgfmathfloatTRIG@#1#2{% - \expandafter\ifx\csname pgfmathfloatTRIG@NUM\endcsname\relax% - % Lazy evaluation: - \pgfmathfloatcreate{1}{3.6}{2}% - \global\let\pgfmathfloatTRIG@NUM=\pgfmathresult - \pgfmathfloatcreate{1}{2.77777777777778}{-3}% - \global\let\pgfmathfloatTRIG@NUM@INV=\pgfmathresult + \if0\pgfmath@trig@format@choice + % trig format=deg + \expandafter\ifx\csname pgfmathfloatTRIG@NUM\endcsname\relax% + % Lazy evaluation: + \pgfmathfloatcreate{1}{3.6}{2}% + \global\let\pgfmathfloatTRIG@NUM=\pgfmathresult + \pgfmathfloatcreate{1}{2.77777777777778}{-3}% + \global\let\pgfmathfloatTRIG@NUM@INV=\pgfmathresult + \fi + \pgfmathfloatmodknowsinverse@{#2}{\pgfmathfloatTRIG@NUM}{\pgfmathfloatTRIG@NUM@INV}% + \else + % trig format=rad + \expandafter\ifx\csname pgfmathfloatTRIG@rad@NUM\endcsname\relax% + % Lazy evaluation: + \pgfmathfloatcreate{1}{6.28318530717959}{0}% + \global\let\pgfmathfloatTRIG@rad@NUM=\pgfmathresult + \pgfmathfloatcreate{1}{1.59154943091895}{-1}% + \global\let\pgfmathfloatTRIG@rad@NUM@INV=\pgfmathresult + \fi + \pgfmathfloatmodknowsinverse@{#2}{\pgfmathfloatTRIG@rad@NUM}{\pgfmathfloatTRIG@rad@NUM@INV}% \fi - \pgfmathfloatmodknowsinverse@{#2}{\pgfmathfloatTRIG@NUM}{\pgfmathfloatTRIG@NUM@INV}% \pgfmathfloattofixed@{\pgfmathresult}% \expandafter#1\expandafter{\pgfmathresult}% \pgfmathfloatparsenumber{\pgfmathresult}% @@ -1618,11 +1680,19 @@ \fi \pgfmathfloatgreaterthan@{#1}{\pgfmathfloatatan@TMP}% \ifpgfmathfloatcomparison - \pgfmathfloatcreate{1}{9.0}{1}% + \pgfmathiftrigonometricusesdeg{% + \pgfmathfloatcreate{1}{9.0}{1}% + }{% + \pgfmathfloatcreate{1}{1.570796326794}{0}% + }% \else \pgfmathfloatlessthan{#1}{\pgfmathfloatatan@TMPB}% \ifpgfmathfloatcomparison - \pgfmathfloatcreate{2}{9.0}{1}% + \pgfmathiftrigonometricusesdeg{% + \pgfmathfloatcreate{2}{9.0}{1}% + }{% + \pgfmathfloatcreate{2}{1.570796326794}{0}% + }% \else \pgfmathfloattofixed@{#1}% \expandafter\pgfmath@basic@atan@\expandafter{\pgfmathresult}% @@ -1634,6 +1704,76 @@ }% \let\pgfmathfloatatan=\pgfmathfloatatan@ +\def\pgfmathfloatatantwo#1#2{% + % Note: first parameter is y (!), second is x (!) + \begingroup% + \let\pgfmath@trig@format@choice@@=\pgfmath@trig@format@choice + \def\pgfmath@trig@format@choice{0}% + % + \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E + \expandafter\pgfmathfloat@decompose#2\relax\pgfmathfloat@b@S\pgfmathfloat@b@M\pgfmathfloat@b@E + \ifnum\pgfmathfloat@a@S=0 + % ok, #1 = 0. Substitute by 1e-16 such that the next \ifnum catches it: + \pgfmathfloat@a@E=-16 % + \fi + % + \ifnum\pgfmathfloat@a@E<-3 % + \ifnum\pgfmathfloat@b@S=2 % + % #2 < 0 + \pgfmathfloatcreate{1}{1.8}{2}% +180 + \else + \ifnum\pgfmathfloat@b@S=1 % + % #2 >0 + \pgfmathfloatcreate{0}{0.0}{0}% + \else + % + or - 90, just use the sign of #1: + \pgfmathfloatcreate{\the\pgfmathfloat@a@S}{9.0}{1}% + \fi + \fi + \else% + \pgfmathfloatabs@{#1}\let\pgfmath@tempa\pgfmathresult% + \pgfmathfloatabs@{#2}\let\pgfmath@tempb\pgfmathresult% + \pgfmathfloatgreaterthan@{\pgfmath@tempa}{\pgfmath@tempb}% + \ifpgfmathfloatcomparison + \pgfmathfloatdivide@{#2}{\pgfmath@tempa}% + \expandafter\pgfmathfloatatan@\expandafter{\pgfmathresult}% + \let\pgfmath@tempa=\pgfmathresult + \pgfmathfloatcreate{1}{9.0}{1}% + \let\pgfmath@tempb=\pgfmathresult + \pgfmathfloatsubtract@{\pgfmath@tempb}{\pgfmath@tempa}% + \else% + \pgfmathfloatdivide@{\pgfmath@tempa}{#2}% + \expandafter\pgfmathfloatatan@\expandafter{\pgfmathresult}% + \expandafter\pgfmathfloatifflags\expandafter{\pgfmathresult}{2}{% + \let\pgfmath@tempa=\pgfmathresult + \pgfmathfloatcreate{1}{1.8}{2}% + \let\pgfmath@tempb=\pgfmathresult + \pgfmathfloatadd@{\pgfmath@tempa}{\pgfmath@tempb}% + }{}% + \fi% + % + \pgfmathfloatifflags{#1}{-}{% + % #1 < 0: + \pgfmathfloatmultiplyfixed@{\pgfmathresult}{-1}% + }{}% + \fi% + \if1\pgfmath@trig@format@choice@@ + % trig format=rad + \pgfmathfloat@scale@deg@to@rad\pgfmathresult + \fi + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +}% +\let\pgfmathfloatatantwo@=\pgfmathfloatatantwo +\expandafter\let\csname pgfmathfloatatan2\endcsname=\pgfmathfloatatantwo +\expandafter\let\csname pgfmathfloatatan2@\endcsname=\pgfmathfloatatantwo@ + +\def\pgfmathfloat@scale@deg@to@rad#1{% + \edef\pgfmathfloat@loc@TMPb{#1}% + \pgfmathfloatcreate{1}{1.74532925199433}{-2}% = pi / 180 + \pgfmathfloatmultiply@{\pgfmathresult}{\pgfmathfloat@loc@TMPb}% +}% + \def\pgfmathfloatsec@#1{\pgfmathfloatTRIG@\pgfmath@basic@cos@{#1}\pgfmathfloatreciprocal@{\pgfmathresult}} \let\pgfmathfloatsec=\pgfmathfloatsec@ \def\pgfmathfloatcosec@#1{\pgfmathfloatTRIG@\pgfmath@basic@sin@{#1}\pgfmathfloatreciprocal@{\pgfmathresult}} @@ -1664,16 +1804,24 @@ \expandafter\def\csname pgfmathfloatlog10@\endcsname#1{% \pgfmathfloatln@{#1}% - \let\pgfmathfloat@log@ten=\pgfmathresult + \let\pgfmathfloat@log@e=\pgfmathresult \pgfmathfloatcreate{1}{4.34294481903252}{-1}% 1/ln(10) - \pgfmathfloatmultiply@{\pgfmathresult}{\pgfmathfloat@log@ten}% + \pgfmathfloatmultiply@{\pgfmathresult}{\pgfmathfloat@log@e}% }% +\pgfutil@namelet{pgfmathfloatlog10}{pgfmathfloatlog10@}% + \expandafter\def\csname pgfmathfloatlog2@\endcsname#1{% \pgfmathfloatln@{#1}% - \let\pgfmathfloat@log@two=\pgfmathresult + \let\pgfmathfloat@log@e=\pgfmathresult \pgfmathfloatcreate{1}{1.44269504088896}{0}% 1/ln(2) - \pgfmathfloatmultiply@{\pgfmathresult}{\pgfmathfloat@log@two}% + \pgfmathfloatmultiply@{\pgfmathresult}{\pgfmathfloat@log@e}% }% +\pgfutil@namelet{pgfmathfloatlog2}{pgfmathfloatlog2@}% + +\expandafter\let\expandafter\pgfmathfloatlogtwo\csname pgfmathfloatlog2\endcsname +\expandafter\let\expandafter\pgfmathfloatlogtwo@\csname pgfmathfloatlog2@\endcsname +\expandafter\let\expandafter\pgfmathfloatlogten\csname pgfmathfloatlog10\endcsname +\expandafter\let\expandafter\pgfmathfloatlogten@\csname pgfmathfloatlog10@\endcsname % Computes log(x) into \pgfmathresult. % |