TeX - LaTeX Asked on May 17, 2021
On page 1/2 of xfp package we see x >? y
as a valid comparison operator. Is it different from x>y
?
I think they are equivalent based on my following code, but not sure:
documentclass{article}
usepackage{,xfp}
begin{document}
edefx{5}
edefy{6}
fpeval{x>? y}
fpeval{x> y}
end{document}
The result for both is zero. So are they equivalent in general?
The question mark ?
is the “not ordered” comparison of l3fp
. More or less quoting from the documentation of fp_compare_p:nNn
:
x ? y
is true ifx
andy
are “not ordered” which occurs exactly if one or both operands isnan
or is a tuple. Note thatnan
is distinct from any other value, even from itself, i.e. ifx = nan
thenx == x
is false. To test whether a value isnan
you can use the “not ordered” comparison with any other value, e.g.x ? 0
.
That also means that if neither x
nor y
are nan
or a tuple, the comparison x >? y
will be equivalent to x > y
.
Personal note: I'm rather skeptical of the usefulness of this “not ordered” comparison. It seems to me that this is trying to solve a problem that is already covered by other operators. For example in a traditional programming language, like C, you can check for nan
by checking whether a value is equal to itself, i.e. x == x
will only ever be false, if x
is nan
. For comparison between tuples, all operators should just return false
(or better throw a type error), except for ==
and !=
which ought to perform and element-wise comparison.
Correct answer by Henri Menke on May 17, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP