Convert double to long if lossless

drug drug2004 at bk.ru
Tue Jan 19 14:23:04 UTC 2021


On 1/19/21 5:04 PM, drug wrote:
> On 1/19/21 4:48 PM, Per Nordlöw wrote:
>> On Tuesday, 19 January 2021 at 13:36:58 UTC, Steven Schveighoffer wrote:
>>> Use a cast instead.
>>>
>>> const lvalue = cast(long)value;
>>
>> Ahh, good point.
>>
>> Followd by a compare of the original value I presume.
> 
> don't forget to check by std.math.isFinite before casting
> 
> Another (low level) way is to shift mantissa left by exponent value. If 
> the remainder equals to zero then no fractal part was encoded in the 
> floating value.

*fractional part


More information about the Digitalmars-d-learn mailing list