I have a problem about calculator package, I need check if #1 is a number or not, could I use conditional command?
ex:
\def\CHECK#1{
% if #1 a number
\if...?
#1 is a number
\else
#1 is not a number
\fi
}
\CHECK{3}
\CHECK{n}
I have a problem about calculator package, I need check if #1 is a number or not, could I use conditional command?
ex:
\def\CHECK#1{
% if #1 a number
\if...?
#1 is a number
\else
#1 is not a number
\fi
}
\CHECK{3}
\CHECK{n}
This is perhaps too much, but I tried to use l3regex and checking whether the argument of #1 contains any non-digit using the 'negative class' [^0-9] as regular expression.
A better approach would use a conditional, but until the context isn't clear, I restrict to this solution.
\documentclass{article}
\usepackage{xparse}
\usepackage{l3regex}
\ExplSyntaxOn
\newcommand{\CHECK}[1]{
\regex_match:nnTF {[^0-9]} {#1}{
#1~is~not~an~integer}{
#1~is~a~integer}
}% End of \CHECK definition
\ExplSyntaxOff
\begin{document}
\CHECK{1234234}
\CHECK{foo}
\CHECK{234.4523}
\end{document}
[latex]\sum\limits_{k=0}^{n}2^k=1+2+2^2+\ldots+2^{n-1}+2^n[/latex]
else
[latex]\sum\limits_{k=0}^{2016}2^k=1+2+2^2+\ldots+2^{2015}+2^2016 [/latex]
I need check a number that I can
[code]\def \SUM#1{
% check #1 is a number or not, if #1 is a number
$\sum\limits_{k=0}^{#1}2^k=1+2+2^2+\ldots+2^{\SUBTRACT{#1}{1} {\sol}\sol}+2^{#1}$ \else $\sum\limits_{k=0}^{n}2^k=1+2+2^2+\ldots+2^{n-1}+2^n$ \fi } \SUM{n} \SUM{2016} [/code]
Which conditional command can use?
– phanttam Feb 03 '16 at 22:26
numberisn't unique -- I think, you mean an integer number? Knowing more of the context would be helpful. – Feb 03 '16 at 21:53calculatorseems to accept both integer and floating point numbers. As such, the linked post should suffice to check whether the input tocalculatorfunctions are (not) acceptable. – Werner Feb 03 '16 at 22:15