# On the xfp package: Comparison

On page 1/2 of the xfp package we read:

• The floating point expressions may comprise:Comparison operators: x < y, x <= y, x >? y, x ! = y etc. However they did not show an example. Below I have an example in which I use \fpeval{\x<\y } to make a decision in a conditional command:

\documentclass{article}
\usepackage{xfp, ifthen}
\begin{document}
\edef\x{6.25}
\edef\y{-2}
\noindent $x=\fpeval{\x}$.\\
$y=\fpeval{\y}$.\\
\ifthenelse{\fpeval{\x<\y }}
{$x\lt y$}
{$x\ge y$}
\end{document}


But got an error:

! Missing = inserted for \ifnum. \relax l.10 \ifthenelse{\fpeval{\x<\y }}

Do you know how to fix it?

• I think \fpeval is supposed to evaluate to a number. I don't know the full rules, but I'd guess it's 1 if the test is true and 0 otherwise. In that case you'd want \ifthenelse{\fpeval{\x<\y }=1}. If it's 0 if the test is false and non-zero otherwise, you'd probably want to go for \ifthenelse{\fpeval{\x<\y }=0} and invert the logic. Commented Aug 14, 2020 at 5:56
– Aria
Commented Aug 14, 2020 at 5:59
• @moewe would you please write ur answer below then I accept it?
– Aria
Commented Aug 14, 2020 at 6:00
• related Why use xfp rather than fp? Commented Aug 14, 2020 at 6:16

The first argument to \ifthenelse must contain a test (by default a test on integer equality).

You could do \ifthenelse{\fpeval{\x<\y}=1}{...}{...} which would return true if \x is actually less than \y.

Example:

\documentclass{article}
\usepackage{xfp,ifthen}

\begin{document}

\def\x{6.25}
\def\y{-2}

\ifthenelse{\fpeval{\x<\y}=1}{TRUE}{FALSE} (should be F)

\ifthenelse{\fpeval{\y<\x}=1}{TRUE}{FALSE} (should be T)

\end{document}


With more flexible (and fully expandable) code that I already suggested you

\documentclass{article}
\usepackage{xfp,xparse}

\usepackage{xparse}

\ExplSyntaxOn
\NewExpandableDocumentCommand{\xifthenelse}{mmm}
{
\bool_if:nTF { #1 } { #2 } { #3 }
}

\cs_new_eq:NN \numtest     \int_compare_p:n
\cs_new_eq:NN \oddtest     \int_if_odd_p:n
\cs_new_eq:NN \fptest      \fp_compare_p:n
\cs_new_eq:NN \dimtest     \dim_compare_p:n
\cs_new_eq:NN \deftest     \cs_if_exist_p:N
\cs_new_eq:NN \namedeftest \cs_if_exist_p:c
\cs_new_eq:NN \eqdeftest   \token_if_eq_meaning_p:NN
\cs_new_eq:NN \streqtest   \str_if_eq_p:ee
\cs_new_eq:NN \emptytest   \tl_if_blank_p:n
\prg_new_conditional:Nnn \xxifthen_legacy_conditional:n { p,T,F,TF }
{
\use:c { if#1 } \prg_return_true: \else: \prg_return_false: \fi:
}
\cs_new_eq:NN \boolean \xxifthen_legacy_conditional_p:n
\ExplSyntaxOff

\begin{document}

\def\x{6.25}
\def\y{-2}

\xifthenelse{\fptest{\x<\y}}{TRUE}{FALSE} (should be F)

\xifthenelse{\fptest{\y<\x}}{TRUE}{FALSE} (should be T)

\end{document}