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