|
From: | Paul Eggert |
Subject: | Re: checking whether a double is in the range of long |
Date: | Sat, 22 Apr 2023 22:40:25 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 |
On 2023-04-22 16:34, Ben Pfaff wrote:
determine whether converting 'd' to 'long' would yield a 'long' with the same value as 'd'
LONG_MIN - 1.0 < d && d < LONG_MAX + 1.0 && d == (long) dOn all practical platforms this should avoid undefined behavior and works correctly even if rounding occurs. You can replace "d == (long) d" with "d == floor (d)" if you prefer.
[Prev in Thread] | Current Thread | [Next in Thread] |