[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Floats and %d
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sat, 18 Jul 2015 21:18:48 +0200
2015-07-18 20:29 GMT+02:00 Rena <hyperhacker@gmail.com>:
> On Jul 16, 2015 8:06 AM, "Roberto Ierusalimschy" <roberto@inf.puc-rio.br>
> wrote:
>> Any correct C compiler will truncate as you said (towards zero), when
>> it converts a float to an integer. 'printf' is an exception, because
>> it is a vararg function and, therefore, without type checking. (With
>> no type checking, the compiler does not know it has to convert.)
>>
>> -- Roberto
>>
>
> Right, I think I mixed up the automatic casting when assigning to an int and
> the automatic promotion to int when passing through a vararg list.
>
> In any case, I'm still wishing Lua would truncate for %d. I keep ending up
> with seemingly harmless UI code crashing with a "number has no integer
> representation" error, and ugly floor() littered everywhere. It reminds me
> of having to use tostring() with %s in earlier versions (a similar case
> which annoyed me as well). But perhaps I'm alone here...
That precedent lends conceptual integrity to your request.