To compare arbitrarily big decimal rational numbers (for example 3.141592
versus 2.1782817828
) you could use package xintfrac.
Particularly since 1.09a (2013/09/24)
it provides \xintifEq{A}{B}{<do this if A=B>}{<do that if A\neq B>}
.
Here A
and B
may be (big) integers, decimal numbers (with scientific part), or fractions, or macros expanding to such things.
\documentclass{article}
\usepackage{xintfrac}
\newcommand*\equalitytest[2]{%
\xintifEq{#1}{#2}{#1 is equal to #2}{#1 is unequal to #2}%
}%
\begin{document}
\equalitytest{3.141529653}{355/113}
\equalitytest{2.718281828459045}{2718.281828459045/1000}
\end{document}

original answer (before addition of \xintifEq
to xintfrac
)
\xintCmp{A}{B}
returns -1
, 0
, or 1
if A<B
, A=B
, A>B
. A
and B
may be decimal numbers, or fractions, or macros expanding to such things.
And \xintSgnFork{\x}{I}{II}{III}
does I
if \x
expands to -1
, II
if 0
, and III
if 1
.
\documentclass{article}
\usepackage{xintfrac}
% arguments may be decimal numbers such as 3.14
% or fractions such as 355/113
% this is an expandable command
% (its arguments may be macros expanding to the numbers or fractions)
\newcommand*\equalitytest[2]{%
\xintSgnFork{\xintiAbs{\xintCmp{#1}{#2}}}% -1 converted into 1
{}% -1: does not happen
{equal}% \xintCmp returned 0
{unequal}% \xintCmp returned -1 or 1.
}%
\begin{document}
\equalitytest{3.141529653}{355/113} (355/113=\xintTrunc{10}{355/113}...) %unequal
\equalitytest{2.718281828459045}{2718.281828459045/1000} % equal
\end{document}
