Int16 overview
This module provides a way to construct and work with signed, 16-bit integers. They are just JavaScriptnumbers under the hood, so they should be comparable in performance.
Since they are limited to 16 bits, Int16s are subject to overflowing if the result of any operation should exceed the range of -2^15 and 2^15 - 1.
To avoid integer overflow, see [[Int]] for arbitrary precision integers.
Like the rest of fp-ts-numerics, this module exposes the Int16 type and namespace as a single declaration. It is intended to be consumed like so:
import { Int16 } from 'fp-ts-numerics'
function isEven(n: Int16): boolean {
return Int16.equals(Int16.zero, Int16.mod(n, Int16.of(2)))
}
Added in v1.0.0
Table of contents
Constructor
of
Constructs a signed 16-bit integer.
- Min value: -2^15
- Max value: 2^15 - 1
Signature
export declare function of(zero: 0): Int16
export declare function of(...digits: Digits): NonZero<Int16>
Example
import { Int16 } from 'fp-ts-numerics/Int16'
Int16.of(3, 2, 7, 6, 7)
// > 32767
Added in v1.0.0
Data Type
Int16 (interface)
The type of signed, 16-bit integers. Subject to integer overflow.
const myInt: Int = Int(1, 0, 0)
Signature
export interface Int16 extends Branded<Int32, typeof INT_16> {}
Added in v1.0.0
Instances
Bounded
Signature
export declare const Bounded: Bounded<Int16>
Added in v1.0.0
CommutativeRing
Signature
export declare const CommutativeRing: CommutativeRing<Int16>
Added in v1.0.0
Enum
Signature
export declare const Enum: Enum<Int16>
Added in v1.0.0
EuclideanRing
Signature
export declare const EuclideanRing: EuclideanRing<Int16>
Added in v1.0.0
HasPow
Signature
export declare const HasPow: HasPow<Int16>
Added in v1.0.0
HasToInt
Signature
export declare const HasToInt: HasToInt<Int16>
Added in v1.0.0
HasToRational
Signature
export declare const HasToRational: HasToRational<Int16>
Added in v1.0.0
Integral
Signature
export declare const Integral: Integral<Int16>
Added in v1.0.0
Numeric
Signature
export declare const Numeric: Numeric<Int16>
Added in v1.0.0
Ord
Signature
export declare const Ord: Ord<Int16>
Added in v1.0.0
Ring
Signature
export declare const Ring: Ring<Int16>
Added in v1.0.0
Semiring
Signature
export declare const Semiring: Semiring<Int16>
Added in v1.0.0
Show
Signature
export declare const Show: Show<Int16>
Added in v1.0.0
utils
Digits (type alias)
A tuple of literal integers representing every valid sequence of digits for [[Int16]]
Signature
export type Digits =
| [-1 | 0 | 1]
| [LeadingDigit]
| [LeadingDigit, Digit]
| [LeadingDigit, Digit, Digit]
| [LeadingDigit, Digit, Digit, Digit]
| [-2 | -1 | 1 | 2, Digit, Digit, Digit, Digit]
| [-3 | 3, 0 | 1, Digit, Digit, Digit]
| [-3 | 3, 2, Exclude<Digit, 7 | 8 | 9>, Digit, Digit]
| [-3 | 3, 2, 7, 0 | 1 | 2 | 3 | 4 | 5, Digit]
| [-3 | 3, 2, 7, 6, Exclude<Digit, 8 | 9>]
| [-3, 2, 7, 6, 8]
Added in v1.0.0
Int16
Signature
export declare const Int16: Bounded<Int16> &
CommutativeRing<Int16> &
Enum<Int16> &
Eq<Int16> &
EuclideanRing<Int16> &
HasPow<Int16> &
HasToInt<Int16> &
HasToRational<Int16> &
Integral<Int16> &
Numeric<Int16> &
Ord<Int16> &
Ring<Int16> &
Semiring<Int16> &
Show<Int16> & {
add: typeof add
bottom: Int16
Bounded: Bounded<Int16>
CommutativeRing: CommutativeRing<Int16>
compare: (x: Int16, y: Int16) => Ordering
div: typeof div
Enum: Enum<Int16>
Eq: Eq<Int16>
equals: typeof equals
EuclideanRing: EuclideanRing<Int16>
fromInt: typeof fromInt
fromNumber: typeof fromNumber
fromNumberLossy: typeof fromNumberLossy
HasPow: HasPow<Int16>
HasToInt: HasToInt<Int16>
HasToRational: HasToRational<Int16>
Integral: Integral<Int16>
isTypeOf: typeof isTypeOf
mod: typeof mod
mul: typeof mul
negate: typeof negate
next: typeof next
Numeric: Numeric<Int16>
of: typeof of
one: Int16
Ord: Ord<Int16>
pow: typeof pow
prev: typeof prev
quot: typeof quot
rem: typeof rem
Ring: Ring<Int16>
Semiring: Semiring<Int16>
Show: Show<Int16>
sub: typeof sub
toInt: typeof toInt
toNumber: typeof toNumber
top: Int16
toRational: typeof toRational
unsafeFromNumber: typeof unsafeFromNumber
zero: Int16
}
Added in v1.0.0
add
Signature
export declare function add(a: Int16, b: Int16): Int16
Added in v1.0.0
bottom
Signature
export declare const bottom: Int16
Added in v1.0.0
compare
Signature
export declare const compare: (x: Int16, y: Int16) => Ordering
Added in v1.0.0
degree
Signature
export declare function degree(i: Int16): Natural
Added in v1.0.0
div
Signature
export declare function div(n: Int16, d: NonZero<Int16>): Int16
Added in v1.0.0
equals
Signature
export declare function equals(a: Int16, b: Int16): boolean
Added in v1.0.0
fromInt
Signature
export declare function fromInt(n: Int): Option<Int16>
Added in v1.0.0
fromNumber
Signature
export declare function fromNumber(n: number): option.Option<Int16>
Added in v1.0.0
fromNumberLossy
Signature
export declare function fromNumberLossy(n: number): Int16
Added in v1.0.0
isTypeOf
Signature
export declare function isTypeOf(x: unknown): x is Int16
Added in v1.0.0
mod
Signature
export declare function mod(n: Int16, d: NonZero<Int16>): Int16
Added in v1.0.0
mul
Signature
export declare function mul(a: Int16, b: Int16): Int16
Added in v1.0.0
negate
Signature
export declare function negate(a: Int16): Int16
Added in v1.0.0
next
Signature
export declare function next(a: Int16): Option<Int16>
Added in v1.0.0
one
Signature
export declare const one: Int16
Added in v1.0.0
pow
Signature
export declare function pow(n: Int16, exp: Int16): Int16
Added in v1.0.0
prev
Signature
export declare function prev(a: Int16): Option<Int16>
Added in v1.0.0
quot
Signature
export declare function quot(a: Int16, b: NonZero<Int16>): Int16
Added in v1.0.0
rem
Signature
export declare function rem(a: Int16, b: NonZero<Int16>): Int16
Added in v1.0.0
sub
Signature
export declare function sub(a: Int16, b: Int16): Int16
Added in v1.0.0
toInt
Signature
export declare function toInt(a: Int16): Int
Added in v1.0.0
toNumber
Signature
export declare function toNumber(i: Int16): number
Added in v1.0.0
toRational
Signature
export declare function toRational(a: Int16): Rational
Added in v1.0.0
top
Signature
export declare const top: Int16
Added in v1.0.0
unsafeFromNumber
Signature
export declare function unsafeFromNumber(n: number): Int16
Added in v1.0.0
zero
Signature
export declare const zero: Int16
Added in v1.0.0