lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In message <20090810075950.B3576@lua.tecgraf.puc-rio.br> you wrote:

> > In my experience, Lua with a 32-bit integer core is covering 95+% of
> > our needs. However, sometimes you just need to represent something
> > that is larger (file/disk sizes, traffic counters, ...) or you need
> > non-integer arithmetic. Using userdata in these cases is just awkward.
>
> Why is it awkward? I se that creating an object is a bit awkward, as in
> .....
> but from then on the metamethods should make it transparent:
> x = (r+2/r)/2
> Am I missing something?

RiscLua ( http://lua.riscos.org.uk/ ) uses a 32-bit integer core
and implements doubles as userdata, using metamethods for as much
syntactic sugar as possible. The only delicate point is the difference
between copying and non-copying assignment. I hope that
the RiscLua notation makes the difference clear:

  x = @ '0.5'
  y = x -- still only one number in heap
  z = @(x) -- now there are two
  x:add(7)  -- x is updated, z is not
  w = z + 11 -- now there are three
  print(y,",",z,",",w) --> 7.5,0.5,11.5

Actually, from the point of view of memory economy, lots of standard
numerical calculations (e.g. Horner's rule) are better served by
updateable numbers.

-- 
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/