Constructor for closed intervals representing all the values inside (and including) lo and hi e.g. [lo, hi]

NOTE: If lo > hi then the constructor will return an empty interval

Mixes

arithmetic

Mixes

algebra

Mixes

misc

Mixes

relational

Mixes

trigonometric

Mixes

utils

Mixes

constants

Link

#bounded

Link

#boundedSingleton

Example

new Interval(1, 2)  // {lo: 1, hi: 2}
// function invocation without new is also supported
Interval(1, 2) // {lo: 1, hi: 2}
// with numbers
Interval(1, 2) // {lo: 1, hi: 2}
Interval(1) // {lo: 1, hi: 1}
// with an array
Interval([1, 2]) // {lo: 1, hi: 2}
// singleton intervals
var x = Interval(1)
var y = Interval(2)
Interval(x, y) // {lo: 1, hi: 2}
// when `lo > hi` it returns an empty interval
Interval(2, 1) // {lo: Infinity, hi: -Infinity}
// bounded interval
Interval().bounded(1, 2) // { lo: 0.9999999999999999, hi: 2.0000000000000004 }
// singleton bounded interval
Interval().boundedSingleton(2) // {lo: 1.9999999999999998, hi: 2.0000000000000004}
// half open and open intervals
// [2, 3]
Interval(2, 3) // {lo: 2, hi: 3}
// (2, 3]
Interval().halfOpenLeft(2, 3) // {lo: 2.0000000000000004, hi: 3}
// [2, 3)
Interval().halfOpenRight(2, 3) // {lo: 2, hi: 2.9999999999999996}
// (2, 3)
Interval().open(2, 3) // {lo: 2.0000000000000004, hi: 2.9999999999999996}

Param

The left endpoint of the interval if it's a number or a singleton interval, if it's an array then an interval will be built out of the elements of the array

Param

The right endpoint of the interval if it's a number or a singleton interval, if omitted then a singleton interval will be built out of lo

Hierarchy

  • Interval

Implements

  • IInterval

Constructors

Properties

hi: number = 0

The right endpoint of the interval

lo: number = 0

The left endpoint of the interval

Methods

  • Sets new endpoints for this interval checking that both arguments exist and that are valid numbers, additionally if lo > hi the interval is set to an empty interval

    Returns

    The calling interval

    Parameters

    • lo: number

      The left endpoint of the interval

    • hi: number

      The right endpoint of the interval

    Returns Interval

  • Sets new endpoints to this interval, the left endpoint is equal to the previous IEEE floating point value of lo and the right endpoint is equal to the next IEEE floating point value of hi, it's assumed that lo <= hi

    Example

    const x = Interval().bounded(1, 2)
    x.lo < 1 // true, x.lo === 0.9999999999999999
    x.hi > 2 // true, x.hi === 2.0000000000000004

    Example

    // the correct representation of 1/3
    var x = Interval().bounded(1/3, 1/3)
    x.lo < 1/3 // true
    x.hi > 1/3 // true
    // however the floating point representation of 1/3 is less than the real 1/3
    // therefore the left endpoint could be 1/3 instead of the previous value of
    var next = Interval.round.safeNext
    var x = Interval().set(1/3, next(1/3))
    // x now represents 1/3 correctly

    Returns

    The calling interval i.e. this

    Parameters

    • lo: number
    • hi: number

    Returns Interval

  • Equivalent to Interval().bounded(v, v)

    Returns

    The calling interval i.e. this

    Parameters

    • v: number

    Returns Interval

  • Creates an interval equal to the calling one

    See

    Interval.clone

    Name

    Interval.prototype

    Example

    var x = Interval(2, 3)
    x.clone() // Interval(2, 3)

    Returns

    Returns Interval

  • Sets the endpoints of this interval to the half open interval (lo, hi]

    NOTE: Interval.round.disable has no effect on this method

    Example

    // (2, 3]
    Interval().halfOpenLeft(2, 3) // {lo: 2.0000000000000004, hi: 3}

    Returns

    The calling interval

    Parameters

    • lo: number
    • hi: number

    Returns Interval

  • Sets the endpoints of this interval to the half open interval [lo, hi)

    NOTE: Interval.round.disable has no effect on this method

    Example

    // [2, 3)
    Interval.halfOpenRight(2, 3) // {lo: 2, hi: 2.9999999999999996}

    Returns

    The calling interval

    Parameters

    • lo: number
    • hi: number

    Returns Interval

  • Sets the endpoints of this interval to the open interval (lo, hi)

    NOTE: Interval.round.disable has no effect on this method

    Example

    // (2, 3)
    Interval().open(2, 3) // {lo: 2.0000000000000004, hi: 2.9999999999999996}

    Returns

    The calling interval

    Parameters

    • lo: number
    • hi: number

    Returns Interval

  • Sets new endpoints for this interval, this method bypasses any checks on the type of arguments

    Returns

    The calling interval

    Parameters

    • lo: number

      The left endpoint of the interval

    • hi: number

      The right endpoint of the interval

    Returns Interval

  • Sets the endpoints of this interval to [∞, -∞] effectively representing no values

    Returns

    The calling interval

    Returns Interval

  • Sets the endpoints of this interval to [-∞, ∞] effectively representing all the possible real values

    Returns

    The calling interval

    Returns Interval

  • Sets this.lo and this.hi to a single value v

    Returns

    The calling interval i.e. this

    Parameters

    • v: number

    Returns Interval

  • Array representation of this interval

    Returns

    Returns number[]

Generated using TypeDoc