[tz] localtime.c issue
Arthur David Olson
arthurdavidolson at gmail.com
Mon Jul 8 22:46:40 UTC 2013
Conditionalizing on "if (0.5 == (time_t) 0.5)" is a possibility (albeit
ugly).
--ado
On Mon, Jul 8, 2013 at 6:00 PM, Andy Heninger <aheninger at google.com> wrote:
> Whatever the code ends up being, it would be helpful if it produced no
> compiler warnings with the warning level cranked up to the maximum, on
> either gcc or clang.
>
> -- Andy
>
>
>
> On Mon, Jul 8, 2013 at 2:49 PM, Alan Barrett <apb at cequrux.com> wrote:
>
>> On Mon, 08 Jul 2013, Paul_Koning at Dell.com wrote:
>>
>>> Perhaps this will work without either a compiler warning or potential
>>>> loss of precision:
>>>>
>>>> seconds = tdays * SECSPERDAY + (time_t)0.5;
>>>>
>>>> --apb (Alan Barrett)
>>>>
>>>
>>> I rather doubt it. Casting 0.5 to an integer type (as time_t is) ends
>>> up adding 0 or 1, but not 0.5.
>>>
>>
>> The whole point of adding 0.5 before converting from time_t to
>> int_fast32_t is to round up if time_t happens to be a floating point type,
>> and to do nothing if time_t happens to be an integral type. You can't
>> assume that time_t is an integral type.
>>
>>
>> How about (tdays * SECSPERDAY * 2 + 1) / 2; ?
>>>
>>
>> Multiplying by 2 might overflow the available range. (I have not checked
>> whether there are reasons why it would always be safe.)
>> --apb (Alan Barrett)
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mm.icann.org/pipermail/tz/attachments/20130708/ff7b44b4/attachment.htm>
More information about the tz
mailing list