Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 0e9c606

Browse files
committed
Add minf
1 parent 9bbab43 commit 0e9c606

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8+
### Added
9+
10+
- minf
11+
812
## [v0.1.2] - 2018-07-18
913

1014
### Added

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ pub trait F32Ext: private::Sealed + Sized {
136136
fn acosh(self) -> Self;
137137

138138
fn atanh(self) -> Self;
139+
140+
fn min(self, other: Self) -> Self;
139141
}
140142

141143
impl F32Ext for f32 {
@@ -327,6 +329,11 @@ impl F32Ext for f32 {
327329
fn atanh(self) -> Self {
328330
atanhf(self)
329331
}
332+
333+
#[inline]
334+
fn min(self, other: Self) -> Self {
335+
minf(self, other)
336+
}
330337
}
331338

332339
/// Math support for `f64`

src/math/minf.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[inline]
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn minf(x: f32, y: f32) -> f32 {
4+
// IEEE754 says: minNum(x, y) is the canonicalized number x if x < y, y if y < x, the
5+
// canonicalized number if one operand is a number and the other a quiet NaN. Otherwise it
6+
// is either x or y, canonicalized (this means results might differ among implementations).
7+
// When either x or y is a signalingNaN, then the result is according to 6.2.
8+
//
9+
// Since we do not support sNaN in Rust yet, we do not need to handle them.
10+
// FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
11+
// multiplying by 1.0. Should switch to the `canonicalize` when it works.
12+
(if y.is_nan() || x < y { x } else { y }) * 1.0
13+
}

src/math/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ mod tgamma;
166166
mod tgammaf;
167167
mod trunc;
168168
mod truncf;
169+
mod minf;
169170

170171
// Use separated imports instead of {}-grouped imports for easier merging.
171172
pub use self::acos::acos;
@@ -272,6 +273,7 @@ pub use self::tgamma::tgamma;
272273
pub use self::tgammaf::tgammaf;
273274
pub use self::trunc::trunc;
274275
pub use self::truncf::truncf;
276+
pub use self::minf::minf;
275277

276278
// Private modules
277279
mod expo2;

0 commit comments

Comments
 (0)