Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sanctuary-js/sanctuary-int
:1234: A collection of functions which operate on 32-bit signed integers
https://github.com/sanctuary-js/sanctuary-int
sanctuary
Last synced: about 2 months ago
JSON representation
:1234: A collection of functions which operate on 32-bit signed integers
- Host: GitHub
- URL: https://github.com/sanctuary-js/sanctuary-int
- Owner: sanctuary-js
- License: mit
- Created: 2015-08-24T14:31:54.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-10-27T10:32:57.000Z (2 months ago)
- Last Synced: 2024-10-27T11:53:24.500Z (2 months ago)
- Topics: sanctuary
- Language: JavaScript
- Homepage:
- Size: 131 KB
- Stars: 12
- Watchers: 22
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# sanctuary-int
A collection of functions which operate on 32-bit signed integers.
## API
#### `Int :: Type`
The Int type represents integers in the range [-2^31 .. 2^31).
#### `NonZeroInt :: Type`
The NonZeroInt type represents non-zero integers in the range
[-2^31 .. 2^31).#### `add :: Int -> Int -> Int`
Returns the sum of its two arguments.
```javascript
> add (1) (2)
3
```#### `sub :: Int -> Int -> Int`
Returns the result of subtracting its first argument from its second
argument.```javascript
> sub (1) (100)
99
```#### `mul :: Int -> Int -> Int`
Returns the product of its two arguments.
```javascript
> mul (6) (7)
42
```#### `quot :: NonZeroInt -> Int -> Int`
Returns the result of dividing its second argument by its first
argument, truncating towards zero.Throws if the divisor is zero.
See also [`div`](#div).
```javascript
> quot (5) (42)
8> quot (-5) (42)
-8> quot (5) (-42)
-8> quot (-5) (-42)
8
```#### `rem :: NonZeroInt -> Int -> Int`
Integer remainder, satisfying:
quot (y) (x) * y + rem (y) (x) === x
Throws if the divisor is zero.
See also [`mod`](#mod).
```javascript
> rem (5) (42)
2> rem (-5) (42)
2> rem (5) (-42)
-2> rem (-5) (-42)
-2
```#### `div :: NonZeroInt -> Int -> Int`
Returns the result of dividing its second argument by its first
argument, truncating towards negative infinity.Throws if the divisor is zero.
See also [`quot`](#quot).
```javascript
> div (5) (42)
8> div (-5) (42)
-9> div (5) (-42)
-9> div (-5) (-42)
8
```#### `mod :: NonZeroInt -> Int -> Int`
Integer modulus, satisfying:
div (y) (x) * y + mod (y) (x) === x
Throws if the divisor is zero.
See also [`rem`](#rem).
```javascript
> mod (5) (42)
2> mod (-5) (42)
-3> mod (5) (-42)
3> mod (-5) (-42)
-2
```#### `and :: Int -> Int -> Int`
[Bitwise AND][&]. Returns an Int with a one at each bit position at
which both arguments have a one.```javascript
> and (0b1100) (0b1010)
0b1000
```#### `or :: Int -> Int -> Int`
[Bitwise OR][|]. Returns an Int with a one at each bit position at
which at least one argument has a one.```javascript
> or (0b1100) (0b1010)
0b1110
```#### `xor :: Int -> Int -> Int`
[Bitwise XOR][^]. Returns an Int with a one at each bit position at
which exactly one argument has a one.```javascript
> xor (0b1100) (0b1010)
0b0110
```#### `not :: Int -> Int`
[Bitwise NOT][~], satisfying:
not (x) === -(x + 1)
```javascript
> not (42)
-43
```#### `even :: Int -> Boolean`
Returns `true` if its argument is even; `false` if it is odd.
```javascript
> even (42)
true
```Returns `true` if its argument is odd; `false` if it is even.
```javascript
> odd (42)
false
```[~]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_NOT
[&]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_AND
[|]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_OR
[^]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_XOR