Gibt es eigentlich von pgfmath (!) eine Funktion, mit etwa folgenden Eigenschaften:

alt text

Öffne in Overleaf
\documentclass[]{article}
\usepackage{tikz}
\usepackage{array}

\begin{document}
\def\myarray{{1,0,"-1","a"}}
\foreach \i in {0,...,3}{\pgfmathparse{\myarray[\i]}$\pgfmathresult$~ }

\pgfmathsetmacro\t{"1"}
\pgfmathparse{"\t" > 0 ? "ja" : "\t"}$\pgfmathresult$ \\

\newcolumntype{B}{ >{\bfseries}l  }
\begin{tabular}{B l B  l }
in: &   \verb+\foo{a}+  & out: & $a$ ist ein String  \\
in: &   \verb+\foo{\frac32}+  & out: & $\frac32$ ist ein String  \\
in: &   \verb+\foo{-1.2}+  & out: & $-1.2$ ist negativ  \\
in: &   \verb+\foo{0}+  & out: & $0$ ist Null\\
in: &   \verb+\foo{2}+  & out: & $2$ ist positiv  \\
\end{tabular}
\end{document}

gefragt 20 Okt '18, 13:21

cis's gravatar image

cis
9.5k75452491
Akzeptiert-Rate: 29%

Ich glaube mit \usetikzlibrary{math} könnte das gehen.

(21 Okt '18, 03:43) cis
(21 Okt '18, 03:44) cis

An sich kann man es so machen:

Öffne in Overleaf
\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

Das Kommando

Öffne in Overleaf
\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

Öffne in Overleaf
\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

Permanenter link

beantwortet 21 Okt '18, 15:41

cis's gravatar image

cis
9.5k75452491
Akzeptiert-Rate: 29%

bearbeitet 21 Okt '18, 22:37

Deine Antwort
Vorschau umschalten

Folgen dieser Frage

Per E-Mail:

Wenn sie sich anmelden, kommen Sie für alle Updates hier in Frage

Per RSS:

Antworten

Antworten und Kommentare

Markdown-Grundlagen

  • *kursiv* oder _kursiv_
  • **Fett** oder __Fett__
  • Link:[Text](http://url.com/ "Titel")
  • Bild?![alt Text](/path/img.jpg "Titel")
  • nummerierte Liste: 1. Foo 2. Bar
  • zum Hinzufügen ein Zeilenumbruchs fügen Sie einfach zwei Leerzeichen an die Stelle an der die neue Linie sein soll.
  • grundlegende HTML-Tags werden ebenfalls unterstützt

Frage-Themen:

×728
×13

gestellte Frage: 20 Okt '18, 13:21

Frage wurde gesehen: 4,316 Mal

zuletzt geändert: 21 Okt '18, 22:37