Function normalize

  • Normalizes a vector of numbers.

    Parameters

    • vector: number[]

      The vector of numbers to be normalized.

    Returns number[]

    A new vector that represents the normalized form of the input vector.

    Example

    normalize([3, 4]);  // Returns [0.6, 0.8]
    
  • Normalizes a vector of bigints.

    Parameters

    • vector: bigint[]

      The vector of bigints to be normalized.

    Returns bigint[]

    A new vector that represents the normalized form of the input vector.

    Example

    normalize([3n, 4n]);  // Returns [3n, 4n]
    
  • Normalizes a vector of numeric type T.

    The function computes the length of the vector and divides each element by the length, thus normalizing the vector to a length/magnitude of 1 or -1. The normalization is done based on the provided numeric type (number/bigint or other, with other requiring a Numerical instance)

    Type Parameters

    • T

      The numeric type of the elements in the vector. T is inferred and doesn't need to be supplied manually.

    Parameters

    • vector: T[]

      The vector to be normalized.

    • Optional numerical: Numerical<T>

      (optional) An instance of Numerical interface for the numeric type T.

      • If not provided, it defaults to NumericalNumber if the vector is of type number[], or to NumericalBigInt if the vector is of type bigint[].
      • If vector is neither number[] nor bigint[], a Numerical instance must be provided.

    Returns T[]

    A new vector that represents the normalized form of the input vector.

    Throws

    If the vector's type is neither number[] nor bigint[], and no Numerical instance was provided.

    Example

    normalize([3, 4]);                  // Returns [0.6, 0.8]
    normalize([3n, 4n]); // Returns [3n, 4n]
    normalize([3, 4], new Numerical()); // Where Numerical() is an implementation for type T.

Generated using TypeDoc