Skip to content

Commit

Permalink
fixes to vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
jairad26 committed Oct 7, 2024
1 parent 3ddd83d commit 1c93102
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sdk/assemblyscript/src/assembly/vectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ export function dot<T extends number>(a: T[], b: T[]): T {
* @param a: The vector
* @returns: The magnitude of the vector
*/
export function magnitude<T extends number>(a: T[]): f64 {
export function magnitude<T extends number>(a: T[]): T {
checkValidArray(a);
return sqrt<f64>(dot(a, a));
return sqrt<number>(dot(a, a)) as T;
}

/**
Expand Down Expand Up @@ -299,9 +299,9 @@ export function product<T extends number>(a: T[]): T {
* @param a: The vector
* @returns: The mean of the vector
*/
export function mean<T extends number>(a: T[]): f64 {
export function mean<T extends number>(a: T[]): T {
checkValidArray(a);
return sum(a) / a.length;
return (sum(a) / a.length) as T;
}

/**
Expand Down Expand Up @@ -372,11 +372,11 @@ export function absInPlace<T extends number>(a: T[]): void {
* @param b: The second vector
* @returns: The euclidian distance between the two vectors
*/
export function euclidianDistance<T extends number>(a: T[], b: T[]): f64 {
export function euclidianDistance<T extends number>(a: T[], b: T[]): T {
checkValidArray(a);
let sum = 0;
for (let i = 0; i < a.length; i++) {
sum += (a[i] - b[i]) ** 2;
}
return sqrt<f64>(sum);
return sqrt<number>(sum) as T;
}

0 comments on commit 1c93102

Please sign in to comment.