Skip to content

Commit 8acbd0d

Browse files
🌱 initial: First draft.
1 parent ef44c65 commit 8acbd0d

35 files changed

+9246
-24
lines changed

‎README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
32-bit signed integer arithmetic and logic operators for JavaScript.
55
See [docs](https://arithmetic-type.github.io/int32/index.html).
66

7-
> :building_construction: Caveat emptor! This is work in progress. Code may be
8-
> working. Documentation may be present. Coherence may be. Maybe.
7+
```js
8+
import {div32, mul32} from '@arithmetic-type/int32';
99

10-
> :warning: Depending on your environment, the code may require
11-
> `regeneratorRuntime` to be defined, for instance by importing
12-
> [regenerator-runtime/runtime](https://www.npmjs.com/package/regenerator-runtime).
10+
div32(5, -2); // -2
11+
mul32(-123456, -123456); // -1938485248
12+
```
1313

1414
[![License](https://img.shields.io/github/license/arithmetic-type/int32.svg)](https://raw.githubusercontent.com/arithmetic-type/int32/main/LICENSE)
1515
[![Version](https://img.shields.io/npm/v/@arithmetic-type/int32.svg)](https://www.npmjs.org/package/@arithmetic-type/int32)

‎doc/manual/usage.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
# Usage
22

3-
> :warning: Depending on your environment, the code may require
4-
> `regeneratorRuntime` to be defined, for instance by importing
5-
> [regenerator-runtime/runtime](https://www.npmjs.com/package/regenerator-runtime).
6-
7-
First, require the polyfill at the entry point of your application
8-
```js
9-
await import('regenerator-runtime/runtime.js');
10-
// or
11-
import 'regenerator-runtime/runtime.js';
12-
```
13-
14-
Then, import the library where needed
3+
Import the library where needed
154
```js
165
const int32 = await import('@arithmetic-type/int32');
176
// or

‎package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@
205205
"unicorn"
206206
],
207207
"rules": {
208+
"no-bitwise": "off",
209+
"unicorn/prefer-math-trunc": "off",
208210
"unicorn/prefer-node-protocol": "off",
209211
"unicorn/filename-case": [
210212
"error",

‎src/arithmetic/add32.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const add32 = (a, b) => (a + b) | 0;
2+
export default add32;

‎src/arithmetic/div32.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// NOTE This emulates hardware signed integer division. For the mathematical
2+
// definition I guess we would need another function.
3+
const div32 = (a, b) => (a / b) | 0;
4+
export default div32;

‎src/arithmetic/mul32.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const mul32 = (a, b) => Math.imul(a, b);
2+
export default mul32;

‎src/arithmetic/neg32.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const neg32 = (x) => -x | 0;
2+
3+
export default neg32;

‎src/arithmetic/sub32.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const sub32 = (a, b) => (a - b) | 0;
2+
export default sub32;

‎src/coerce/int32.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const int32 = (x) => x | 0;
2+
3+
export default int32;

‎src/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
const answer = 42;
2-
export default answer;
1+
export {default as add32} from './arithmetic/add32.js';
2+
export {default as div32} from './arithmetic/div32.js';
3+
export {default as mul32} from './arithmetic/mul32.js';
4+
export {default as neg32} from './arithmetic/neg32.js';
5+
export {default as sub32} from './arithmetic/sub32.js';
6+
export {default as int32} from './coerce/int32.js';
7+
export {default as max} from './limits/max.js';
8+
export {default as min} from './limits/min.js';
9+
export {default as and32} from './logic/and32.js';
10+
export {default as not32} from './logic/not32.js';
11+
export {default as or32} from './logic/or32.js';
12+
export {default as xor32} from './logic/xor32.js';
13+
export {default as decreasing} from './order/decreasing.js';
14+
export {default as increasing} from './order/increasing.js';
15+
export {default as shl32} from './shift/shl32.js';
16+
export {default as shr32} from './shift/shr32.js';

0 commit comments

Comments
 (0)