Skip to content

Commit

Permalink
resolve comment
Browse files Browse the repository at this point in the history
  • Loading branch information
CascadingRadium committed Jul 9, 2024
1 parent 63c7155 commit db19daa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func NormalizeVector(vector []float32) []float32 {
mag += v * v
}
mag = float32(math.Sqrt(float64(mag)))
// zannot normalize a zero vector
if mag != 0 {
// cannot normalize a zero vector
// if the magnitude is 1, then the vector is already normalized
if mag != 0 && mag != 1 {
// normalize the vector
for i, v := range vector {
vector[i] = v / mag
Expand Down

0 comments on commit db19daa

Please sign in to comment.