Take the 2-minute tour ×
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.

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}$:

\documentclass{article}
\usepackage{expl3}

\begin{document}

\ExplSyntaxOn

\fp_set:Nn\a_fp{0.04}
\fp_pow:Nn\a_fp{0.5}
\fp_use:N\a_fp\par    %wrong

\fp_set:Nn\a_fp{4.0}
\fp_pow:Nn\a_fp{0.5}
\fp_use:N\a_fp\par    %ok

\fp_set:Nn\a_fp{9.0}
\fp_pow:Nn\a_fp{0.5}
\fp_use:N\a_fp\par    %wrong

\fp_set:Nn\a_fp{16.0}
\fp_pow:Nn\a_fp{0.5}
\fp_use:N\a_fp\par    %wrong

\ExplSyntaxOff

\end{document}
share|improve this question
1  
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
add comment

2 Answers

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:
  {
    \group_begin:
      \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
      \fp_ln_internal:
      \cs_set_protected_nopar:Npx \fp_tmp:w
        {
          \group_end:
          \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:
        }
    \fp_tmp:w
    \l_fp_input_a_extended_int  \c_zero
    \fp_mul:NNNNNNNNN
      \l_fp_input_a_integer_int \l_fp_input_a_decimal_int
        \l_fp_input_a_extended_int
      \l_fp_input_b_integer_int \l_fp_input_b_decimal_int
        \l_fp_input_b_extended_int
      \l_fp_output_integer_int \l_fp_output_decimal_int
        \l_fp_output_extended_int
    \l_fp_output_exponent_int
      \int_eval:w
        \l_fp_input_a_exponent_int + \l_fp_input_b_exponent_int
      \scan_stop:
    \fp_extended_normalise_output:
    \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
    \fp_exp_internal:
  }
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
add comment

Interestingly enough

\fp_set:Nn\a_fp{0.04}
\fp_ln:Nn\a_fp{\a_fp}
\fp_div:Nn\a_fp{2}
\fp_exp:Nn\a_fp{\a_fp}
\fp_use:N\a_fp\par

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
add comment

Your Answer

 
discard

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.