Re-compile lua to use double precision for floating-point numbers

Delbert Franz ddf at
Mon May 3 14:01:41 EDT 2010

Thanks, Mirko.  After I sent the E-mail, I had another inspiration on 
how to find out what was needed to accomplish my goal: 

1.  By looking at the output from "make V=99" after doing a "make clean" 
(takes a bit less than 3 hours on my Intel i7), I found out where the 
original package for lua was stored.  I copied that to a temp location 
and discovered that none of the "extra" files were present.  

2.  I saw that there were several patches that created completely new 
files.  One of these was lnum_config.h and the first patch in the list 
created it.  

3.  Then in ../openwrt-xburst/package/lua/patches (the .. is whatever 
top level directory name you used when creating the tool chain) I made 
one change to the first patch file: 010-lua-5.1.3-lnum-full-260308.patch, 
at line 1852: 

Original line:

+# define LNUM_FLOAT

Changed line:
+# define LNUM_DOUBLE

Then returned to  the directory: ../open-xburst
and executed

make package/lua/compile V=99 >& make_just_lua.out

where: "make_just_lua.out"
is a file containing  the output from the command.  If everything
goes well you should find two new packages in 


4.  Copy these two files to some convenient location on your 
filesystem on the Ben.  

5.  Then you have to remove the existing Lua.  Of course if you want 
to return to the original package, you will have to find it somewhere, 
I took mine from an earlier compile of a custom image, and have it 
available to reinstall Lua.  To remove lua and lualib 

opkg remove lua
opkg remove lualib

You will get some error messages about some files not found-- I just 
ignored them:) 

6. Then install the new version

opkg install liblua_5.1.4-6_xburst.ipk  lua_5.1.4-6_xburst.ipk

You will again get some error messages: just ignore them.  Maybe in 
the next month or two those will go away as the software packages 

I did a test run of a simple prime-number routine.  With single 
precision I could find the number of primes less than about 2,000,000, 
before Lua reported "not enough memory".  With double precision, I 
could find the number of primes less than about 1,000,000, which is 
just what I expected.  However, the run time only increased by about 
10 per cent!  Not bad for such a tiny machine.

Now I can do some more benchmarks and see if double precision is "too 
slow".  Of course, "too slow" depends on the application and the 
expectations of the user:) 

Thanks to all the crew that made this fascinating device both 
available, open, and more fun than a "barrel of monkeys." 


On Monday 03 May 2010, Mirko Vogt wrote:
> You could remove all patches, as they're mostly just to avoid
> performance issues :)
> mirko
> On Sun, 2010-05-02 at 14:42 -0700, Delbert Franz wrote:
> > I'm trying to set the values for Lua so that it will use double 
> > precision for floating point numbers.  Yes, I know it will be slow:) 
> > However, I am trying to compare the Nanonote to some other small 
> > computers I have, and all of them come with Lua set to use double 
> > precision for floating-pint numbers.  Since I am already doing a 
> > custom image for the Nanonote I thought it should not be that hard to 
> > get Lua compiled to do the same:) 
> > 
> > Well, it turns out to be rather too complex for me:( The latest 
> > version of Lua (5.1.4) from its website has a luaconf.h which contains 
> > the number definition.  Openwrt extensively patches/modifies this so 
> > that in addition to luaconf.h, there is a lnum_config.h file as well.  
> > Not having programmed in C for some decades, all of my attempts ended 
> > either not changing the number representation or in changing it in 
> > such a way that parts were broken.  
> > 
> > Does anyone on this list know what changes are required in luaconf.h 
> > and lnum_config.h so that Lua will properly use double-precision 
> > floating point numbers?  If not, what is the best place within the 
> > OpenWRT community to inquire as to how that should be done?  
> > 
> >                       Delbert
> > 
> > 
> > 
> > 
> > 
> > _______________________________________________
> > discussion mailing list
> > discussion at
> >
> -- 
> This email address is used for mailinglist purposes only.
> Non-mailinglist emails will be dropped automatically.
> If you want to get in contact with me personally, please mail to:
> mirko.vogt <at> nanl <dot> de
> _______________________________________________
> discussion mailing list
> discussion at

More information about the discussion mailing list