akon1248

Useless Integer Check

Sep 23rd, 2021 (edited)
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.29 KB | None | 0 0
  1. public static boolean isInteger(double d) {
  2.     if (d != d) {
  3.         return false;
  4.     }
  5.     long bits = Double.doubleToRawLongBits(d);
  6.     long exponent = ((bits >> 52) & 0x7FF)-1023;
  7.     long fraction = bits & 0xFFFFFFFFFFFFFL;
  8.     long l = 52-exponent;
  9.     return (fraction & ~(fraction >> l << l)) == 0;
  10. }
Add Comment
Please, Sign In to add comment