https://github.com/roginvs/is-even
isEven function in native nodejs bindings using machine code
https://github.com/roginvs/is-even
Last synced: 9 months ago
JSON representation
isEven function in native nodejs bindings using machine code
- Host: GitHub
- URL: https://github.com/roginvs/is-even
- Owner: roginvs
- Created: 2025-08-22T16:37:36.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-08-22T18:28:55.000Z (11 months ago)
- Last Synced: 2025-08-22T19:05:27.794Z (11 months ago)
- Language: C++
- Size: 57.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# is-even
A deliberately inefficient utility to check if a number is even.
It literally contains [4 billion if statements](https://andreasjhkarlsson.github.io/jekyll/update/2023/12/27/4-billion-if-statements.html), one for every possible 32-bit unsigned integer.
## Features
- Works on macOS, Windows, and Linux
- Supports x64 and arm64
- Handles 32-bit unsigned numbers (0 to 0xFFFFFFFF). Passing anything else is undefined behavior
- Complexity: `O(n)`. Small numbers return fast, large ones can take 30–40s
- The 4 billion statements are generated on first import, not downloaded
- Generated code lives in `node_modules` (~45 GB on amd64)
- Uses Node.js native bindings to execute assembly
- No external dependencies
## Installation
```sh
npm install https://github.com/roginvs/is-even
```
## Usage
```js
const isEven = require("is-even");
console.log(isEven(4)); // true
console.log(isEven(7)); // false
```
## TODO
- Add support for risc-v
- Add `bun` support
## License
MIT