[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: problem with string.format %d and very large integers
- From: Steve Litt <slitt@...>
- Date: Fri, 29 Jul 2011 10:49:47 -0400
On Friday, July 29, 2011 07:30:10 AM Lorenzo Donati wrote:
> On 29/07/2011 10.54, Dirk Laurie wrote:
> > On Fri, Jul 29, 2011 at 09:22:33AM +0200, Lorenzo Donati wrote:
> >> Is there someone else that gets the same results on WinXP
> >> (32bit) with (TDM) mingw?
> >>
> >> Any hint appreciated.
> >
> > Install cygwin and gcc.
>
> Thanks, but that is not an option for me. I need native Windows
> executables, without compatibility layers (moreover, at the time I
> last checked, cygwin.dll had a quite restrictive license).
Yeah, when I read the cygwin suggestion it sounded like a workaround
that might not be practical.
I have no idea how often you need correct functionality of %d in
string.format, but maybe, until this unexpected inconsistent behavior
is converted to a consistent behavior, you could write your own
decimal2string(num, width, decimalplaces) function, and then just use
%s in string.format. Crude, ugly, should be unnecessary, but these
things happen, and I've found sometimes the easiest thing is to write
a workaround until the next version fixes the bug.
You could implement this function in C if practical, or otherwise in
Lua if where it's deployed can't compile C. The C would obviously be
faster and perhaps easier (I think you just use itoa() or ltoa or
sprintf() with a %f or something similar), but if you don't use this
function all over the place or in tight inner loops, the speed
differential would be meaningless.
HTH
SteveT
Steve Litt
Author: The Key to Everyday Excellence
http://www.troubleshooters.com/bookstore/key_excellence.htm
Twitter: http://www.twitter.com/stevelitt