• Home
  • Raw
  • Download

Lines Matching +full:check +full:- +full:examples

15     /// # Examples
21 /// fn check<T: FloatCore>(x: T) {
25 /// check(f32::INFINITY);
26 /// check(f64::INFINITY);
28 fn infinity() -> Self; in infinity()
32 /// # Examples
38 /// fn check<T: FloatCore>(x: T) {
42 /// check(f32::NEG_INFINITY);
43 /// check(f64::NEG_INFINITY);
45 fn neg_infinity() -> Self; in neg_infinity()
49 /// # Examples
54 /// fn check<T: FloatCore>() {
59 /// check::<f32>();
60 /// check::<f64>();
62 fn nan() -> Self; in nan()
64 /// Returns `-0.0`.
66 /// # Examples
72 /// fn check<T: FloatCore>(n: T) {
78 /// check(f32::NEG_INFINITY);
79 /// check(f64::NEG_INFINITY);
81 fn neg_zero() -> Self; in neg_zero()
85 /// # Examples
91 /// fn check<T: FloatCore>(x: T) {
95 /// check(f32::MIN);
96 /// check(f64::MIN);
98 fn min_value() -> Self; in min_value()
102 /// # Examples
108 /// fn check<T: FloatCore>(x: T) {
112 /// check(f32::MIN_POSITIVE);
113 /// check(f64::MIN_POSITIVE);
115 fn min_positive_value() -> Self; in min_positive_value()
119 /// # Examples
125 /// fn check<T: FloatCore>(x: T) {
129 /// check(f32::EPSILON);
130 /// check(f64::EPSILON);
132 fn epsilon() -> Self; in epsilon()
136 /// # Examples
142 /// fn check<T: FloatCore>(x: T) {
146 /// check(f32::MAX);
147 /// check(f64::MAX);
149 fn max_value() -> Self; in max_value()
153 /// # Examples
159 /// fn check<T: FloatCore>(x: T, p: bool) {
163 /// check(f32::NAN, true);
164 /// check(f32::INFINITY, false);
165 /// check(f64::NAN, true);
166 /// check(0.0f64, false);
170 fn is_nan(self) -> bool { in is_nan()
176 /// # Examples
182 /// fn check<T: FloatCore>(x: T, p: bool) {
186 /// check(f32::INFINITY, true);
187 /// check(f32::NEG_INFINITY, true);
188 /// check(f32::NAN, false);
189 /// check(f64::INFINITY, true);
190 /// check(f64::NEG_INFINITY, true);
191 /// check(0.0f64, false);
194 fn is_infinite(self) -> bool { in is_infinite()
200 /// # Examples
206 /// fn check<T: FloatCore>(x: T, p: bool) {
210 /// check(f32::INFINITY, false);
211 /// check(f32::MAX, true);
212 /// check(f64::NEG_INFINITY, false);
213 /// check(f64::MIN_POSITIVE, true);
214 /// check(f64::NAN, false);
217 fn is_finite(self) -> bool { in is_finite()
223 /// # Examples
229 /// fn check<T: FloatCore>(x: T, p: bool) {
233 /// check(f32::INFINITY, false);
234 /// check(f32::MAX, true);
235 /// check(f64::NEG_INFINITY, false);
236 /// check(f64::MIN_POSITIVE, true);
237 /// check(0.0f64, false);
240 fn is_normal(self) -> bool { in is_normal()
250 /// let min = f64::MIN_POSITIVE; // 2.2250738585072014e-308_f64
252 /// let lower_than_min = 1.0e-308_f64;
266 fn is_subnormal(self) -> bool { in is_subnormal()
274 /// # Examples
281 /// fn check<T: FloatCore>(x: T, c: FpCategory) {
285 /// check(f32::INFINITY, FpCategory::Infinite);
286 /// check(f32::MAX, FpCategory::Normal);
287 /// check(f64::NAN, FpCategory::Nan);
288 /// check(f64::MIN_POSITIVE, FpCategory::Normal);
289 /// check(f64::MIN_POSITIVE / 2.0, FpCategory::Subnormal);
290 /// check(0.0f64, FpCategory::Zero);
292 fn classify(self) -> FpCategory; in classify()
296 /// # Examples
302 /// fn check<T: FloatCore>(x: T, y: T) {
306 /// check(f32::INFINITY, f32::INFINITY);
307 /// check(0.9f32, 0.0);
308 /// check(1.0f32, 1.0);
309 /// check(1.1f32, 1.0);
310 /// check(-0.0f64, 0.0);
311 /// check(-0.9f64, -1.0);
312 /// check(-1.0f64, -1.0);
313 /// check(-1.1f64, -2.0);
314 /// check(f64::MIN, f64::MIN);
317 fn floor(self) -> Self { in floor()
322 self - f - Self::one() in floor()
324 self - f in floor()
330 /// # Examples
336 /// fn check<T: FloatCore>(x: T, y: T) {
340 /// check(f32::INFINITY, f32::INFINITY);
341 /// check(0.9f32, 1.0);
342 /// check(1.0f32, 1.0);
343 /// check(1.1f32, 2.0);
344 /// check(-0.0f64, 0.0);
345 /// check(-0.9f64, -0.0);
346 /// check(-1.0f64, -1.0);
347 /// check(-1.1f64, -1.0);
348 /// check(f64::MIN, f64::MIN);
351 fn ceil(self) -> Self { in ceil()
356 self - f + Self::one() in ceil()
358 self - f in ceil()
362 /// Returns the nearest integer to a number. Round half-way cases away from `0.0`.
364 /// # Examples
370 /// fn check<T: FloatCore>(x: T, y: T) {
374 /// check(f32::INFINITY, f32::INFINITY);
375 /// check(0.4f32, 0.0);
376 /// check(0.5f32, 1.0);
377 /// check(0.6f32, 1.0);
378 /// check(-0.4f64, 0.0);
379 /// check(-0.5f64, -1.0);
380 /// check(-0.6f64, -1.0);
381 /// check(f64::MIN, f64::MIN);
384 fn round(self) -> Self { in round()
392 self - f in round()
394 self - f + one in round()
396 } else if -f < h { in round()
397 self - f in round()
399 self - f - one in round()
405 /// # Examples
411 /// fn check<T: FloatCore>(x: T, y: T) {
415 /// check(f32::INFINITY, f32::INFINITY);
416 /// check(0.9f32, 0.0);
417 /// check(1.0f32, 1.0);
418 /// check(1.1f32, 1.0);
419 /// check(-0.0f64, 0.0);
420 /// check(-0.9f64, -0.0);
421 /// check(-1.0f64, -1.0);
422 /// check(-1.1f64, -1.0);
423 /// check(f64::MIN, f64::MIN);
426 fn trunc(self) -> Self { in trunc()
431 self - f in trunc()
437 /// # Examples
443 /// fn check<T: FloatCore>(x: T, y: T) {
447 /// check(f32::MAX, 0.0);
448 /// check(0.75f32, 0.75);
449 /// check(1.0f32, 0.0);
450 /// check(1.25f32, 0.25);
451 /// check(-0.0f64, 0.0);
452 /// check(-0.75f64, -0.75);
453 /// check(-1.0f64, 0.0);
454 /// check(-1.25f64, -0.25);
455 /// check(f64::MIN, 0.0);
458 fn fract(self) -> Self { in fract()
469 /// # Examples
475 /// fn check<T: FloatCore>(x: T, y: T) {
479 /// check(f32::INFINITY, f32::INFINITY);
480 /// check(1.0f32, 1.0);
481 /// check(0.0f64, 0.0);
482 /// check(-0.0f64, 0.0);
483 /// check(-1.0f64, 1.0);
484 /// check(f64::MIN, f64::MAX);
487 fn abs(self) -> Self { in abs()
492 return -self; in abs()
499 /// - `1.0` if the number is positive, `+0.0` or `FloatCore::infinity()`
500 /// - `-1.0` if the number is negative, `-0.0` or `FloatCore::neg_infinity()`
501 /// - `FloatCore::nan()` if the number is `FloatCore::nan()`
503 /// # Examples
509 /// fn check<T: FloatCore>(x: T, y: T) {
513 /// check(f32::INFINITY, 1.0);
514 /// check(3.0f32, 1.0);
515 /// check(0.0f32, 1.0);
516 /// check(-0.0f64, -1.0);
517 /// check(-3.0f64, -1.0);
518 /// check(f64::MIN, -1.0);
521 fn signum(self) -> Self { in signum()
525 -Self::one() in signum()
534 /// # Examples
540 /// fn check<T: FloatCore>(x: T, p: bool) {
544 /// check(f32::INFINITY, true);
545 /// check(f32::MAX, true);
546 /// check(0.0f32, true);
547 /// check(-0.0f64, false);
548 /// check(f64::NEG_INFINITY, false);
549 /// check(f64::MIN_POSITIVE, true);
550 /// check(f64::NAN, true);
551 /// check(-f64::NAN, false);
554 fn is_sign_positive(self) -> bool { in is_sign_positive()
558 /// Returns `true` if `self` is negative, including `-0.0` and
559 /// `FloatCore::neg_infinity()`, and `-FloatCore::nan()`.
561 /// # Examples
567 /// fn check<T: FloatCore>(x: T, p: bool) {
571 /// check(f32::INFINITY, false);
572 /// check(f32::MAX, false);
573 /// check(0.0f32, false);
574 /// check(-0.0f64, true);
575 /// check(f64::NEG_INFINITY, true);
576 /// check(f64::MIN_POSITIVE, false);
577 /// check(f64::NAN, false);
578 /// check(-f64::NAN, true);
581 fn is_sign_negative(self) -> bool { in is_sign_negative()
590 /// # Examples
596 /// fn check<T: FloatCore>(x: T, y: T, min: T) {
600 /// check(1.0f32, 2.0, 1.0);
601 /// check(f32::NAN, 2.0, 2.0);
602 /// check(1.0f64, -2.0, -2.0);
603 /// check(1.0f64, f64::NAN, 1.0);
606 fn min(self, other: Self) -> Self { in min()
624 /// # Examples
630 /// fn check<T: FloatCore>(x: T, y: T, max: T) {
634 /// check(1.0f32, 2.0, 2.0);
635 /// check(1.0f32, f32::NAN, 1.0);
636 /// check(-1.0f64, 2.0, 2.0);
637 /// check(-1.0f64, f64::NAN, -1.0);
640 fn max(self, other: Self) -> Self { in max()
656 /// # Examples
662 /// fn check<T: FloatCore>(x: T, y: T) {
667 /// check(f32::INFINITY, 0.0);
668 /// check(2.0f32, 0.5);
669 /// check(-0.25f64, -4.0);
670 /// check(-0.0f64, f64::NEG_INFINITY);
673 fn recip(self) -> Self { in recip()
681 /// # Examples
686 /// fn check<T: FloatCore>(x: T, exp: i32, powi: T) {
690 /// check(9.0f32, 2, 81.0);
691 /// check(1.0f32, -2, 1.0);
692 /// check(10.0f64, 20, 1e20);
693 /// check(4.0f64, -2, 0.0625);
694 /// check(-1.0f64, std::i32::MIN, 1.0);
697 fn powi(mut self, mut exp: i32) -> Self { in powi()
704 // to `u32` without sign-extension before growing to `usize`. in powi()
710 /// # Examples
716 /// fn check<T: FloatCore>(rad: T, deg: T) {
720 /// check(0.0f32, 0.0);
721 /// check(f32::consts::PI, 180.0);
722 /// check(f64::consts::FRAC_PI_4, 45.0);
723 /// check(f64::INFINITY, f64::INFINITY);
725 fn to_degrees(self) -> Self; in to_degrees()
729 /// # Examples
735 /// fn check<T: FloatCore>(deg: T, rad: T) {
739 /// check(0.0f32, 0.0);
740 /// check(180.0, f32::consts::PI);
741 /// check(45.0, f64::consts::FRAC_PI_4);
742 /// check(f64::INFINITY, f64::INFINITY);
744 fn to_radians(self) -> Self; in to_radians()
749 /// # Examples
755 /// fn check<T: FloatCore>(x: T, m: u64, e: i16, s:i8) {
762 /// check(2.0f32, 1 << 23, -22, 1);
763 /// check(-2.0f32, 1 << 23, -22, -1);
764 /// check(f32::INFINITY, 1 << 23, 105, 1);
765 /// check(f64::NEG_INFINITY, 1 << 52, 972, -1);
767 fn integer_decode(self) -> (u64, i16, i8); in integer_decode()
772 infinity() -> f32::INFINITY;
773 neg_infinity() -> f32::NEG_INFINITY;
774 nan() -> f32::NAN;
775 neg_zero() -> -0.0;
776 min_value() -> f32::MIN;
777 min_positive_value() -> f32::MIN_POSITIVE;
778 epsilon() -> f32::EPSILON;
779 max_value() -> f32::MAX;
783 fn integer_decode(self) -> (u64, i16, i8) { in integer_decode()
788 Self::is_nan(self) -> bool;
789 Self::is_infinite(self) -> bool;
790 Self::is_finite(self) -> bool;
791 Self::is_normal(self) -> bool;
792 Self::classify(self) -> FpCategory;
793 Self::is_sign_positive(self) -> bool;
794 Self::is_sign_negative(self) -> bool;
795 Self::min(self, other: Self) -> Self;
796 Self::max(self, other: Self) -> Self;
797 Self::recip(self) -> Self;
798 Self::to_degrees(self) -> Self;
799 Self::to_radians(self) -> Self;
804 Self::is_subnormal(self) -> bool;
809 Self::floor(self) -> Self;
810 Self::ceil(self) -> Self;
811 Self::round(self) -> Self;
812 Self::trunc(self) -> Self;
813 Self::fract(self) -> Self;
814 Self::abs(self) -> Self;
815 Self::signum(self) -> Self;
816 Self::powi(self, n: i32) -> Self;
821 libm::floorf as floor(self) -> Self;
822 libm::ceilf as ceil(self) -> Self;
823 libm::roundf as round(self) -> Self;
824 libm::truncf as trunc(self) -> Self;
825 libm::fabsf as abs(self) -> Self;
830 fn fract(self) -> Self { in fract()
831 self - libm::truncf(self) in fract()
837 infinity() -> f64::INFINITY;
838 neg_infinity() -> f64::NEG_INFINITY;
839 nan() -> f64::NAN;
840 neg_zero() -> -0.0;
841 min_value() -> f64::MIN;
842 min_positive_value() -> f64::MIN_POSITIVE;
843 epsilon() -> f64::EPSILON;
844 max_value() -> f64::MAX;
848 fn integer_decode(self) -> (u64, i16, i8) { in integer_decode()
853 Self::is_nan(self) -> bool;
854 Self::is_infinite(self) -> bool;
855 Self::is_finite(self) -> bool;
856 Self::is_normal(self) -> bool;
857 Self::classify(self) -> FpCategory;
858 Self::is_sign_positive(self) -> bool;
859 Self::is_sign_negative(self) -> bool;
860 Self::min(self, other: Self) -> Self;
861 Self::max(self, other: Self) -> Self;
862 Self::recip(self) -> Self;
863 Self::to_degrees(self) -> Self;
864 Self::to_radians(self) -> Self;
869 Self::is_subnormal(self) -> bool;
874 Self::floor(self) -> Self;
875 Self::ceil(self) -> Self;
876 Self::round(self) -> Self;
877 Self::trunc(self) -> Self;
878 Self::fract(self) -> Self;
879 Self::abs(self) -> Self;
880 Self::signum(self) -> Self;
881 Self::powi(self, n: i32) -> Self;
886 libm::floor as floor(self) -> Self;
887 libm::ceil as ceil(self) -> Self;
888 libm::round as round(self) -> Self;
889 libm::trunc as trunc(self) -> Self;
890 libm::fabs as abs(self) -> Self;
895 fn fract(self) -> Self { in fract()
896 self - libm::trunc(self) in fract()
917 fn nan() -> Self; in nan()
930 fn infinity() -> Self; in infinity()
943 fn neg_infinity() -> Self; in neg_infinity()
944 /// Returns `-0.0`.
957 fn neg_zero() -> Self; in neg_zero()
969 fn min_value() -> Self; in min_value()
981 fn min_positive_value() -> Self; in min_positive_value()
998 fn epsilon() -> Self { in epsilon()
1011 fn max_value() -> Self; in max_value()
1025 fn is_nan(self) -> bool; in is_nan()
1045 fn is_infinite(self) -> bool; in is_infinite()
1064 fn is_finite(self) -> bool; in is_finite()
1073 /// let min = f32::MIN_POSITIVE; // 1.17549435e-38f32
1075 /// let lower_than_min = 1.0e-40_f32;
1088 fn is_normal(self) -> bool; in is_normal()
1096 /// let min = f64::MIN_POSITIVE; // 2.2250738585072014e-308_f64
1098 /// let lower_than_min = 1.0e-308_f64;
1112 fn is_subnormal(self) -> bool { in is_subnormal()
1131 fn classify(self) -> FpCategory; in classify()
1144 fn floor(self) -> Self; in floor()
1157 fn ceil(self) -> Self; in ceil()
1159 /// Returns the nearest integer to a number. Round half-way cases away from
1166 /// let g = -3.3;
1169 /// assert_eq!(g.round(), -3.0);
1171 fn round(self) -> Self; in round()
1179 /// let g = -3.7;
1182 /// assert_eq!(g.trunc(), -3.0);
1184 fn trunc(self) -> Self; in trunc()
1192 /// let y = -3.5;
1193 /// let abs_difference_x = (x.fract() - 0.5).abs();
1194 /// let abs_difference_y = (y.fract() - (-0.5)).abs();
1196 /// assert!(abs_difference_x < 1e-10);
1197 /// assert!(abs_difference_y < 1e-10);
1199 fn fract(self) -> Self; in fract()
1209 /// let y = -3.5;
1211 /// let abs_difference_x = (x.abs() - x).abs();
1212 /// let abs_difference_y = (y.abs() - (-y)).abs();
1214 /// assert!(abs_difference_x < 1e-10);
1215 /// assert!(abs_difference_y < 1e-10);
1219 fn abs(self) -> Self; in abs()
1223 /// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
1224 /// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
1225 /// - `Float::nan()` if the number is `Float::nan()`
1234 /// assert_eq!(f64::NEG_INFINITY.signum(), -1.0);
1238 fn signum(self) -> Self; in signum()
1248 /// let neg_nan: f64 = -f64::NAN;
1251 /// let g = -7.0;
1258 fn is_sign_positive(self) -> bool; in is_sign_positive()
1260 /// Returns `true` if `self` is negative, including `-0.0`,
1261 /// `Float::neg_infinity()`, and `-Float::nan()`.
1268 /// let neg_nan: f64 = -f64::NAN;
1271 /// let g = -7.0;
1278 fn is_sign_negative(self) -> bool; in is_sign_negative()
1280 /// Fused multiply-add. Computes `(self * a) + b` with only one rounding
1281 /// error, yielding a more accurate result than an unfused multiply-add.
1283 /// Using `mul_add` can be more performant than an unfused multiply-add if
1294 /// let abs_difference = (m.mul_add(x, b) - (m*x + b)).abs();
1296 /// assert!(abs_difference < 1e-10);
1298 fn mul_add(self, a: Self, b: Self) -> Self; in mul_add()
1305 /// let abs_difference = (x.recip() - (1.0/x)).abs();
1307 /// assert!(abs_difference < 1e-10);
1309 fn recip(self) -> Self; in recip()
1319 /// let abs_difference = (x.powi(2) - x*x).abs();
1321 /// assert!(abs_difference < 1e-10);
1323 fn powi(self, n: i32) -> Self; in powi()
1331 /// let abs_difference = (x.powf(2.0) - x*x).abs();
1333 /// assert!(abs_difference < 1e-10);
1335 fn powf(self, n: Self) -> Self; in powf()
1345 /// let negative = -4.0;
1347 /// let abs_difference = (positive.sqrt() - 2.0).abs();
1349 /// assert!(abs_difference < 1e-10);
1352 fn sqrt(self) -> Self; in sqrt()
1363 /// // ln(e) - 1 == 0
1364 /// let abs_difference = (e.ln() - 1.0).abs();
1366 /// assert!(abs_difference < 1e-10);
1368 fn exp(self) -> Self; in exp()
1377 /// // 2^2 - 4 == 0
1378 /// let abs_difference = (f.exp2() - 4.0).abs();
1380 /// assert!(abs_difference < 1e-10);
1382 fn exp2(self) -> Self; in exp2()
1393 /// // ln(e) - 1 == 0
1394 /// let abs_difference = (e.ln() - 1.0).abs();
1396 /// assert!(abs_difference < 1e-10);
1398 fn ln(self) -> Self; in ln()
1408 /// // log10(10) - 1 == 0
1409 /// let abs_difference_10 = (ten.log(10.0) - 1.0).abs();
1411 /// // log2(2) - 1 == 0
1412 /// let abs_difference_2 = (two.log(2.0) - 1.0).abs();
1414 /// assert!(abs_difference_10 < 1e-10);
1415 /// assert!(abs_difference_2 < 1e-10);
1417 fn log(self, base: Self) -> Self; in log()
1426 /// // log2(2) - 1 == 0
1427 /// let abs_difference = (two.log2() - 1.0).abs();
1429 /// assert!(abs_difference < 1e-10);
1431 fn log2(self) -> Self; in log2()
1440 /// // log10(10) - 1 == 0
1441 /// let abs_difference = (ten.log10() - 1.0).abs();
1443 /// assert!(abs_difference < 1e-10);
1445 fn log10(self) -> Self; in log10()
1454 /// let abs_difference = (angle.to_degrees() - 180.0).abs();
1456 /// assert!(abs_difference < 1e-10);
1459 fn to_degrees(self) -> Self { in to_degrees()
1472 /// let abs_difference = (angle.to_radians() - consts::PI).abs();
1474 /// assert!(abs_difference < 1e-10);
1477 fn to_radians(self) -> Self { in to_radians()
1493 fn max(self, other: Self) -> Self; in max()
1505 fn min(self, other: Self) -> Self; in min()
1510 /// * Else: `self - other`
1516 /// let y = -3.0;
1518 /// let abs_difference_x = (x.abs_sub(1.0) - 2.0).abs();
1519 /// let abs_difference_y = (y.abs_sub(1.0) - 0.0).abs();
1521 /// assert!(abs_difference_x < 1e-10);
1522 /// assert!(abs_difference_y < 1e-10);
1524 fn abs_sub(self, other: Self) -> Self; in abs_sub()
1533 /// // x^(1/3) - 2 == 0
1534 /// let abs_difference = (x.cbrt() - 2.0).abs();
1536 /// assert!(abs_difference < 1e-10);
1538 fn cbrt(self) -> Self; in cbrt()
1540 /// Calculate the length of the hypotenuse of a right-angle triangle given
1550 /// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();
1552 /// assert!(abs_difference < 1e-10);
1554 fn hypot(self, other: Self) -> Self; in hypot()
1564 /// let abs_difference = (x.sin() - 1.0).abs();
1566 /// assert!(abs_difference < 1e-10);
1568 fn sin(self) -> Self; in sin()
1578 /// let abs_difference = (x.cos() - 1.0).abs();
1580 /// assert!(abs_difference < 1e-10);
1582 fn cos(self) -> Self; in cos()
1591 /// let abs_difference = (x.tan() - 1.0).abs();
1593 /// assert!(abs_difference < 1e-14);
1595 fn tan(self) -> Self; in tan()
1598 /// the range [-pi/2, pi/2] or NaN if the number is outside the range
1599 /// [-1, 1].
1608 /// let abs_difference = (f.sin().asin() - f64::consts::PI / 2.0).abs();
1610 /// assert!(abs_difference < 1e-10);
1612 fn asin(self) -> Self; in asin()
1616 /// [-1, 1].
1625 /// let abs_difference = (f.cos().acos() - f64::consts::PI / 4.0).abs();
1627 /// assert!(abs_difference < 1e-10);
1629 fn acos(self) -> Self; in acos()
1632 /// range [-pi/2, pi/2];
1640 /// let abs_difference = (f.tan().atan() - 1.0).abs();
1642 /// assert!(abs_difference < 1e-10);
1644 fn atan(self) -> Self; in atan()
1649 /// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]`
1650 /// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
1651 /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
1659 /// // 45 deg counter-clockwise
1661 /// let y1 = -3.0;
1664 /// let x2 = -3.0;
1667 /// let abs_difference_1 = (y1.atan2(x1) - (-pi/4.0)).abs();
1668 /// let abs_difference_2 = (y2.atan2(x2) - 3.0*pi/4.0).abs();
1670 /// assert!(abs_difference_1 < 1e-10);
1671 /// assert!(abs_difference_2 < 1e-10);
1673 fn atan2(self, other: Self) -> Self; in atan2()
1685 /// let abs_difference_0 = (f.0 - x.sin()).abs();
1686 /// let abs_difference_1 = (f.1 - x.cos()).abs();
1688 /// assert!(abs_difference_0 < 1e-10);
1689 /// assert!(abs_difference_0 < 1e-10);
1691 fn sin_cos(self) -> (Self, Self); in sin_cos()
1693 /// Returns `e^(self) - 1` in a way that is accurate even if the
1701 /// // e^(ln(7)) - 1
1702 /// let abs_difference = (x.ln().exp_m1() - 6.0).abs();
1704 /// assert!(abs_difference < 1e-10);
1706 fn exp_m1(self) -> Self; in exp_m1()
1715 /// let x = f64::consts::E - 1.0;
1717 /// // ln(1 + (e - 1)) == ln(e) == 1
1718 /// let abs_difference = (x.ln_1p() - 1.0).abs();
1720 /// assert!(abs_difference < 1e-10);
1722 fn ln_1p(self) -> Self; in ln_1p()
1734 /// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
1735 /// let g = (e*e - 1.0)/(2.0*e);
1736 /// let abs_difference = (f - g).abs();
1738 /// assert!(abs_difference < 1e-10);
1740 fn sinh(self) -> Self; in sinh()
1753 /// let abs_difference = (f - g).abs();
1756 /// assert!(abs_difference < 1.0e-10);
1758 fn cosh(self) -> Self; in cosh()
1770 /// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
1771 /// let g = (1.0 - e.powi(-2))/(1.0 + e.powi(-2));
1772 /// let abs_difference = (f - g).abs();
1774 /// assert!(abs_difference < 1.0e-10);
1776 fn tanh(self) -> Self; in tanh()
1786 /// let abs_difference = (f - x).abs();
1788 /// assert!(abs_difference < 1.0e-10);
1790 fn asinh(self) -> Self; in asinh()
1800 /// let abs_difference = (f - x).abs();
1802 /// assert!(abs_difference < 1.0e-10);
1804 fn acosh(self) -> Self; in acosh()
1815 /// let abs_difference = (f - e).abs();
1817 /// assert!(abs_difference < 1.0e-10);
1819 fn atanh(self) -> Self; in atanh()
1829 /// // (8388608, -22, 1)
1835 /// // 1 * 8388608 * 2^(-22) == 2
1836 /// let abs_difference = (sign_f * mantissa_f * exponent_f - num).abs();
1838 /// assert!(abs_difference < 1e-10);
1840 fn integer_decode(self) -> (u64, i16, i8); in integer_decode()
1846 /// equal to `-self`. If `self` is a `NAN`, then a `NAN` with the sign of
1849 /// # Examples
1857 /// assert_eq!(f.copysign(-0.42), -3.5_f32);
1858 /// assert_eq!((-f).copysign(0.42), 3.5_f32);
1859 /// assert_eq!((-f).copysign(-0.42), -3.5_f32);
1863 fn copysign(self, sign: Self) -> Self { in copysign()
1877 nan() -> $T::NAN;
1878 infinity() -> $T::INFINITY;
1879 neg_infinity() -> $T::NEG_INFINITY;
1880 neg_zero() -> -0.0;
1881 min_value() -> $T::MIN;
1882 min_positive_value() -> $T::MIN_POSITIVE;
1883 epsilon() -> $T::EPSILON;
1884 max_value() -> $T::MAX;
1889 fn abs_sub(self, other: Self) -> Self {
1894 fn integer_decode(self) -> (u64, i16, i8) {
1899 Self::is_nan(self) -> bool;
1900 Self::is_infinite(self) -> bool;
1901 Self::is_finite(self) -> bool;
1902 Self::is_normal(self) -> bool;
1903 Self::classify(self) -> FpCategory;
1904 Self::floor(self) -> Self;
1905 Self::ceil(self) -> Self;
1906 Self::round(self) -> Self;
1907 Self::trunc(self) -> Self;
1908 Self::fract(self) -> Self;
1909 Self::abs(self) -> Self;
1910 Self::signum(self) -> Self;
1911 Self::is_sign_positive(self) -> bool;
1912 Self::is_sign_negative(self) -> bool;
1913 Self::mul_add(self, a: Self, b: Self) -> Self;
1914 Self::recip(self) -> Self;
1915 Self::powi(self, n: i32) -> Self;
1916 Self::powf(self, n: Self) -> Self;
1917 Self::sqrt(self) -> Self;
1918 Self::exp(self) -> Self;
1919 Self::exp2(self) -> Self;
1920 Self::ln(self) -> Self;
1921 Self::log(self, base: Self) -> Self;
1922 Self::log2(self) -> Self;
1923 Self::log10(self) -> Self;
1924 Self::to_degrees(self) -> Self;
1925 Self::to_radians(self) -> Self;
1926 Self::max(self, other: Self) -> Self;
1927 Self::min(self, other: Self) -> Self;
1928 Self::cbrt(self) -> Self;
1929 Self::hypot(self, other: Self) -> Self;
1930 Self::sin(self) -> Self;
1931 Self::cos(self) -> Self;
1932 Self::tan(self) -> Self;
1933 Self::asin(self) -> Self;
1934 Self::acos(self) -> Self;
1935 Self::atan(self) -> Self;
1936 Self::atan2(self, other: Self) -> Self;
1937 Self::sin_cos(self) -> (Self, Self);
1938 Self::exp_m1(self) -> Self;
1939 Self::ln_1p(self) -> Self;
1940 Self::sinh(self) -> Self;
1941 Self::cosh(self) -> Self;
1942 Self::tanh(self) -> Self;
1943 Self::asinh(self) -> Self;
1944 Self::acosh(self) -> Self;
1945 Self::atanh(self) -> Self;
1950 Self::copysign(self, sign: Self) -> Self;
1955 Self::is_subnormal(self) -> bool;
1965 nan() -> $T::NAN;
1966 infinity() -> $T::INFINITY;
1967 neg_infinity() -> $T::NEG_INFINITY;
1968 neg_zero() -> -0.0;
1969 min_value() -> $T::MIN;
1970 min_positive_value() -> $T::MIN_POSITIVE;
1971 epsilon() -> $T::EPSILON;
1972 max_value() -> $T::MAX;
1976 fn integer_decode(self) -> (u64, i16, i8) {
1981 fn fract(self) -> Self {
1982 self - Float::trunc(self)
1986 fn log(self, base: Self) -> Self {
1991 Self::is_nan(self) -> bool;
1992 Self::is_infinite(self) -> bool;
1993 Self::is_finite(self) -> bool;
1994 Self::is_normal(self) -> bool;
1995 Self::classify(self) -> FpCategory;
1996 Self::is_sign_positive(self) -> bool;
1997 Self::is_sign_negative(self) -> bool;
1998 Self::min(self, other: Self) -> Self;
1999 Self::max(self, other: Self) -> Self;
2000 Self::recip(self) -> Self;
2001 Self::to_degrees(self) -> Self;
2002 Self::to_radians(self) -> Self;
2007 Self::is_subnormal(self) -> bool;
2011 FloatCore::signum(self) -> Self;
2012 FloatCore::powi(self, n: i32) -> Self;
2017 fn integer_decode_f32(f: f32) -> (u64, i16, i8) { in integer_decode_f32()
2019 let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 }; in integer_decode_f32()
2027 exponent -= 127 + 23; in integer_decode_f32()
2031 fn integer_decode_f64(f: f64) -> (u64, i16, i8) { in integer_decode_f64()
2033 let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 }; in integer_decode_f64()
2041 exponent -= 1023 + 52; in integer_decode_f64()
2056 fn abs_sub(self, other: Self) -> Self { in abs_sub()
2061 libm::floorf as floor(self) -> Self;
2062 libm::ceilf as ceil(self) -> Self;
2063 libm::roundf as round(self) -> Self;
2064 libm::truncf as trunc(self) -> Self;
2065 libm::fabsf as abs(self) -> Self;
2066 libm::fmaf as mul_add(self, a: Self, b: Self) -> Self;
2067 libm::powf as powf(self, n: Self) -> Self;
2068 libm::sqrtf as sqrt(self) -> Self;
2069 libm::expf as exp(self) -> Self;
2070 libm::exp2f as exp2(self) -> Self;
2071 libm::logf as ln(self) -> Self;
2072 libm::log2f as log2(self) -> Self;
2073 libm::log10f as log10(self) -> Self;
2074 libm::cbrtf as cbrt(self) -> Self;
2075 libm::hypotf as hypot(self, other: Self) -> Self;
2076 libm::sinf as sin(self) -> Self;
2077 libm::cosf as cos(self) -> Self;
2078 libm::tanf as tan(self) -> Self;
2079 libm::asinf as asin(self) -> Self;
2080 libm::acosf as acos(self) -> Self;
2081 libm::atanf as atan(self) -> Self;
2082 libm::atan2f as atan2(self, other: Self) -> Self;
2083 libm::sincosf as sin_cos(self) -> (Self, Self);
2084 libm::expm1f as exp_m1(self) -> Self;
2085 libm::log1pf as ln_1p(self) -> Self;
2086 libm::sinhf as sinh(self) -> Self;
2087 libm::coshf as cosh(self) -> Self;
2088 libm::tanhf as tanh(self) -> Self;
2089 libm::asinhf as asinh(self) -> Self;
2090 libm::acoshf as acosh(self) -> Self;
2091 libm::atanhf as atanh(self) -> Self;
2092 libm::copysignf as copysign(self, other: Self) -> Self;
2102 fn abs_sub(self, other: Self) -> Self { in abs_sub()
2107 libm::floor as floor(self) -> Self;
2108 libm::ceil as ceil(self) -> Self;
2109 libm::round as round(self) -> Self;
2110 libm::trunc as trunc(self) -> Self;
2111 libm::fabs as abs(self) -> Self;
2112 libm::fma as mul_add(self, a: Self, b: Self) -> Self;
2113 libm::pow as powf(self, n: Self) -> Self;
2114 libm::sqrt as sqrt(self) -> Self;
2115 libm::exp as exp(self) -> Self;
2116 libm::exp2 as exp2(self) -> Self;
2117 libm::log as ln(self) -> Self;
2118 libm::log2 as log2(self) -> Self;
2119 libm::log10 as log10(self) -> Self;
2120 libm::cbrt as cbrt(self) -> Self;
2121 libm::hypot as hypot(self, other: Self) -> Self;
2122 libm::sin as sin(self) -> Self;
2123 libm::cos as cos(self) -> Self;
2124 libm::tan as tan(self) -> Self;
2125 libm::asin as asin(self) -> Self;
2126 libm::acos as acos(self) -> Self;
2127 libm::atan as atan(self) -> Self;
2128 libm::atan2 as atan2(self, other: Self) -> Self;
2129 libm::sincos as sin_cos(self) -> (Self, Self);
2130 libm::expm1 as exp_m1(self) -> Self;
2131 libm::log1p as ln_1p(self) -> Self;
2132 libm::sinh as sinh(self) -> Self;
2133 libm::cosh as cosh(self) -> Self;
2134 libm::tanh as tanh(self) -> Self;
2135 libm::asinh as asinh(self) -> Self;
2136 libm::acosh as acosh(self) -> Self;
2137 libm::atanh as atanh(self) -> Self;
2138 libm::copysign as copysign(self, sign: Self) -> Self;
2146 $(#[$doc] fn $constant() -> Self;)+
2149 fn TAU() -> Self where Self: Sized + Add<Self, Output = Self> {
2154 fn LOG10_2() -> Self where Self: Sized + Div<Self, Output = Self> {
2159 fn LOG2_10() -> Self where Self: Sized + Div<Self, Output = Self> {
2169 $( $constant() -> $T::consts::$constant; )+
2170 TAU() -> 6.28318530717958647692528676655900577;
2171 LOG10_2() -> 0.301029995663981195213738894724493027;
2172 LOG2_10() -> 3.32192809488736234787031942948939018;
2232 assert!((FloatCore::to_degrees(rad) - deg).abs() < 1e-6); in convert_deg_rad()
2233 assert!((FloatCore::to_radians(deg) - rad).abs() < 1e-6); in convert_deg_rad()
2236 assert!((FloatCore::to_degrees(rad) - deg).abs() < 1e-5); in convert_deg_rad()
2237 assert!((FloatCore::to_radians(deg) - rad).abs() < 1e-5); in convert_deg_rad()
2247 assert!((Float::to_degrees(rad) - deg).abs() < 1e-6); in convert_deg_rad_std()
2248 assert!((Float::to_radians(deg) - rad).abs() < 1e-6); in convert_deg_rad_std()
2251 assert!((Float::to_degrees(rad) - deg).abs() < 1e-5); in convert_deg_rad_std()
2252 assert!((Float::to_radians(deg) - rad).abs() < 1e-5); in convert_deg_rad_std()
2271 fn check<F: Float + FloatConst>(diff: F) { in extra_logs() function
2273 assert!((F::LOG10_2() - F::log10(_2)).abs() < diff); in extra_logs()
2274 assert!((F::LOG10_2() - F::LN_2() / F::LN_10()).abs() < diff); in extra_logs()
2277 assert!((F::LOG2_10() - F::log2(_10)).abs() < diff); in extra_logs()
2278 assert!((F::LOG2_10() - F::LN_10() / F::LN_2()).abs() < diff); in extra_logs()
2281 check::<f32>(1e-6); in extra_logs()
2282 check::<f64>(1e-12); in extra_logs()
2289 test_copysign_generic(2.0_f32, -2.0_f32, f32::nan()); in copysign()
2290 test_copysign_generic(2.0_f64, -2.0_f64, f64::nan()); in copysign()
2291 test_copysignf(2.0_f32, -2.0_f32, f32::nan()); in copysign()