Check that scalar is finite on construction

This commit is contained in:
Hanno Braun 2022-02-19 10:37:26 +01:00
parent 00e38b0068
commit 3a75c9ef92

View File

@ -24,7 +24,12 @@ impl Scalar {
/// Construct a `Scalar` from an `f64` /// Construct a `Scalar` from an `f64`
pub fn from_f64(scalar: f64) -> Self { pub fn from_f64(scalar: f64) -> Self {
Self(scalar) if scalar.is_finite() {
// `scalar` is neither infinite, nor NaN
Self(scalar)
} else {
panic!("Invalid scalar value: {scalar}");
}
} }
/// Construct a `Scalar` from a `u64` /// Construct a `Scalar` from a `u64`