Überarbeitungsverlauf[Zurück]
Klicke auf Einblenden/Ausblenden von Überarbeitungen 2

21 Okt '18, 22:37

cis's gravatar image

cis
9.6k104461491

An sich kann man es so machen: \pgfmathfloatparsenumber{123.52} \pgfmathfloattomacro{\pgfmathresult}{\F}{\M}{\E} Flag: \F; Mantissa \M; Exponent \E $\to$ \pgfmathfloattofixed{\pgfmathresult} \pgfmathresult wobei `Flag` die Bedeutung hat: [![alt text][1]][2] Das Kommando \newcommand\foo[1]{ \pgfmathfloatparsenumber{#1} \pgfmathfloattomacro{\pgfmathresult}{\F}{\M}{\E} \pgfmathparse{\F==0 ? "$#1$ is zero" : ( \F==1 ? "$#1$ is positive" : ( \F==2 ? "$#1$ is negative" : ( \F==3 ? "$#1$ is a string (NaN)" : ( \F==4 ? "$\infty$" : ( \F==5 ? "$\infty$" "$-\infty$" : ("I do not know" ))))))}\pgfmathresult} liefert dann [![alt text][3]][4] \documentclass[border=3mm, varwidth]{standalone} \usepackage{tikz, amsmath} \usepgflibrary{fpu} % Das braucht man scheints: \pgfkeys{/pgf/fpu/handlers/invalid number/.code={% \pgfmathfloatparsenumber{3Y0.0e0]}% } } \begin{document} $\begin{array}{c | c} \text{Flag} & \text{Meaning} \\ \hline 0 & 0 \\ 1 & \text{positive} \\ 2 & \text{negative} \\ 3 & \text{NaN} \\ 4 & \infty \\ 5 & -\infty \\ \end{array}$ %Beispiel: %\pgfmathfloatparsenumber{123.52} %\pgfmathfloattomacro{\pgfmathresult}{\F}{\M}{\E} %Flag: \F; Mantissa \M; Exponent \E %$\to$ \pgfmathfloattofixed{\pgfmathresult} \pgfmathresult \newcommand\foo[1]{ \pgfmathfloatparsenumber{#1} \pgfmathfloattomacro{\pgfmathresult}{\F}{\M}{\E} \pgfmathparse{\F==0 ? "$#1$ is zero" : ( \F==1 ? "$#1$ is positive" : ( \F==2 ? "$#1$ is negative" : ( \F==3 ? "$#1$ is a string (NaN)" : ( \F==4 ? "$\infty$" : ( \F==5 ? "$\infty$" "$-\infty$" : ("I do not know" ))))))}\pgfmathresult} \foreach \Test in {1,-1,0,1.23,a,sin(30)}{\foo{\Test} \\} Aber: % \foo{\frac32} % error \end{document} [![alt text][5]][5] [1]: https://texwelt.de/wissen/upfiles/1_21.png [2]: https://texwelt.de/wissen/upfiles/1_21.png [3]: https://texwelt.de/wissen/upfiles/2_15.png [4]: https://texwelt.de/wissen/upfiles/2_15.png [5]: https://texwelt.de/wissen/upfiles/55555555_252.png
Klicke auf Einblenden/Ausblenden von Überarbeitungen 1

21 Okt '18, 15:41

cis's gravatar image

cis
9.6k104461491

An sich kann man es so machen: \pgfmathfloatparsenumber{123.52} \pgfmathfloattomacro{\pgfmathresult}{\F}{\M}{\E} Flag: \F; Mantissa \M; Exponent \E $\to$ \pgfmathfloattofixed{\pgfmathresult} \pgfmathresult wobei `Flag` die Bedeutung hat: [![alt text][1]][2] Das Kommando \newcommand\foo[1]{ \pgfmathfloatparsenumber{#1} \pgfmathfloattomacro{\pgfmathresult}{\F}{\M}{\E} \pgfmathparse{\F==0 ? "$#1$ is zero" : ( \F==1 ? "$#1$ is positive" : ( \F==2 ? "$#1$ is negative" : ( \F==3 ? "$#1$ is a string (NaN)" : ( \F==4 ? "$\infty$" : ( \F==5 ? "$\infty$" : ("I do not know" ))))))}\pgfmathresult} liefert dann [![alt text][3]][4] \documentclass[border=3mm, varwidth]{standalone} \usepackage{tikz, amsmath} \usepgflibrary{fpu} % Das braucht man scheints: \pgfkeys{/pgf/fpu/handlers/invalid number/.code={% \pgfmathfloatparsenumber{3Y0.0e0]}% } } \begin{document} $\begin{array}{c | c} \text{Flag} & \text{Meaning} \\ \hline 0 & 0 \\ 1 & \text{positive} \\ 2 & \text{negative} \\ 3 & \text{NaN} \\ 4 & \infty \\ 5 & -\infty \\ \end{array}$ %Beispiel: %\pgfmathfloatparsenumber{123.52} %\pgfmathfloattomacro{\pgfmathresult}{\F}{\M}{\E} %Flag: \F; Mantissa \M; Exponent \E %$\to$ \pgfmathfloattofixed{\pgfmathresult} \pgfmathresult \newcommand\foo[1]{ \pgfmathfloatparsenumber{#1} \pgfmathfloattomacro{\pgfmathresult}{\F}{\M}{\E} \pgfmathparse{\F==0 ? "$#1$ is zero" : ( \F==1 ? "$#1$ is positive" : ( \F==2 ? "$#1$ is negative" : ( \F==3 ? "$#1$ is a string (NaN)" : ( \F==4 ? "$\infty$" : ( \F==5 ? "$\infty$" : ("I do not know" ))))))}\pgfmathresult} \foreach \Test in {1,-1,0,1.23,a,sin(30)}{\foo{\Test} \\} Aber: % \foo{\frac32} % error \end{document} [![alt text][5]][5] [1]: https://texwelt.de/wissen/upfiles/1_21.png [2]: https://texwelt.de/wissen/upfiles/1_21.png [3]: https://texwelt.de/wissen/upfiles/2_15.png [4]: https://texwelt.de/wissen/upfiles/2_15.png [5]: https://texwelt.de/wissen/upfiles/55555555_252.png