Skip to content

Instantly share code, notes, and snippets.

@char-1ee
Created July 3, 2022 14:37
Show Gist options
  • Save char-1ee/237324ea9ce77e9389a5fc586d69f2b2 to your computer and use it in GitHub Desktop.
Save char-1ee/237324ea9ce77e9389a5fc586d69f2b2 to your computer and use it in GitHub Desktop.

To check whether givn x is an integer,

  • In Java, take the decimal part using % 1 and then check if is 0:

    return (x + EPSILON) % 1 <= 2 * EPSILON; // caution on double type
  • In cpp, check by using x - int(x) == 0.

  • In Javascript, check by Number.isInteger().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment