 |
Icy North Technologies User Forums
|
| View previous topic :: View next topic |
| Author |
Message |
nanotiger
Joined: 12 Dec 2009 Posts: 2
|
Posted: Sat Dec 12, 2009 11:53 am Post subject: string format %x of negative number |
|
|
Hi,
This is a simple question that puzzles me. Why string.format("%u %x %X") outputs 0 for all negative numbers.
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> = string.format("%d, %i, %u, %x, %X", -100,-100, -100, -100, -100)
-100, -100, 0, 0, 0 |
|
| Back to top |
|
 |
lhf
Joined: 20 Feb 2006 Posts: 175 Location: Rio de Janeiro, Brazil
|
Posted: Sat Dec 12, 2009 7:27 pm Post subject: |
|
|
Under Linux and Mac OS X, I get
-100, -100, 4294967196, ffffff9c, FFFFFF9C
Anyway, %u, %x, %X only handles unsigned numbers. |
|
| Back to top |
|
 |
nanotiger
Joined: 12 Dec 2009 Posts: 2
|
Posted: Sat Dec 12, 2009 8:13 pm Post subject: |
|
|
Weird, I've tested it on Mac OSX and an embedded system with ARM processor. Both report
> = string.format("%d, %i, %u, %x, %X", -100,-100, -100, -100, -100)
-100, -100, 0, 0, 0
I would expect Lua handles %u, %x, %X as in C just like your result.
int main()
{
printf("%d, %i, %u, %x, %X\n", -100, -100, -100, -100, -199);
}
-100, -100, 4294967196, ffffff9c, FFFFFF9C
Are there different options to build Lua which might cause the difference? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|