On Tuesday, 19 January 2021 at 11:42:17 UTC, Per Nordlöw wrote:
I want to convert a double to a long if conversion is lossless (without fractional part, non-nan, non-inf, within long-range, etc).

And then? I mean: What do you want to do with the long what could not
be done with the double in the first place?

BTW: Has anybody noticed that there already might have been a loss of precision even before the conversion to long, since the mantissa of the double only
entails 53 bit?

   long q = 1L << 53;
   long r = q + 1;
   assert (q != r);
   double s = q, t = r;
   assert (s == q);
   assert (t == r);
   assert (s != t); // fail

Reply via email to