2 ms·
>I am still looking for a better way to check, if a double will convert cleanly to an integer of the same size or not. I'd say the cleanest would be to decode
by ginko 7y ago
>I am still looking for a better way to check, if a double will convert cleanly to an integer of the same size or not.
I'd say the cleanest would be to decode exponent and mantissa, check if the exponent is within the 64-bit limit of long, then check if there's any bits set below the decimal point. (+plus some extra care for two's complement negative numbers)
The problem with this is of course that this would be platform dependent.
- clarry 7y agoI'd say the correct way to is to use lrint or lround and check for errors the standard way.