Skip to main content

normalize

Function normalize 

Source
pub fn normalize<T: Real>(xs: &[T]) -> Vec<T>
Expand description

Normalize a vector (represented as a slice) to unit length.

Returns a zero vector if the norm is zero.

ยงExamples

use mathverse_core::ops::normalize;

let v = normalize(&[3.0_f64, 4.0]);
assert!((v[0] - 0.6).abs() < 1e-12);
assert!((v[1] - 0.8).abs() < 1e-12);