[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: problem with formatting large integers
- From: "Joseph Manning" <manning@...>
- Date: Fri, 15 Apr 2011 22:18:45 +0100 (IST)
On Fri, April 15, 2011 21:57, Roberto Ierusalimschy wrote:
>>> 4) Modify the current implementation of "string.format" so that all
>>> "%i" (and "%d") conversions are intercepted and replaced by the
>>> equivalent "%.0f" conversions, before then calling C's "sprintf".
>>> This, imho, is the best overall approach.
>>
>> The problem with this option is that %.0f does not accept the same
>> options as %i (e.g., "%i.4").
Umm ... what does "%i.4" do?
BTW, in my original post, when I suggested converting "%i" into "%.0f",
I meant of course to include field widths as well, so that, for example,
"%12i" converts to "%12.0f", etc.
>> Another, and maybe
better, option is
>> to compile Lua with the LUA_USELONGLONG option (on systems that
>> support long long).
But surely "%i" should be made to work correctly in ALL situations,
regardless of which particular compile-time options were chosen.
There's hardly a genuine situation in which
string.format( "%i", 2^31 ) --> -2147483648
is a reasonable or desirable outcome?
------------------------------------------------------------------------
Joseph Manning / Computer Science / UCC Cork Ireland / manning@cs.ucc.ie
------------------------------------------------------------------------