TransWikia.com

The difference between {x >y} and {x >? y} in xfp package?

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?

One Answer

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 if x and y are “not ordered” which occurs exactly if one or both operands is nan or is a tuple. Note that nan is distinct from any other value, even from itself, i.e. if x = nan then x == x is false. To test whether a value is nan 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

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP