TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to draw the square-root from a rational number using the l3fp package. As the package does not provide an sqrt function, I played with \fp_pow:Nn. Unfortunately, I could only get the correct result for $\sqrt{4}$:




\fp_use:N\a_fp\par    %wrong

\fp_use:N\a_fp\par    %ok

\fp_use:N\a_fp\par    %wrong

\fp_use:N\a_fp\par    %wrong


share|improve this question
There is an open bug report on this (github.com/latex3/svn-mirror/issues/10). Currently, fixing it has not been high-priority as (1) we are not using powers for typesetting and (2) Bruno Le Floch is working on an overall reimplementation of the module which will be more robust/efficient and also expandable. I will see if I can fix it: the code for this part is not very easy to follow. – Joseph Wright May 31 '11 at 13:01
@Joseph: Thanks for the pointer. I searched the bugs on latex-project but didn't find anything related. – AlexG May 31 '11 at 13:08
Bugs for LaTeX3 are currently collected on GitHub. The main Project bugs database is better suited to a mature system than the transitory stuff we get for expl3. – Joseph Wright May 31 '11 at 13:37
up vote 2 down vote accepted

As Joseph said, the code is quite intricate. The bug should be fixed in the SVN (and probably in the next week or so on CTAN with the next update of expl3).

If you cannot wait, you can also redefine the offending function \fp_pow_aux_iv:. Only the end changes, but the function is massive.

\cs_set_protected_nopar:Npn \fp_pow_aux_iv:
      \l_fp_input_a_integer_int  \l_fp_input_b_integer_int
      \l_fp_input_a_decimal_int  \l_fp_input_b_decimal_int
      \l_fp_input_a_exponent_int \l_fp_input_b_exponent_int
      \cs_set_protected_nopar:Npx \fp_tmp:w
          \exp_not:N \l_fp_input_b_sign_int
            \int_use:N \l_fp_output_sign_int \scan_stop:
          \exp_not:N \l_fp_input_b_integer_int
            \int_use:N \l_fp_output_integer_int \scan_stop:
          \exp_not:N \l_fp_input_b_decimal_int
            \int_use:N \l_fp_output_decimal_int \scan_stop:
          \exp_not:N \l_fp_input_b_extended_int
            \int_use:N \l_fp_output_extended_int \scan_stop:
          \exp_not:N \l_fp_input_b_exponent_int
            \int_use:N \l_fp_output_exponent_int \scan_stop:
    \l_fp_input_a_extended_int  \c_zero
      \l_fp_input_a_integer_int \l_fp_input_a_decimal_int
      \l_fp_input_b_integer_int \l_fp_input_b_decimal_int
      \l_fp_output_integer_int \l_fp_output_decimal_int
        \l_fp_input_a_exponent_int + \l_fp_input_b_exponent_int
    \tex_multiply:D \l_fp_input_a_sign_int \l_fp_input_b_sign_int
    \l_fp_input_a_integer_int  \l_fp_output_integer_int
    \l_fp_input_a_decimal_int  \l_fp_output_decimal_int
    \l_fp_input_a_extended_int \l_fp_output_extended_int
    \l_fp_input_a_exponent_int \l_fp_output_exponent_int
    \l_fp_output_integer_int  \c_zero
    \l_fp_output_decimal_int  \c_zero
    \l_fp_output_extended_int \c_zero
    \l_fp_output_exponent_int \c_zero
    \cs_set_eq:NN \fp_exp_const:Nx \use_none:nn
share|improve this answer
Many thanks, @Bruno. I updated l3kernel this morning and everything works as expected now. – AlexG Jun 6 '11 at 7:50
@Alexander: thank Joseph Wright for most of the fp module. I'm working hard on a complete rewrite with 16 significant digits, proper handling of exceptions, and "exact" rounding (as per IEEE 854), and realising that it is hard to do better than the current. – Bruno Le Floch Jun 6 '11 at 8:37

Interestingly enough


prints 0.2000000010, but using 4 as argument prints 1.999999999.

After \fp_set:Nn\a_fp{0.04} and \fp_pow:Nn\a_fp{0.5}, \fp_show:N\a_fp shows +2.624477407e0. When used with 4 it shows +2.000000000e0. When used with 400 it says "Number too big"!

Note: my version of l3fp.sty is l3fp.dtx 2201 2011-03-19 17:16:13Z

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.