Link Search Menu Expand Document

Int32 overview

This module provides a way to construct and work with signed, 32-bit integers. They are just JavaScriptnumbers under the hood, so they should be comparable in performance.

Since they are limited to 32 bits, Int32s are subject to overflowing if the result of any operation should exceed the range of -2^31 and 2^31 - 1.

To avoid integer overflow, see [[Int]] for arbitrary precision integers.

Like the rest of fp-ts-numerics, this module exposes the Int32 type and namespace as a single declaration. It is intended to be consumed like so:

import { Int32 } from 'fp-ts-numerics'

function isEven(n: Int32): boolean {
  return Int32.equals(Int32.zero, Int32.mod(n, Int32.of(2)))
}

Added in v1.0.0


Table of contents


Typeclass Instance

Bounded

Signature

export declare const Bounded: Bounded<Int32>

Added in v1.0.0

CommutativeRing

Signature

export declare const CommutativeRing: CommutativeRing<Int32>

Added in v1.0.0

Enum

Signature

export declare const Enum: Enum<Int32>

Added in v1.0.0

Eq

Signature

export declare const Eq: Eq<Int32>

Added in v1.0.0

EuclideanRing

Signature

export declare const EuclideanRing: EuclideanRing<Int32>

Added in v1.0.0

HasPow

Signature

export declare const HasPow: HasPow<Int32>

Added in v1.0.0

HasToInt

Signature

export declare const HasToInt: HasToInt<Int32>

Added in v1.0.0

HasToRational

Signature

export declare const HasToRational: HasToRational<Int32>

Added in v1.0.0

Integral

Signature

export declare const Integral: Integral<Int32>

Added in v1.0.0

Numeric

Signature

export declare const Numeric: Numeric<Int32>

Added in v1.0.0

Ord

Signature

export declare const Ord: Ord<Int32>

Added in v1.0.0

Ring

Signature

export declare const Ring: Ring<Int32>

Added in v1.0.0

Semiring

Signature

export declare const Semiring: Semiring<Int32>

Added in v1.0.0

Show

Signature

export declare const Show: Show<Int32>

Added in v1.0.0

utils

Digits (type alias)

A tuple of literal integers representing every valid sequence of digits for Int32

Signature

export type Digits =
  | [-1 | 0 | 1]
  | [LeadingDigit]
  | [LeadingDigit, Digit]
  | [LeadingDigit, Digit, Digit]
  | [LeadingDigit, Digit, Digit, Digit]
  | [LeadingDigit, Digit, Digit, Digit, Digit]
  | [LeadingDigit, Digit, Digit, Digit, Digit, Digit]
  | [LeadingDigit, Digit, Digit, Digit, Digit, Digit, Digit]
  | [LeadingDigit, Digit, Digit, Digit, Digit, Digit, Digit, Digit]
  | [LeadingDigit, Digit, Digit, Digit, Digit, Digit, Digit, Digit, Digit]
  | [-1 | 1, Digit, Digit, Digit, Digit, Digit, Digit, Digit, Digit, Digit]
  | [-2 | 2, 0, Digit, Digit, Digit, Digit, Digit, Digit, Digit, Digit]
  | [-2 | 2, 1, 0 | 1 | 2 | 3, Digit, Digit, Digit, Digit, Digit, Digit, Digit]
  | [-2 | 2, 1, 4, Exclude<Digit, 7 | 8 | 9>, Digit, Digit, Digit, Digit, Digit, Digit]
  | [-2 | 2, 1, 4, 7, 0 | 1 | 2 | 3, Digit, Digit, Digit, Digit, Digit]
  | [-2 | 2, 1, 4, 7, 4, Exclude<Digit, 8 | 9>, Digit, Digit, Digit, Digit]
  | [-2 | 2, 1, 4, 7, 4, 8, 0 | 1 | 2, Digit, Digit, Digit]
  | [-2 | 2, 1, 4, 7, 4, 8, 3, 0 | 1 | 2 | 3 | 4 | 5, Digit, Digit]
  | [-2 | 2, 1, 4, 7, 4, 8, 3, 6, 0 | 1 | 2 | 3, Digit]
  | [-2 | 2, 1, 4, 7, 4, 8, 3, 6, 4, Exclude<Digit, 8 | 9>]
  | [-2, 1, 4, 7, 4, 8, 3, 6, 4, 8]

Added in v1.0.0

Int32

Signature

