Skip to content

Commit 42a8dfb

Browse files
authored
Merge pull request rust-lang#466 from tgross35/generic-fmin-fmax
Add `fminf16`, `fmaxf16`, `fminf128`, and `fmaxf128`
2 parents 933d9b0 + f65487b commit 42a8dfb

19 files changed

+123
-44
lines changed

crates/libm-macros/src/shared.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
4747
FloatTy::F16,
4848
Signature { args: &[Ty::F16, Ty::F16], returns: &[Ty::F16] },
4949
None,
50-
&["copysignf16", "fdimf16"],
50+
&["copysignf16", "fdimf16", "fmaxf16", "fminf16"],
5151
),
5252
(
5353
// `(f32, f32) -> f32`
@@ -90,7 +90,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
9090
FloatTy::F128,
9191
Signature { args: &[Ty::F128, Ty::F128], returns: &[Ty::F128] },
9292
None,
93-
&["copysignf128", "fdimf128"],
93+
&["copysignf128", "fdimf128", "fmaxf128", "fminf128"],
9494
),
9595
(
9696
// `(f32, f32, f32) -> f32`

crates/libm-test/benches/random.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ libm_macros::for_each_function! {
127127
| fdimf16
128128
| floorf128
129129
| floorf16
130+
| fmaxf128
131+
| fmaxf16
132+
| fminf128
133+
| fminf16
130134
| rintf128
131135
| rintf16
132136
| roundf128

crates/libm-test/src/mpfloat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ libm_macros::for_each_function! {
192192
fabs | fabsf => abs,
193193
fdim | fdimf | fdimf16 | fdimf128 => positive_diff,
194194
fma | fmaf => mul_add,
195-
fmax | fmaxf => max,
196-
fmin | fminf => min,
195+
fmax | fmaxf | fmaxf16 | fmaxf128 => max,
196+
fmin | fminf | fminf16 | fminf128 => min,
197197
lgamma | lgammaf => ln_gamma,
198198
log | logf => ln,
199199
log1p | log1pf => ln_1p,

crates/libm-test/tests/compare_built_musl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ libm_macros::for_each_function! {
8989
fdimf16,
9090
floorf128,
9191
floorf16,
92+
fmaxf128,
93+
fmaxf16,
94+
fminf128,
95+
fminf16,
9296
rintf128,
9397
rintf16,
9498
roundf128,

crates/util/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
9696
| fdimf16
9797
| floorf128
9898
| floorf16
99+
| fmaxf128
100+
| fmaxf16
101+
| fminf128
102+
| fminf16
99103
| rintf128
100104
| rintf16
101105
| roundf128

etc/function-definitions.json

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,29 +379,61 @@
379379
"fmax": {
380380
"sources": [
381381
"src/libm_helper.rs",
382-
"src/math/fmax.rs"
382+
"src/math/fmax.rs",
383+
"src/math/generic/fmax.rs"
383384
],
384385
"type": "f64"
385386
},
386387
"fmaxf": {
387388
"sources": [
388-
"src/math/fmaxf.rs"
389+
"src/math/fmaxf.rs",
390+
"src/math/generic/fmax.rs"
389391
],
390392
"type": "f32"
391393
},
394+
"fmaxf128": {
395+
"sources": [
396+
"src/math/fmaxf128.rs",
397+
"src/math/generic/fmax.rs"
398+
],
399+
"type": "f128"
400+
},
401+
"fmaxf16": {
402+
"sources": [
403+
"src/math/fmaxf16.rs",
404+
"src/math/generic/fmax.rs"
405+
],
406+
"type": "f16"
407+
},
392408
"fmin": {
393409
"sources": [
394410
"src/libm_helper.rs",
395-
"src/math/fmin.rs"
411+
"src/math/fmin.rs",
412+
"src/math/generic/fmin.rs"
396413
],
397414
"type": "f64"
398415
},
399416
"fminf": {
400417
"sources": [
401-
"src/math/fminf.rs"
418+
"src/math/fminf.rs",
419+
"src/math/generic/fmin.rs"
402420
],
403421
"type": "f32"
404422
},
423+
"fminf128": {
424+
"sources": [
425+
"src/math/fminf128.rs",
426+
"src/math/generic/fmin.rs"
427+
],
428+
"type": "f128"
429+
},
430+
"fminf16": {
431+
"sources": [
432+
"src/math/fminf16.rs",
433+
"src/math/generic/fmin.rs"
434+
],
435+
"type": "f16"
436+
},
405437
"fmod": {
406438
"sources": [
407439
"src/libm_helper.rs",

etc/function-list.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ fma
5555
fmaf
5656
fmax
5757
fmaxf
58+
fmaxf128
59+
fmaxf16
5860
fmin
5961
fminf
62+
fminf128
63+
fminf16
6064
fmod
6165
fmodf
6266
frexp

src/math/fmax.rs

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

src/math/fmaxf.rs

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

src/math/fmaxf128.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Return the greater of two arguments or, if either argument is NaN, the other argument.
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn fmaxf128(x: f128, y: f128) -> f128 {
4+
super::generic::fmax(x, y)
5+
}

src/math/fmaxf16.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Return the greater of two arguments or, if either argument is NaN, the other argument.
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn fmaxf16(x: f16, y: f16) -> f16 {
4+
super::generic::fmax(x, y)
5+
}

src/math/fmin.rs

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

src/math/fminf.rs

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

src/math/fminf128.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Return the lesser of two arguments or, if either argument is NaN, the other argument.
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn fminf128(x: f128, y: f128) -> f128 {
4+
super::generic::fmin(x, y)
5+
}

src/math/fminf16.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Return the lesser of two arguments or, if either argument is NaN, the other argument.
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn fminf16(x: f16, y: f16) -> f16 {
4+
super::generic::fmin(x, y)
5+
}

src/math/generic/fmax.rs

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

src/math/generic/fmin.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use super::super::Float;
2+
3+
pub fn fmin<F: Float>(x: F, y: F) -> F {
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 }) * F::ONE
13+
}

src/math/generic/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ mod copysign;
33
mod fabs;
44
mod fdim;
55
mod floor;
6+
mod fmax;
7+
mod fmin;
68
mod rint;
79
mod round;
810
mod scalbn;
@@ -14,6 +16,8 @@ pub use copysign::copysign;
1416
pub use fabs::fabs;
1517
pub use fdim::fdim;
1618
pub use floor::floor;
19+
pub use fmax::fmax;
20+
pub use fmin::fmin;
1721
pub use rint::rint;
1822
pub use round::round;
1923
pub use scalbn::scalbn;

src/math/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ cfg_if! {
346346
mod fabsf16;
347347
mod fdimf16;
348348
mod floorf16;
349+
mod fmaxf16;
350+
mod fminf16;
349351
mod rintf16;
350352
mod roundf16;
351353
mod sqrtf16;
@@ -356,6 +358,8 @@ cfg_if! {
356358
pub use self::fabsf16::fabsf16;
357359
pub use self::fdimf16::fdimf16;
358360
pub use self::floorf16::floorf16;
361+
pub use self::fmaxf16::fmaxf16;
362+
pub use self::fminf16::fminf16;
359363
pub use self::rintf16::rintf16;
360364
pub use self::roundf16::roundf16;
361365
pub use self::sqrtf16::sqrtf16;
@@ -370,6 +374,8 @@ cfg_if! {
370374
mod fabsf128;
371375
mod fdimf128;
372376
mod floorf128;
377+
mod fmaxf128;
378+
mod fminf128;
373379
mod rintf128;
374380
mod roundf128;
375381
mod sqrtf128;
@@ -380,6 +386,8 @@ cfg_if! {
380386
pub use self::fabsf128::fabsf128;
381387
pub use self::fdimf128::fdimf128;
382388
pub use self::floorf128::floorf128;
389+
pub use self::fmaxf128::fmaxf128;
390+
pub use self::fminf128::fminf128;
383391
pub use self::rintf128::rintf128;
384392
pub use self::roundf128::roundf128;
385393
pub use self::sqrtf128::sqrtf128;

0 commit comments

Comments
 (0)