This repository was archived by the owner on Apr 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +95
-0
lines changed Expand file tree Collapse file tree 7 files changed +95
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55
66## [ Unreleased]
77
8+ ### Added
9+
10+ - minf
11+ - fmin
12+ - fmaxf
13+ - fmax
14+
815## [ v0.1.2] - 2018-07-18
916
1017### Added
Original file line number Diff line number Diff line change @@ -136,6 +136,10 @@ 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 ;
141+
142+ fn max ( self , other : Self ) -> Self ;
139143}
140144
141145impl F32Ext for f32 {
@@ -327,6 +331,16 @@ impl F32Ext for f32 {
327331 fn atanh ( self ) -> Self {
328332 atanhf ( self )
329333 }
334+
335+ #[ inline]
336+ fn min ( self , other : Self ) -> Self {
337+ fminf ( self , other)
338+ }
339+
340+ #[ inline]
341+ fn max ( self , other : Self ) -> Self {
342+ fmaxf ( self , other)
343+ }
330344}
331345
332346/// Math support for `f64`
@@ -410,6 +424,10 @@ pub trait F64Ext: private::Sealed + Sized {
410424 fn acosh ( self ) -> Self ;
411425
412426 fn atanh ( self ) -> Self ;
427+
428+ fn min ( self , other : Self ) -> Self ;
429+
430+ fn max ( self , other : Self ) -> Self ;
413431}
414432
415433impl F64Ext for f64 {
@@ -601,6 +619,16 @@ impl F64Ext for f64 {
601619 fn atanh ( self ) -> Self {
602620 atanh ( self )
603621 }
622+
623+ #[ inline]
624+ fn min ( self , other : Self ) -> Self {
625+ fmin ( self , other)
626+ }
627+
628+ #[ inline]
629+ fn max ( self , other : Self ) -> Self {
630+ fmax ( self , other)
631+ }
604632}
605633
606634mod private {
Original file line number Diff line number Diff line change 1+ #[ inline]
2+ #[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
3+ pub fn fmax ( x : f64 , y : f64 ) -> f64 {
4+ // IEEE754 says: maxNum(x, y) is the canonicalized number y if x < y, x 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 x. is_nan ( ) || x < y { y } else { x } ) * 1.0
13+ }
Original file line number Diff line number Diff line change 1+ #[ inline]
2+ #[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
3+ pub fn fmaxf ( x : f32 , y : f32 ) -> f32 {
4+ // IEEE754 says: maxNum(x, y) is the canonicalized number y if x < y, x 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 x. is_nan ( ) || x < y { y } else { x } ) * 1.0
13+ }
Original file line number Diff line number Diff line change 1+ #[ inline]
2+ #[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
3+ pub fn fmin ( x : f64 , y : f64 ) -> f64 {
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+ }
Original file line number Diff line number Diff line change 1+ #[ inline]
2+ #[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
3+ pub fn fminf ( 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+ }
Original file line number Diff line number Diff line change @@ -112,6 +112,10 @@ mod floor;
112112mod floorf;
113113mod fma;
114114mod fmaf;
115+ mod fmax;
116+ mod fmaxf;
117+ mod fmin;
118+ mod fminf;
115119mod fmod;
116120mod fmodf;
117121mod frexp;
@@ -212,6 +216,10 @@ pub use self::floor::floor;
212216pub use self :: floorf:: floorf;
213217pub use self :: fma:: fma;
214218pub use self :: fmaf:: fmaf;
219+ pub use self :: fmax:: fmax;
220+ pub use self :: fmaxf:: fmaxf;
221+ pub use self :: fmin:: fmin;
222+ pub use self :: fminf:: fminf;
215223pub use self :: fmod:: fmod;
216224pub use self :: fmodf:: fmodf;
217225pub use self :: frexp:: frexp;
You can’t perform that action at this time.
0 commit comments