Skip to content

Commit a90797d

Browse files
committed
add const constructor
1 parent 3e80f42 commit a90797d

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,18 @@ impl<T: FloatCore> NotNan<T> {
12611261
}
12621262
}
12631263

1264+
impl NotNan<f32> {
1265+
/// Create a `NotNan` value possibly at compile-time.
1266+
///
1267+
/// Returns `Err` if `val` is NaN
1268+
pub const fn new_const(val: f32) -> Result<Self, FloatIsNan> {
1269+
match val {
1270+
ref val if val.is_nan() => Err(FloatIsNan),
1271+
val => Ok(NotNan(val)),
1272+
}
1273+
}
1274+
}
1275+
12641276
impl<T> NotNan<T> {
12651277
/// Get the value out.
12661278
#[inline]

0 commit comments

Comments
 (0)