From 3a75c9ef92dbc3736de5442036e0d4d46eea2e7b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 19 Feb 2022 10:37:26 +0100 Subject: [PATCH] Check that scalar is finite on construction --- src/math/scalar.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/math/scalar.rs b/src/math/scalar.rs index f350cf990..72a1df265 100644 --- a/src/math/scalar.rs +++ b/src/math/scalar.rs @@ -24,7 +24,12 @@ impl Scalar { /// Construct a `Scalar` from an `f64` 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`