6

I just discovered that we can now create new functions (fp words) that can be evaluated inside \fp_eval:n per page 273 of interface3.pdf (it also seems to work with \fpeval). This is straightforward as the demo shows.

What if I want, or need, to manipulate the function arguments to get the returned result? I can't get that to work. This functionality may not be provided yet, but I don't see it mentioned in the documentatin and searching this site turned up nothing (or I somehow missed it).

MWE:

% !TEX program = lualatexmk
% !TEX encoding = UTF-8 Unicode

\documentclass{article}

\ExplSyntaxOn
% This works.
\fp_new_function:n { npow }
\fp_set_function:nnn { npow } { a,b } { a**b }

% This does not work.
\fp_new_function:n { biggerof }
\fp_set_function:nnn { biggerof } { a,b } 
  {
    \fp_compare:nTF { a < b }
    { b }
    { a }
  }
\ExplSyntaxOff

\begin{document}
\( \alpha = \fpeval{npow(2,3)} \)

\( \alpha = \fpeval{biggerof(2,3)} \)
\end{document}
2
  • I don't think you can b/c 'These functions ... should be implemented using expansion methods only' and I don't think the comparison qualifies. (but I do not really understand what counts as an 'expansion method'). Commented 12 hours ago
  • you can use the provided way to compare, though i.e. you can write \fpeval{2 < 3 ? 3 : 2} but that probably is not what you were hoping for. Commented 12 hours ago

1 Answer 1

7

Whilst the symbolic code is very cool, it's not set up for all possible functions from l3fp. In particular, as you've noticed, it's not available for \fp_compare:nTF (or related functions). It will work for

  • Core arithmetic functions: +, -, *, /, ^, &, |
  • Built-in functions acos, acsc,asec, asin, cos, cot, csc, exp, fact, ln, not, sec, set_sign, sin, sign, sqrt, tan
  • Expandable functions from other modules (those marked with a * in interface3
  • Expandable commands/functions using only the above

The sources say

The following functions are not implemented: min, max, ?:, comparisons, round, atan, acot.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.