Re: Floats and %d
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Floats and %d
- From: Parke <parke.nexus@...>
- Date: 2015年7月14日 18:20:07 -0700
On Tue, Jul 14, 2015 at 5:58 PM, Rena <hyperhacker@gmail.com> wrote:
> This is something I've been stubbing my toe on a lot lately and it's
> rather annoying:
>
> Lua 5.3.1 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> ; print(string.format('%d', 1.1))
> In previous versions - and in C - it would just silently truncate the
> number (drop the fractional part).
In C? Really? What compiler?
$ cat test.c
#include <stdio.h>
int main () {
printf ( "%d\n", 2.3 );
return 0;
}
$ gcc test.c
test.c: In function ‘main’:
test.c:3:3: warning: format ‘%d’ expects argument of type ‘int’, but
argument 2 has type ‘double’ [-Wformat=]
printf ( "%d\n", 2.3 );
^
$ gcc -Wformat=0 test.c
$ ./a.out
-782778040
-Parke