Function dot

  • Calculates the dot product of two vectors of numbers.

    The function is an algebraic operation that takes two equal-length sequences of numbers (usually coordinate vectors) and returns a single number.

    Parameters

    • vector1: number[]

      The first vector to calculate the dot product.

    • vector2: number[]

      The second vector to calculate the dot product.

    Returns number

    A number representing the dot product of the two vectors.

    Throws

    If the vectors' lengths do not match.

    Example

    dot([1, 3, -5], [4, -2, -1]);  // Returns 3
    
  • Calculates the dot product of two vectors of bigints.

    The function is an algebraic operation that takes two equal-length sequences of bigints (usually coordinate vectors) and returns a single bigint.

    Parameters

    • vector1: bigint[]

      The first vector to calculate the dot product.

    • vector2: bigint[]

      The second vector to calculate the dot product.

    Returns bigint

    A bigint representing the dot product of the two vectors.

    Throws

    If the vectors' lengths do not match.

    Example

    dot([1n, 3n, -5n], [4n, -2n, -1n]);  // Returns 3n
    
  • Calculates the dot product of two vectors of a generic type.

    The function is an algebraic operation that takes two equal-length sequences of generic type (usually coordinate vectors) and returns a single value of type T.

    Type Parameters

    • T

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

    Parameters

    • vector1: T[]

      The first vector to calculate the dot product.

    • vector2: T[]

      The second vector to calculate the dot product.

    • numerical: Numerical<T>

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

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

    Returns T

    A value of type T, representing the dot product of two vectors.

    Throws

    If the vectors' type is neither array of numbers nor bigints, and no Numerical instance was provided.

    Throws

    If the vectors' lengths do not match.

    Example

    dot([1, 3, -5], [4, -2, -1], new Numerical());  // Where Numerical() is an implementation for type T.
    

Generated using TypeDoc