LATEX-L Archives

Mailing list for the LaTeX3 project


Options: Use Classic View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Date: Tue, 15 Jun 2010 22:04:04 +0100
Reply-To: Mailing list for the LaTeX3 project <[log in to unmask]>
MIME-Version: 1.0
Message-ID: <[log in to unmask]>
Content-Transfer-Encoding: 7bit
Sender: Mailing list for the LaTeX3 project <[log in to unmask]>
From: Joseph Wright <[log in to unmask]>
Parts/Attachments: text/plain (49 lines)
Hello all,

Those of you who take an interest in the LaTeX3 SVN may have noticed 
that I've just added the beginnings of a 'l3fp' module as part of expl3. 
This is intended to provide a set of floating point functions for LaTeX3.

As you'll all know, floating point work in TeX is not exactly easy 
(excepting when using LuaTeX, where of course the Lua route is 
available). The aim of l3fp is to provide accurate floating point 
functions (i.e. not using dimens) with a reasonable range of input and 
written for speed so that the module is generally useful.

At the moment there are only a small set of basic arithmetic functions 
available in l3fp. So for example there is

   \fp_add:Nnn <var> <a> <b>

which adds <a> and <b> and assigns the result to <var>. I've also 
defined an 'fp' data type, which is currently simply a macro which 
contains a number. So there is also a function

   \fp_add:Nn <var> <a>

which adds <a> to the current content of <var> (which of course should 
be an fp).

In terms of input range, I've gone for -999999999.999999999 to 
+999999999.999999999. This should be sufficient for a wide range of 
purposes (for example, if you convert a dimen into a floating point 
number in units pt then you are safe for any dimen TeX can handle).

The design of the internals of the package is loosely following the 
well-known fp package. However, that package is rather slow, at least 
partly as it handles 18 digits either side of the decimal. The approach 
in l3fp currently delivers addition, subtraction, multiplication and 
division much faster than fp does (between about 8 and 15 times as fast 
for a large number of repeated calculations). I hope this makes the 
module fast enough for practical use.

The next phase is to add some more complex functions. I'm planning to 
cover trigonometry, exponential/ln and roots, plus a pseudo-random 
number generator and a few utility functions. They may take a while: 
getting it right is not that easy.

Feedback on the module is very welcome, for example on which functions 
to provide, bugs (there are bound to be some), etc.
Joseph Wright