lua-users home
lua-l archive

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


Useful reference on the subject:

Clinger, William D. How to read floating point numbers accurately. In [ACM PLDI, 1990], pp. 92--101. 

http://citeseer.ist.psu.edu/clinger90how.html  


On Jan 29, 2007, at 8:00 PM, David Burgess wrote:

To me this raises the question as to whether the way out of the CRT mess
is to implement as part of standard Lua the function ua_str2number().
Restated the implementation of lua_str2number().is provided.
As Rici has demonstrated, it is not a lot of code.
So rather than having everyone complain about variant behaviours with
strtod() we could solve the problem with lua_strtod().
And maybe the same can be said for strtoul().

Agreement anyone?

db


Rici Lake wrote:

On 29-Jan-07, at 5:12 PM, Mike Pall wrote:

> The behaviour of number parsing and output is system dependent
> because Lua uses the library functions provided by the toolchain.
> This makes sense because some implementations need more lines of
> code for this task than Lua itself. ;-)

OK, it's a little longer than I hoped it might be (127 including
comments and test driver / 72 actually in the function) but it's still
somewhat smaller than Lua. Of course, it only does hex floats (doubles,
actually, but a simple %s/double/float/g should fix that.)






--
Gé Weijers