| 1 | /// Return the lesser of two arguments or, if either argument is NaN, the other argument. |
| 2 | /// |
| 3 | /// This coincides with IEEE 754-2019 `minimum`. The result orders -0.0 < 0.0. |
| 4 | #[cfg (f16_enabled)] |
| 5 | #[cfg_attr (all(test, assert_no_panic), no_panic::no_panic)] |
| 6 | pub fn fminimumf16(x: f16, y: f16) -> f16 { |
| 7 | super::generic::fminimum(x, y) |
| 8 | } |
| 9 | |
| 10 | /// Return the lesser of two arguments or, if either argument is NaN, the other argument. |
| 11 | /// |
| 12 | /// This coincides with IEEE 754-2019 `minimum`. The result orders -0.0 < 0.0. |
| 13 | #[cfg_attr (all(test, assert_no_panic), no_panic::no_panic)] |
| 14 | pub fn fminimum(x: f64, y: f64) -> f64 { |
| 15 | super::generic::fminimum(x, y) |
| 16 | } |
| 17 | |
| 18 | /// Return the lesser of two arguments or, if either argument is NaN, the other argument. |
| 19 | /// |
| 20 | /// This coincides with IEEE 754-2019 `minimum`. The result orders -0.0 < 0.0. |
| 21 | #[cfg_attr (all(test, assert_no_panic), no_panic::no_panic)] |
| 22 | pub fn fminimumf(x: f32, y: f32) -> f32 { |
| 23 | super::generic::fminimum(x, y) |
| 24 | } |
| 25 | |
| 26 | /// Return the lesser of two arguments or, if either argument is NaN, the other argument. |
| 27 | /// |
| 28 | /// This coincides with IEEE 754-2019 `minimum`. The result orders -0.0 < 0.0. |
| 29 | #[cfg (f128_enabled)] |
| 30 | #[cfg_attr (all(test, assert_no_panic), no_panic::no_panic)] |
| 31 | pub fn fminimumf128(x: f128, y: f128) -> f128 { |
| 32 | super::generic::fminimum(x, y) |
| 33 | } |
| 34 | |
| 35 | /// Return the greater of two arguments or, if either argument is NaN, the other argument. |
| 36 | /// |
| 37 | /// This coincides with IEEE 754-2019 `maximum`. The result orders -0.0 < 0.0. |
| 38 | #[cfg (f16_enabled)] |
| 39 | #[cfg_attr (all(test, assert_no_panic), no_panic::no_panic)] |
| 40 | pub fn fmaximumf16(x: f16, y: f16) -> f16 { |
| 41 | super::generic::fmaximum(x, y) |
| 42 | } |
| 43 | |
| 44 | /// Return the greater of two arguments or, if either argument is NaN, the other argument. |
| 45 | /// |
| 46 | /// This coincides with IEEE 754-2019 `maximum`. The result orders -0.0 < 0.0. |
| 47 | #[cfg_attr (all(test, assert_no_panic), no_panic::no_panic)] |
| 48 | pub fn fmaximumf(x: f32, y: f32) -> f32 { |
| 49 | super::generic::fmaximum(x, y) |
| 50 | } |
| 51 | |
| 52 | /// Return the greater of two arguments or, if either argument is NaN, the other argument. |
| 53 | /// |
| 54 | /// This coincides with IEEE 754-2019 `maximum`. The result orders -0.0 < 0.0. |
| 55 | #[cfg_attr (all(test, assert_no_panic), no_panic::no_panic)] |
| 56 | pub fn fmaximum(x: f64, y: f64) -> f64 { |
| 57 | super::generic::fmaximum(x, y) |
| 58 | } |
| 59 | |
| 60 | /// Return the greater of two arguments or, if either argument is NaN, the other argument. |
| 61 | /// |
| 62 | /// This coincides with IEEE 754-2019 `maximum`. The result orders -0.0 < 0.0. |
| 63 | #[cfg (f128_enabled)] |
| 64 | #[cfg_attr (all(test, assert_no_panic), no_panic::no_panic)] |
| 65 | pub fn fmaximumf128(x: f128, y: f128) -> f128 { |
| 66 | super::generic::fmaximum(x, y) |
| 67 | } |
| 68 | |
| 69 | #[cfg (test)] |
| 70 | mod tests { |
| 71 | use super::*; |
| 72 | use crate::support::{Float, Hexf}; |
| 73 | |
| 74 | fn fminimum_spec_test<F: Float>(f: impl Fn(F, F) -> F) { |
| 75 | let cases = [ |
| 76 | (F::ZERO, F::ZERO, F::ZERO), |
| 77 | (F::ONE, F::ONE, F::ONE), |
| 78 | (F::ZERO, F::ONE, F::ZERO), |
| 79 | (F::ONE, F::ZERO, F::ZERO), |
| 80 | (F::ZERO, F::NEG_ONE, F::NEG_ONE), |
| 81 | (F::NEG_ONE, F::ZERO, F::NEG_ONE), |
| 82 | (F::INFINITY, F::ZERO, F::ZERO), |
| 83 | (F::NEG_INFINITY, F::ZERO, F::NEG_INFINITY), |
| 84 | (F::NAN, F::ZERO, F::NAN), |
| 85 | (F::ZERO, F::NAN, F::NAN), |
| 86 | (F::NAN, F::NAN, F::NAN), |
| 87 | (F::ZERO, F::NEG_ZERO, F::NEG_ZERO), |
| 88 | (F::NEG_ZERO, F::ZERO, F::NEG_ZERO), |
| 89 | ]; |
| 90 | |
| 91 | for (x, y, res) in cases { |
| 92 | let val = f(x, y); |
| 93 | assert_biteq!(val, res, "fminimum({}, {})" , Hexf(x), Hexf(y)); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | #[test ] |
| 98 | #[cfg (f16_enabled)] |
| 99 | fn fminimum_spec_tests_f16() { |
| 100 | fminimum_spec_test::<f16>(fminimumf16); |
| 101 | } |
| 102 | |
| 103 | #[test ] |
| 104 | fn fminimum_spec_tests_f32() { |
| 105 | fminimum_spec_test::<f32>(fminimumf); |
| 106 | } |
| 107 | |
| 108 | #[test ] |
| 109 | fn fminimum_spec_tests_f64() { |
| 110 | fminimum_spec_test::<f64>(fminimum); |
| 111 | } |
| 112 | |
| 113 | #[test ] |
| 114 | #[cfg (f128_enabled)] |
| 115 | fn fminimum_spec_tests_f128() { |
| 116 | fminimum_spec_test::<f128>(fminimumf128); |
| 117 | } |
| 118 | |
| 119 | fn fmaximum_spec_test<F: Float>(f: impl Fn(F, F) -> F) { |
| 120 | let cases = [ |
| 121 | (F::ZERO, F::ZERO, F::ZERO), |
| 122 | (F::ONE, F::ONE, F::ONE), |
| 123 | (F::ZERO, F::ONE, F::ONE), |
| 124 | (F::ONE, F::ZERO, F::ONE), |
| 125 | (F::ZERO, F::NEG_ONE, F::ZERO), |
| 126 | (F::NEG_ONE, F::ZERO, F::ZERO), |
| 127 | (F::INFINITY, F::ZERO, F::INFINITY), |
| 128 | (F::NEG_INFINITY, F::ZERO, F::ZERO), |
| 129 | (F::NAN, F::ZERO, F::NAN), |
| 130 | (F::ZERO, F::NAN, F::NAN), |
| 131 | (F::NAN, F::NAN, F::NAN), |
| 132 | (F::ZERO, F::NEG_ZERO, F::ZERO), |
| 133 | (F::NEG_ZERO, F::ZERO, F::ZERO), |
| 134 | ]; |
| 135 | |
| 136 | for (x, y, res) in cases { |
| 137 | let val = f(x, y); |
| 138 | assert_biteq!(val, res, "fmaximum({}, {})" , Hexf(x), Hexf(y)); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | #[test ] |
| 143 | #[cfg (f16_enabled)] |
| 144 | fn fmaximum_spec_tests_f16() { |
| 145 | fmaximum_spec_test::<f16>(fmaximumf16); |
| 146 | } |
| 147 | |
| 148 | #[test ] |
| 149 | fn fmaximum_spec_tests_f32() { |
| 150 | fmaximum_spec_test::<f32>(fmaximumf); |
| 151 | } |
| 152 | |
| 153 | #[test ] |
| 154 | fn fmaximum_spec_tests_f64() { |
| 155 | fmaximum_spec_test::<f64>(fmaximum); |
| 156 | } |
| 157 | |
| 158 | #[test ] |
| 159 | #[cfg (f128_enabled)] |
| 160 | fn fmaximum_spec_tests_f128() { |
| 161 | fmaximum_spec_test::<f128>(fmaximumf128); |
| 162 | } |
| 163 | } |
| 164 | |