export declare const Int32: Bounded<Int32> &
  CommutativeRing<Int32> &
  Enum<Int32> &
  Eq<Int32> &
  EuclideanRing<Int32> &
  HasPow<Int32> &
  HasToInt<Int32> &
  HasToRational<Int32> &
  Integral<Int32> &
  Numeric<Int32> &
  Ord<Int32> &
  Ring<Int32> &
  Semiring<Int32> &
  Show<Int32> & {
    add: typeof add
    bottom: Int32
    Bounded: Bounded<Int32>
    CommutativeRing: CommutativeRing<Int32>
    compare: (x: Int32, y: Int32) => Ordering
    div: typeof div
    Enum: Enum<Int32>
    Eq: Eq<Int32>
    equals: typeof equals
    EuclideanRing: EuclideanRing<Int32>
    fromInt: typeof fromInt
    fromNumber: typeof fromNumber
    fromNumberLossy: typeof fromNumberLossy
    HasPow: HasPow<Int32>
    HasToInt: HasToInt<Int32>
    HasToRational: HasToRational<Int32>
    Integral: Integral<Int32>
    isTypeOf: typeof isTypeOf
    mod: typeof mod
    mul: typeof mul
    negate: typeof negate
    next: typeof next
    Numeric: Numeric<Int32>
    of: typeof of
    one: Int32
    Ord: Ord<Int32>
    pow: typeof pow
    prev: typeof prev
    quot: typeof quot
    rem: typeof rem
    Ring: Ring<Int32>
    Semiring: Semiring<Int32>
    Show: Show<Int32>
    sub: typeof sub
    toInt: typeof toInt
    toNumber: typeof toNumber
    top: Int32
    toRational: typeof toRational
    unsafeFromNumber: typeof unsafeFromNumber
    zero: Int32
  }

Added in v1.0.0

Int32 (interface)

Signature

export interface Int32 extends Newtype<typeof INT_32, number> {}

Added in v1.0.0

add

Signature

export declare function add(a: Int32, b: Int32): Int32

Added in v1.0.0

bottom

Signature

export declare const bottom: Int32

Added in v1.0.0

compare

Signature

export declare const compare: (x: Int32, y: Int32) => Ordering

Added in v1.0.0

degree

Signature

export declare function degree(i: Int32): Natural

Added in v1.0.0

div

Signature

export declare function div(n: Int32, d: NonZero<Int32>): Int32

Added in v1.0.0

equals

Signature

export declare function equals(a: Int32, b: Int32): boolean

Added in v1.0.0

fromInt

Signature

export declare function fromInt(int: Int): Option<Int32>

Added in v1.0.0

fromNumber

Signature

export declare function fromNumber(n: number): option.Option<Int32>

Added in v1.0.0

fromNumberLossy

Signature

export declare function fromNumberLossy(n: number): Int32

Added in v1.0.0

isTypeOf

Signature

export declare function isTypeOf(x: unknown): x is Int32

Added in v1.0.0

mod

Signature

export declare function mod(n: Int32, d: NonZero<Int32>): Int32

Added in v1.0.0

mul

Signature

export declare function mul(a: Int32, b: Int32): Int32

Added in v1.0.0

negate

Signature

export declare function negate(a: Int32): Int32

Added in v1.0.0

next

Signature

export declare function next(a: Int32): Option<Int32>

Added in v1.0.0

of

Constructs a 32-bit, signed, two’s complement integer.

  • Min value: -2^31
  • Max value: 2^31 - 1

Signature

export declare function of(zero: 0): Int32
export declare function of(...digits: Digits): NonZero<Int32>

Example

import { Int32 } from 'fp-ts-numerics/Int32'

Int32.of(2, 1, 4, 7, 4, 8, 3, 6, 4, 7)
// > 21474883647

Added in v1.0.0

one

Signature

export declare const one: Int32

Added in v1.0.0

pow

Signature

export declare function pow(n: Int32, exp: Int32): Int32

Added in v1.0.0

prev

Signature

export declare function prev(a: Int32): Option<Int32>

Added in v1.0.0

quot

Signature

export declare function quot(a: Int32, b: NonZero<Int32>): Int32

Added in v1.0.0

rem

Signature

export declare function rem(a: Int32, b: NonZero<Int32>): Int32

Added in v1.0.0

sub

Signature

export declare function sub(a: Int32, b: Int32): Int32

Added in v1.0.0

toInt

Signature

export declare function toInt(a: Int32): Int

Added in v1.0.0

toNumber

Signature

export declare function toNumber(i: Int32): number

Added in v1.0.0

toRational

Signature

export declare function toRational(a: Int32): Rational

Added in v1.0.0

top

Signature

export declare const top: Int32

Added in v1.0.0

unsafeFromNumber

Signature

export declare function unsafeFromNumber(n: number): Int32

Added in v1.0.0

zero

Signature

export declare const zero: Int32

Added in v1.0.0