std/
f128.rs

1//! Constants for the `f128` quadruple-precision floating point type.
2//!
3//! *[See also the `f128` primitive type](primitive@f128).*
4//!
5//! Mathematically significant numbers are provided in the `consts` sub-module.
6
7#[unstable(feature = "f128", issue = "116909")]
8pub use core::f128::consts;
9
10#[cfg(not(test))]
11use crate::intrinsics;
12#[cfg(not(test))]
13use crate::sys::cmath;
14
15#[cfg(not(test))]
16impl f128 {
17    /// Returns the largest integer less than or equal to `self`.
18    ///
19    /// This function always returns the precise result.
20    ///
21    /// # Examples
22    ///
23    /// ```
24    /// #![feature(f128)]
25    /// # #[cfg(reliable_f128_math)] {
26    ///
27    /// let f = 3.7_f128;
28    /// let g = 3.0_f128;
29    /// let h = -3.7_f128;
30    ///
31    /// assert_eq!(f.floor(), 3.0);
32    /// assert_eq!(g.floor(), 3.0);
33    /// assert_eq!(h.floor(), -4.0);
34    /// # }
35    /// ```
36    #[inline]
37    #[rustc_allow_incoherent_impl]
38    #[unstable(feature = "f128", issue = "116909")]
39    #[must_use = "method returns a new number and does not mutate the original value"]
40    pub fn floor(self) -> f128 {
41        unsafe { intrinsics::floorf128(self) }
42    }
43
44    /// Returns the smallest integer greater than or equal to `self`.
45    ///
46    /// This function always returns the precise result.
47    ///
48    /// # Examples
49    ///
50    /// ```
51    /// #![feature(f128)]
52    /// # #[cfg(reliable_f128_math)] {
53    ///
54    /// let f = 3.01_f128;
55    /// let g = 4.0_f128;
56    ///
57    /// assert_eq!(f.ceil(), 4.0);
58    /// assert_eq!(g.ceil(), 4.0);
59    /// # }
60    /// ```
61    #[inline]
62    #[doc(alias = "ceiling")]
63    #[rustc_allow_incoherent_impl]
64    #[unstable(feature = "f128", issue = "116909")]
65    #[must_use = "method returns a new number and does not mutate the original value"]
66    pub fn ceil(self) -> f128 {
67        unsafe { intrinsics::ceilf128(self) }
68    }
69
70    /// Returns the nearest integer to `self`. If a value is half-way between two
71    /// integers, round away from `0.0`.
72    ///
73    /// This function always returns the precise result.
74    ///
75    /// # Examples
76    ///
77    /// ```
78    /// #![feature(f128)]
79    /// # #[cfg(reliable_f128_math)] {
80    ///
81    /// let f = 3.3_f128;
82    /// let g = -3.3_f128;
83    /// let h = -3.7_f128;
84    /// let i = 3.5_f128;
85    /// let j = 4.5_f128;
86    ///
87    /// assert_eq!(f.round(), 3.0);
88    /// assert_eq!(g.round(), -3.0);
89    /// assert_eq!(h.round(), -4.0);
90    /// assert_eq!(i.round(), 4.0);
91    /// assert_eq!(j.round(), 5.0);
92    /// # }
93    /// ```
94    #[inline]
95    #[rustc_allow_incoherent_impl]
96    #[unstable(feature = "f128", issue = "116909")]
97    #[must_use = "method returns a new number and does not mutate the original value"]
98    pub fn round(self) -> f128 {
99        unsafe { intrinsics::roundf128(self) }
100    }
101
102    /// Returns the nearest integer to a number. Rounds half-way cases to the number
103    /// with an even least significant digit.
104    ///
105    /// This function always returns the precise result.
106    ///
107    /// # Examples
108    ///
109    /// ```
110    /// #![feature(f128)]
111    /// # #[cfg(reliable_f128_math)] {
112    ///
113    /// let f = 3.3_f128;
114    /// let g = -3.3_f128;
115    /// let h = 3.5_f128;
116    /// let i = 4.5_f128;
117    ///
118    /// assert_eq!(f.round_ties_even(), 3.0);
119    /// assert_eq!(g.round_ties_even(), -3.0);
120    /// assert_eq!(h.round_ties_even(), 4.0);
121    /// assert_eq!(i.round_ties_even(), 4.0);
122    /// # }
123    /// ```
124    #[inline]
125    #[rustc_allow_incoherent_impl]
126    #[unstable(feature = "f128", issue = "116909")]
127    #[must_use = "method returns a new number and does not mutate the original value"]
128    pub fn round_ties_even(self) -> f128 {
129        intrinsics::round_ties_even_f128(self)
130    }
131
132    /// Returns the integer part of `self`.
133    /// This means that non-integer numbers are always truncated towards zero.
134    ///
135    /// This function always returns the precise result.
136    ///
137    /// # Examples
138    ///
139    /// ```
140    /// #![feature(f128)]
141    /// # #[cfg(reliable_f128_math)] {
142    ///
143    /// let f = 3.7_f128;
144    /// let g = 3.0_f128;
145    /// let h = -3.7_f128;
146    ///
147    /// assert_eq!(f.trunc(), 3.0);
148    /// assert_eq!(g.trunc(), 3.0);
149    /// assert_eq!(h.trunc(), -3.0);
150    /// # }
151    /// ```
152    #[inline]
153    #[doc(alias = "truncate")]
154    #[rustc_allow_incoherent_impl]
155    #[unstable(feature = "f128", issue = "116909")]
156    #[must_use = "method returns a new number and does not mutate the original value"]
157    pub fn trunc(self) -> f128 {
158        unsafe { intrinsics::truncf128(self) }
159    }
160
161    /// Returns the fractional part of `self`.
162    ///
163    /// This function always returns the precise result.
164    ///
165    /// # Examples
166    ///
167    /// ```
168    /// #![feature(f128)]
169    /// # #[cfg(reliable_f128_math)] {
170    ///
171    /// let x = 3.6_f128;
172    /// let y = -3.6_f128;
173    /// let abs_difference_x = (x.fract() - 0.6).abs();
174    /// let abs_difference_y = (y.fract() - (-0.6)).abs();
175    ///
176    /// assert!(abs_difference_x <= f128::EPSILON);
177    /// assert!(abs_difference_y <= f128::EPSILON);
178    /// # }
179    /// ```
180    #[inline]
181    #[rustc_allow_incoherent_impl]
182    #[unstable(feature = "f128", issue = "116909")]
183    #[must_use = "method returns a new number and does not mutate the original value"]
184    pub fn fract(self) -> f128 {
185        self - self.trunc()
186    }
187
188    /// Fused multiply-add. Computes `(self * a) + b` with only one rounding
189    /// error, yielding a more accurate result than an unfused multiply-add.
190    ///
191    /// Using `mul_add` *may* be more performant than an unfused multiply-add if
192    /// the target architecture has a dedicated `fma` CPU instruction. However,
193    /// this is not always true, and will be heavily dependant on designing
194    /// algorithms with specific target hardware in mind.
195    ///
196    /// # Precision
197    ///
198    /// The result of this operation is guaranteed to be the rounded
199    /// infinite-precision result. It is specified by IEEE 754 as
200    /// `fusedMultiplyAdd` and guaranteed not to change.
201    ///
202    /// # Examples
203    ///
204    /// ```
205    /// #![feature(f128)]
206    /// # #[cfg(reliable_f128_math)] {
207    ///
208    /// let m = 10.0_f128;
209    /// let x = 4.0_f128;
210    /// let b = 60.0_f128;
211    ///
212    /// assert_eq!(m.mul_add(x, b), 100.0);
213    /// assert_eq!(m * x + b, 100.0);
214    ///
215    /// let one_plus_eps = 1.0_f128 + f128::EPSILON;
216    /// let one_minus_eps = 1.0_f128 - f128::EPSILON;
217    /// let minus_one = -1.0_f128;
218    ///
219    /// // The exact result (1 + eps) * (1 - eps) = 1 - eps * eps.
220    /// assert_eq!(one_plus_eps.mul_add(one_minus_eps, minus_one), -f128::EPSILON * f128::EPSILON);
221    /// // Different rounding with the non-fused multiply and add.
222    /// assert_eq!(one_plus_eps * one_minus_eps + minus_one, 0.0);
223    /// # }
224    /// ```
225    #[inline]
226    #[rustc_allow_incoherent_impl]
227    #[doc(alias = "fmaf128", alias = "fusedMultiplyAdd")]
228    #[unstable(feature = "f128", issue = "116909")]
229    #[must_use = "method returns a new number and does not mutate the original value"]
230    pub fn mul_add(self, a: f128, b: f128) -> f128 {
231        unsafe { intrinsics::fmaf128(self, a, b) }
232    }
233
234    /// Calculates Euclidean division, the matching method for `rem_euclid`.
235    ///
236    /// This computes the integer `n` such that
237    /// `self = n * rhs + self.rem_euclid(rhs)`.
238    /// In other words, the result is `self / rhs` rounded to the integer `n`
239    /// such that `self >= n * rhs`.
240    ///
241    /// # Precision
242    ///
243    /// The result of this operation is guaranteed to be the rounded
244    /// infinite-precision result.
245    ///
246    /// # Examples
247    ///
248    /// ```
249    /// #![feature(f128)]
250    /// # #[cfg(reliable_f128_math)] {
251    ///
252    /// let a: f128 = 7.0;
253    /// let b = 4.0;
254    /// assert_eq!(a.div_euclid(b), 1.0); // 7.0 > 4.0 * 1.0
255    /// assert_eq!((-a).div_euclid(b), -2.0); // -7.0 >= 4.0 * -2.0
256    /// assert_eq!(a.div_euclid(-b), -1.0); // 7.0 >= -4.0 * -1.0
257    /// assert_eq!((-a).div_euclid(-b), 2.0); // -7.0 >= -4.0 * 2.0
258    /// # }
259    /// ```
260    #[inline]
261    #[rustc_allow_incoherent_impl]
262    #[unstable(feature = "f128", issue = "116909")]
263    #[must_use = "method returns a new number and does not mutate the original value"]
264    pub fn div_euclid(self, rhs: f128) -> f128 {
265        let q = (self / rhs).trunc();
266        if self % rhs < 0.0 {
267            return if rhs > 0.0 { q - 1.0 } else { q + 1.0 };
268        }
269        q
270    }
271
272    /// Calculates the least nonnegative remainder of `self (mod rhs)`.
273    ///
274    /// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
275    /// most cases. However, due to a floating point round-off error it can
276    /// result in `r == rhs.abs()`, violating the mathematical definition, if
277    /// `self` is much smaller than `rhs.abs()` in magnitude and `self < 0.0`.
278    /// This result is not an element of the function's codomain, but it is the
279    /// closest floating point number in the real numbers and thus fulfills the
280    /// property `self == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs)`
281    /// approximately.
282    ///
283    /// # Precision
284    ///
285    /// The result of this operation is guaranteed to be the rounded
286    /// infinite-precision result.
287    ///
288    /// # Examples
289    ///
290    /// ```
291    /// #![feature(f128)]
292    /// # #[cfg(reliable_f128_math)] {
293    ///
294    /// let a: f128 = 7.0;
295    /// let b = 4.0;
296    /// assert_eq!(a.rem_euclid(b), 3.0);
297    /// assert_eq!((-a).rem_euclid(b), 1.0);
298    /// assert_eq!(a.rem_euclid(-b), 3.0);
299    /// assert_eq!((-a).rem_euclid(-b), 1.0);
300    /// // limitation due to round-off error
301    /// assert!((-f128::EPSILON).rem_euclid(3.0) != 0.0);
302    /// # }
303    /// ```
304    #[inline]
305    #[rustc_allow_incoherent_impl]
306    #[doc(alias = "modulo", alias = "mod")]
307    #[unstable(feature = "f128", issue = "116909")]
308    #[must_use = "method returns a new number and does not mutate the original value"]
309    pub fn rem_euclid(self, rhs: f128) -> f128 {
310        let r = self % rhs;
311        if r < 0.0 { r + rhs.abs() } else { r }
312    }
313
314    /// Raises a number to an integer power.
315    ///
316    /// Using this function is generally faster than using `powf`.
317    /// It might have a different sequence of rounding operations than `powf`,
318    /// so the results are not guaranteed to agree.
319    ///
320    /// # Unspecified precision
321    ///
322    /// The precision of this function is non-deterministic. This means it varies by platform,
323    /// Rust version, and can even differ within the same execution from one invocation to the next.
324    ///
325    /// # Examples
326    ///
327    /// ```
328    /// #![feature(f128)]
329    /// # #[cfg(reliable_f128_math)] {
330    ///
331    /// let x = 2.0_f128;
332    /// let abs_difference = (x.powi(2) - (x * x)).abs();
333    /// assert!(abs_difference <= f128::EPSILON);
334    ///
335    /// assert_eq!(f128::powi(f128::NAN, 0), 1.0);
336    /// # }
337    /// ```
338    #[inline]
339    #[rustc_allow_incoherent_impl]
340    #[unstable(feature = "f128", issue = "116909")]
341    #[must_use = "method returns a new number and does not mutate the original value"]
342    pub fn powi(self, n: i32) -> f128 {
343        unsafe { intrinsics::powif128(self, n) }
344    }
345
346    /// Raises a number to a floating point power.
347    ///
348    /// # Unspecified precision
349    ///
350    /// The precision of this function is non-deterministic. This means it varies by platform,
351    /// Rust version, and can even differ within the same execution from one invocation to the next.
352    ///
353    /// # Examples
354    ///
355    /// ```
356    /// #![feature(f128)]
357    /// # #[cfg(reliable_f128_math)] {
358    ///
359    /// let x = 2.0_f128;
360    /// let abs_difference = (x.powf(2.0) - (x * x)).abs();
361    /// assert!(abs_difference <= f128::EPSILON);
362    ///
363    /// assert_eq!(f128::powf(1.0, f128::NAN), 1.0);
364    /// assert_eq!(f128::powf(f128::NAN, 0.0), 1.0);
365    /// # }
366    /// ```
367    #[inline]
368    #[rustc_allow_incoherent_impl]
369    #[unstable(feature = "f128", issue = "116909")]
370    #[must_use = "method returns a new number and does not mutate the original value"]
371    pub fn powf(self, n: f128) -> f128 {
372        unsafe { intrinsics::powf128(self, n) }
373    }
374
375    /// Returns the square root of a number.
376    ///
377    /// Returns NaN if `self` is a negative number other than `-0.0`.
378    ///
379    /// # Precision
380    ///
381    /// The result of this operation is guaranteed to be the rounded
382    /// infinite-precision result. It is specified by IEEE 754 as `squareRoot`
383    /// and guaranteed not to change.
384    ///
385    /// # Examples
386    ///
387    /// ```
388    /// #![feature(f128)]
389    /// # #[cfg(reliable_f128_math)] {
390    ///
391    /// let positive = 4.0_f128;
392    /// let negative = -4.0_f128;
393    /// let negative_zero = -0.0_f128;
394    ///
395    /// assert_eq!(positive.sqrt(), 2.0);
396    /// assert!(negative.sqrt().is_nan());
397    /// assert!(negative_zero.sqrt() == negative_zero);
398    /// # }
399    /// ```
400    #[inline]
401    #[doc(alias = "squareRoot")]
402    #[rustc_allow_incoherent_impl]
403    #[unstable(feature = "f128", issue = "116909")]
404    #[must_use = "method returns a new number and does not mutate the original value"]
405    pub fn sqrt(self) -> f128 {
406        unsafe { intrinsics::sqrtf128(self) }
407    }
408
409    /// Returns `e^(self)`, (the exponential function).
410    ///
411    /// # Unspecified precision
412    ///
413    /// The precision of this function is non-deterministic. This means it varies by platform,
414    /// Rust version, and can even differ within the same execution from one invocation to the next.
415    ///
416    /// # Examples
417    ///
418    /// ```
419    /// #![feature(f128)]
420    /// # #[cfg(reliable_f128_math)] {
421    ///
422    /// let one = 1.0f128;
423    /// // e^1
424    /// let e = one.exp();
425    ///
426    /// // ln(e) - 1 == 0
427    /// let abs_difference = (e.ln() - 1.0).abs();
428    ///
429    /// assert!(abs_difference <= f128::EPSILON);
430    /// # }
431    /// ```
432    #[inline]
433    #[rustc_allow_incoherent_impl]
434    #[unstable(feature = "f128", issue = "116909")]
435    #[must_use = "method returns a new number and does not mutate the original value"]
436    pub fn exp(self) -> f128 {
437        unsafe { intrinsics::expf128(self) }
438    }
439
440    /// Returns `2^(self)`.
441    ///
442    /// # Unspecified precision
443    ///
444    /// The precision of this function is non-deterministic. This means it varies by platform,
445    /// Rust version, and can even differ within the same execution from one invocation to the next.
446    ///
447    /// # Examples
448    ///
449    /// ```
450    /// #![feature(f128)]
451    /// # #[cfg(reliable_f128_math)] {
452    ///
453    /// let f = 2.0f128;
454    ///
455    /// // 2^2 - 4 == 0
456    /// let abs_difference = (f.exp2() - 4.0).abs();
457    ///
458    /// assert!(abs_difference <= f128::EPSILON);
459    /// # }
460    /// ```
461    #[inline]
462    #[rustc_allow_incoherent_impl]
463    #[unstable(feature = "f128", issue = "116909")]
464    #[must_use = "method returns a new number and does not mutate the original value"]
465    pub fn exp2(self) -> f128 {
466        unsafe { intrinsics::exp2f128(self) }
467    }
468
469    /// Returns the natural logarithm of the number.
470    ///
471    /// This returns NaN when the number is negative, and negative infinity when number is zero.
472    ///
473    /// # Unspecified precision
474    ///
475    /// The precision of this function is non-deterministic. This means it varies by platform,
476    /// Rust version, and can even differ within the same execution from one invocation to the next.
477    ///
478    /// # Examples
479    ///
480    /// ```
481    /// #![feature(f128)]
482    /// # #[cfg(reliable_f128_math)] {
483    ///
484    /// let one = 1.0f128;
485    /// // e^1
486    /// let e = one.exp();
487    ///
488    /// // ln(e) - 1 == 0
489    /// let abs_difference = (e.ln() - 1.0).abs();
490    ///
491    /// assert!(abs_difference <= f128::EPSILON);
492    /// # }
493    /// ```
494    ///
495    /// Non-positive values:
496    /// ```
497    /// #![feature(f128)]
498    /// # #[cfg(reliable_f128_math)] {
499    ///
500    /// assert_eq!(0_f128.ln(), f128::NEG_INFINITY);
501    /// assert!((-42_f128).ln().is_nan());
502    /// # }
503    /// ```
504    #[inline]
505    #[rustc_allow_incoherent_impl]
506    #[unstable(feature = "f128", issue = "116909")]
507    #[must_use = "method returns a new number and does not mutate the original value"]
508    pub fn ln(self) -> f128 {
509        unsafe { intrinsics::logf128(self) }
510    }
511
512    /// Returns the logarithm of the number with respect to an arbitrary base.
513    ///
514    /// This returns NaN when the number is negative, and negative infinity when number is zero.
515    ///
516    /// The result might not be correctly rounded owing to implementation details;
517    /// `self.log2()` can produce more accurate results for base 2, and
518    /// `self.log10()` can produce more accurate results for base 10.
519    ///
520    /// # Unspecified precision
521    ///
522    /// The precision of this function is non-deterministic. This means it varies by platform,
523    /// Rust version, and can even differ within the same execution from one invocation to the next.
524    ///
525    /// # Examples
526    ///
527    /// ```
528    /// #![feature(f128)]
529    /// # #[cfg(reliable_f128_math)] {
530    ///
531    /// let five = 5.0f128;
532    ///
533    /// // log5(5) - 1 == 0
534    /// let abs_difference = (five.log(5.0) - 1.0).abs();
535    ///
536    /// assert!(abs_difference <= f128::EPSILON);
537    /// # }
538    /// ```
539    ///
540    /// Non-positive values:
541    /// ```
542    /// #![feature(f128)]
543    /// # #[cfg(reliable_f128_math)] {
544    ///
545    /// assert_eq!(0_f128.log(10.0), f128::NEG_INFINITY);
546    /// assert!((-42_f128).log(10.0).is_nan());
547    /// # }
548    /// ```
549    #[inline]
550    #[rustc_allow_incoherent_impl]
551    #[unstable(feature = "f128", issue = "116909")]
552    #[must_use = "method returns a new number and does not mutate the original value"]
553    pub fn log(self, base: f128) -> f128 {
554        self.ln() / base.ln()
555    }
556
557    /// Returns the base 2 logarithm of the number.
558    ///
559    /// This returns NaN when the number is negative, and negative infinity when number is zero.
560    ///
561    /// # Unspecified precision
562    ///
563    /// The precision of this function is non-deterministic. This means it varies by platform,
564    /// Rust version, and can even differ within the same execution from one invocation to the next.
565    ///
566    /// # Examples
567    ///
568    /// ```
569    /// #![feature(f128)]
570    /// # #[cfg(reliable_f128_math)] {
571    ///
572    /// let two = 2.0f128;
573    ///
574    /// // log2(2) - 1 == 0
575    /// let abs_difference = (two.log2() - 1.0).abs();
576    ///
577    /// assert!(abs_difference <= f128::EPSILON);
578    /// # }
579    /// ```
580    ///
581    /// Non-positive values:
582    /// ```
583    /// #![feature(f128)]
584    /// # #[cfg(reliable_f128_math)] {
585    ///
586    /// assert_eq!(0_f128.log2(), f128::NEG_INFINITY);
587    /// assert!((-42_f128).log2().is_nan());
588    /// # }
589    /// ```
590    #[inline]
591    #[rustc_allow_incoherent_impl]
592    #[unstable(feature = "f128", issue = "116909")]
593    #[must_use = "method returns a new number and does not mutate the original value"]
594    pub fn log2(self) -> f128 {
595        unsafe { intrinsics::log2f128(self) }
596    }
597
598    /// Returns the base 10 logarithm of the number.
599    ///
600    /// This returns NaN when the number is negative, and negative infinity when number is zero.
601    ///
602    /// # Unspecified precision
603    ///
604    /// The precision of this function is non-deterministic. This means it varies by platform,
605    /// Rust version, and can even differ within the same execution from one invocation to the next.
606    ///
607    /// # Examples
608    ///
609    /// ```
610    /// #![feature(f128)]
611    /// # #[cfg(reliable_f128_math)] {
612    ///
613    /// let ten = 10.0f128;
614    ///
615    /// // log10(10) - 1 == 0
616    /// let abs_difference = (ten.log10() - 1.0).abs();
617    ///
618    /// assert!(abs_difference <= f128::EPSILON);
619    /// # }
620    /// ```
621    ///
622    /// Non-positive values:
623    /// ```
624    /// #![feature(f128)]
625    /// # #[cfg(reliable_f128_math)] {
626    ///
627    /// assert_eq!(0_f128.log10(), f128::NEG_INFINITY);
628    /// assert!((-42_f128).log10().is_nan());
629    /// # }
630    /// ```
631    #[inline]
632    #[rustc_allow_incoherent_impl]
633    #[unstable(feature = "f128", issue = "116909")]
634    #[must_use = "method returns a new number and does not mutate the original value"]
635    pub fn log10(self) -> f128 {
636        unsafe { intrinsics::log10f128(self) }
637    }
638
639    /// Returns the cube root of a number.
640    ///
641    /// # Unspecified precision
642    ///
643    /// The precision of this function is non-deterministic. This means it varies by platform,
644    /// Rust version, and can even differ within the same execution from one invocation to the next.
645    ///
646    ///
647    /// This function currently corresponds to the `cbrtf128` from libc on Unix
648    /// and Windows. Note that this might change in the future.
649    ///
650    /// # Examples
651    ///
652    /// ```
653    /// #![feature(f128)]
654    /// # #[cfg(reliable_f128_math)] {
655    ///
656    /// let x = 8.0f128;
657    ///
658    /// // x^(1/3) - 2 == 0
659    /// let abs_difference = (x.cbrt() - 2.0).abs();
660    ///
661    /// assert!(abs_difference <= f128::EPSILON);
662    /// # }
663    /// ```
664    #[inline]
665    #[rustc_allow_incoherent_impl]
666    #[unstable(feature = "f128", issue = "116909")]
667    #[must_use = "method returns a new number and does not mutate the original value"]
668    pub fn cbrt(self) -> f128 {
669        unsafe { cmath::cbrtf128(self) }
670    }
671
672    /// Compute the distance between the origin and a point (`x`, `y`) on the
673    /// Euclidean plane. Equivalently, compute the length of the hypotenuse of a
674    /// right-angle triangle with other sides having length `x.abs()` and
675    /// `y.abs()`.
676    ///
677    /// # Unspecified precision
678    ///
679    /// The precision of this function is non-deterministic. This means it varies by platform,
680    /// Rust version, and can even differ within the same execution from one invocation to the next.
681    ///
682    ///
683    /// This function currently corresponds to the `hypotf128` from libc on Unix
684    /// and Windows. Note that this might change in the future.
685    ///
686    /// # Examples
687    ///
688    /// ```
689    /// #![feature(f128)]
690    /// # #[cfg(reliable_f128_math)] {
691    ///
692    /// let x = 2.0f128;
693    /// let y = 3.0f128;
694    ///
695    /// // sqrt(x^2 + y^2)
696    /// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();
697    ///
698    /// assert!(abs_difference <= f128::EPSILON);
699    /// # }
700    /// ```
701    #[inline]
702    #[rustc_allow_incoherent_impl]
703    #[unstable(feature = "f128", issue = "116909")]
704    #[must_use = "method returns a new number and does not mutate the original value"]
705    pub fn hypot(self, other: f128) -> f128 {
706        unsafe { cmath::hypotf128(self, other) }
707    }
708
709    /// Computes the sine of a number (in radians).
710    ///
711    /// # Unspecified precision
712    ///
713    /// The precision of this function is non-deterministic. This means it varies by platform,
714    /// Rust version, and can even differ within the same execution from one invocation to the next.
715    ///
716    /// # Examples
717    ///
718    /// ```
719    /// #![feature(f128)]
720    /// # #[cfg(reliable_f128_math)] {
721    ///
722    /// let x = std::f128::consts::FRAC_PI_2;
723    ///
724    /// let abs_difference = (x.sin() - 1.0).abs();
725    ///
726    /// assert!(abs_difference <= f128::EPSILON);
727    /// # }
728    /// ```
729    #[inline]
730    #[rustc_allow_incoherent_impl]
731    #[unstable(feature = "f128", issue = "116909")]
732    #[must_use = "method returns a new number and does not mutate the original value"]
733    pub fn sin(self) -> f128 {
734        unsafe { intrinsics::sinf128(self) }
735    }
736
737    /// Computes the cosine of a number (in radians).
738    ///
739    /// # Unspecified precision
740    ///
741    /// The precision of this function is non-deterministic. This means it varies by platform,
742    /// Rust version, and can even differ within the same execution from one invocation to the next.
743    ///
744    /// # Examples
745    ///
746    /// ```
747    /// #![feature(f128)]
748    /// # #[cfg(reliable_f128_math)] {
749    ///
750    /// let x = 2.0 * std::f128::consts::PI;
751    ///
752    /// let abs_difference = (x.cos() - 1.0).abs();
753    ///
754    /// assert!(abs_difference <= f128::EPSILON);
755    /// # }
756    /// ```
757    #[inline]
758    #[rustc_allow_incoherent_impl]
759    #[unstable(feature = "f128", issue = "116909")]
760    #[must_use = "method returns a new number and does not mutate the original value"]
761    pub fn cos(self) -> f128 {
762        unsafe { intrinsics::cosf128(self) }
763    }
764
765    /// Computes the tangent of a number (in radians).
766    ///
767    /// # Unspecified precision
768    ///
769    /// The precision of this function is non-deterministic. This means it varies by platform,
770    /// Rust version, and can even differ within the same execution from one invocation to the next.
771    ///
772    /// This function currently corresponds to the `tanf128` from libc on Unix and
773    /// Windows. Note that this might change in the future.
774    ///
775    /// # Examples
776    ///
777    /// ```
778    /// #![feature(f128)]
779    /// # #[cfg(reliable_f128_math)] {
780    ///
781    /// let x = std::f128::consts::FRAC_PI_4;
782    /// let abs_difference = (x.tan() - 1.0).abs();
783    ///
784    /// assert!(abs_difference <= f128::EPSILON);
785    /// # }
786    /// ```
787    #[inline]
788    #[rustc_allow_incoherent_impl]
789    #[unstable(feature = "f128", issue = "116909")]
790    #[must_use = "method returns a new number and does not mutate the original value"]
791    pub fn tan(self) -> f128 {
792        unsafe { cmath::tanf128(self) }
793    }
794
795    /// Computes the arcsine of a number. Return value is in radians in
796    /// the range [-pi/2, pi/2] or NaN if the number is outside the range
797    /// [-1, 1].
798    ///
799    /// # Unspecified precision
800    ///
801    /// The precision of this function is non-deterministic. This means it varies by platform,
802    /// Rust version, and can even differ within the same execution from one invocation to the next.
803    ///
804    /// This function currently corresponds to the `asinf128` from libc on Unix
805    /// and Windows. Note that this might change in the future.
806    ///
807    /// # Examples
808    ///
809    /// ```
810    /// #![feature(f128)]
811    /// # #[cfg(reliable_f128_math)] {
812    ///
813    /// let f = std::f128::consts::FRAC_PI_2;
814    ///
815    /// // asin(sin(pi/2))
816    /// let abs_difference = (f.sin().asin() - std::f128::consts::FRAC_PI_2).abs();
817    ///
818    /// assert!(abs_difference <= f128::EPSILON);
819    /// # }
820    /// ```
821    #[inline]
822    #[doc(alias = "arcsin")]
823    #[rustc_allow_incoherent_impl]
824    #[unstable(feature = "f128", issue = "116909")]
825    #[must_use = "method returns a new number and does not mutate the original value"]
826    pub fn asin(self) -> f128 {
827        unsafe { cmath::asinf128(self) }
828    }
829
830    /// Computes the arccosine of a number. Return value is in radians in
831    /// the range [0, pi] or NaN if the number is outside the range
832    /// [-1, 1].
833    ///
834    /// # Unspecified precision
835    ///
836    /// The precision of this function is non-deterministic. This means it varies by platform,
837    /// Rust version, and can even differ within the same execution from one invocation to the next.
838    ///
839    /// This function currently corresponds to the `acosf128` from libc on Unix
840    /// and Windows. Note that this might change in the future.
841    ///
842    /// # Examples
843    ///
844    /// ```
845    /// #![feature(f128)]
846    /// # #[cfg(reliable_f128_math)] {
847    ///
848    /// let f = std::f128::consts::FRAC_PI_4;
849    ///
850    /// // acos(cos(pi/4))
851    /// let abs_difference = (f.cos().acos() - std::f128::consts::FRAC_PI_4).abs();
852    ///
853    /// assert!(abs_difference <= f128::EPSILON);
854    /// # }
855    /// ```
856    #[inline]
857    #[doc(alias = "arccos")]
858    #[rustc_allow_incoherent_impl]
859    #[unstable(feature = "f128", issue = "116909")]
860    #[must_use = "method returns a new number and does not mutate the original value"]
861    pub fn acos(self) -> f128 {
862        unsafe { cmath::acosf128(self) }
863    }
864
865    /// Computes the arctangent of a number. Return value is in radians in the
866    /// range [-pi/2, pi/2];
867    ///
868    /// # Unspecified precision
869    ///
870    /// The precision of this function is non-deterministic. This means it varies by platform,
871    /// Rust version, and can even differ within the same execution from one invocation to the next.
872    ///
873    /// This function currently corresponds to the `atanf128` from libc on Unix
874    /// and Windows. Note that this might change in the future.
875    ///
876    /// # Examples
877    ///
878    /// ```
879    /// #![feature(f128)]
880    /// # #[cfg(reliable_f128_math)] {
881    ///
882    /// let f = 1.0f128;
883    ///
884    /// // atan(tan(1))
885    /// let abs_difference = (f.tan().atan() - 1.0).abs();
886    ///
887    /// assert!(abs_difference <= f128::EPSILON);
888    /// # }
889    /// ```
890    #[inline]
891    #[doc(alias = "arctan")]
892    #[rustc_allow_incoherent_impl]
893    #[unstable(feature = "f128", issue = "116909")]
894    #[must_use = "method returns a new number and does not mutate the original value"]
895    pub fn atan(self) -> f128 {
896        unsafe { cmath::atanf128(self) }
897    }
898
899    /// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
900    ///
901    /// * `x = 0`, `y = 0`: `0`
902    /// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]`
903    /// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
904    /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
905    ///
906    /// # Unspecified precision
907    ///
908    /// The precision of this function is non-deterministic. This means it varies by platform,
909    /// Rust version, and can even differ within the same execution from one invocation to the next.
910    ///
911    /// This function currently corresponds to the `atan2f128` from libc on Unix
912    /// and Windows. Note that this might change in the future.
913    ///
914    /// # Examples
915    ///
916    /// ```
917    /// #![feature(f128)]
918    /// # #[cfg(reliable_f128_math)] {
919    ///
920    /// // Positive angles measured counter-clockwise
921    /// // from positive x axis
922    /// // -pi/4 radians (45 deg clockwise)
923    /// let x1 = 3.0f128;
924    /// let y1 = -3.0f128;
925    ///
926    /// // 3pi/4 radians (135 deg counter-clockwise)
927    /// let x2 = -3.0f128;
928    /// let y2 = 3.0f128;
929    ///
930    /// let abs_difference_1 = (y1.atan2(x1) - (-std::f128::consts::FRAC_PI_4)).abs();
931    /// let abs_difference_2 = (y2.atan2(x2) - (3.0 * std::f128::consts::FRAC_PI_4)).abs();
932    ///
933    /// assert!(abs_difference_1 <= f128::EPSILON);
934    /// assert!(abs_difference_2 <= f128::EPSILON);
935    /// # }
936    /// ```
937    #[inline]
938    #[rustc_allow_incoherent_impl]
939    #[unstable(feature = "f128", issue = "116909")]
940    #[must_use = "method returns a new number and does not mutate the original value"]
941    pub fn atan2(self, other: f128) -> f128 {
942        unsafe { cmath::atan2f128(self, other) }
943    }
944
945    /// Simultaneously computes the sine and cosine of the number, `x`. Returns
946    /// `(sin(x), cos(x))`.
947    ///
948    /// # Unspecified precision
949    ///
950    /// The precision of this function is non-deterministic. This means it varies by platform,
951    /// Rust version, and can even differ within the same execution from one invocation to the next.
952    ///
953    /// This function currently corresponds to the `(f128::sin(x),
954    /// f128::cos(x))`. Note that this might change in the future.
955    ///
956    /// # Examples
957    ///
958    /// ```
959    /// #![feature(f128)]
960    /// # #[cfg(reliable_f128_math)] {
961    ///
962    /// let x = std::f128::consts::FRAC_PI_4;
963    /// let f = x.sin_cos();
964    ///
965    /// let abs_difference_0 = (f.0 - x.sin()).abs();
966    /// let abs_difference_1 = (f.1 - x.cos()).abs();
967    ///
968    /// assert!(abs_difference_0 <= f128::EPSILON);
969    /// assert!(abs_difference_1 <= f128::EPSILON);
970    /// # }
971    /// ```
972    #[inline]
973    #[doc(alias = "sincos")]
974    #[rustc_allow_incoherent_impl]
975    #[unstable(feature = "f128", issue = "116909")]
976    pub fn sin_cos(self) -> (f128, f128) {
977        (self.sin(), self.cos())
978    }
979
980    /// Returns `e^(self) - 1` in a way that is accurate even if the
981    /// number is close to zero.
982    ///
983    /// # Unspecified precision
984    ///
985    /// The precision of this function is non-deterministic. This means it varies by platform,
986    /// Rust version, and can even differ within the same execution from one invocation to the next.
987    ///
988    /// This function currently corresponds to the `expm1f128` from libc on Unix
989    /// and Windows. Note that this might change in the future.
990    ///
991    /// # Examples
992    ///
993    /// ```
994    /// #![feature(f128)]
995    /// # #[cfg(reliable_f128_math)] {
996    ///
997    /// let x = 1e-8_f128;
998    ///
999    /// // for very small x, e^x is approximately 1 + x + x^2 / 2
1000    /// let approx = x + x * x / 2.0;
1001    /// let abs_difference = (x.exp_m1() - approx).abs();
1002    ///
1003    /// assert!(abs_difference < 1e-10);
1004    /// # }
1005    /// ```
1006    #[inline]
1007    #[rustc_allow_incoherent_impl]
1008    #[unstable(feature = "f128", issue = "116909")]
1009    #[must_use = "method returns a new number and does not mutate the original value"]
1010    pub fn exp_m1(self) -> f128 {
1011        unsafe { cmath::expm1f128(self) }
1012    }
1013
1014    /// Returns `ln(1+n)` (natural logarithm) more accurately than if
1015    /// the operations were performed separately.
1016    ///
1017    /// This returns NaN when `n < -1.0`, and negative infinity when `n == -1.0`.
1018    ///
1019    /// # Unspecified precision
1020    ///
1021    /// The precision of this function is non-deterministic. This means it varies by platform,
1022    /// Rust version, and can even differ within the same execution from one invocation to the next.
1023    ///
1024    /// This function currently corresponds to the `log1pf128` from libc on Unix
1025    /// and Windows. Note that this might change in the future.
1026    ///
1027    /// # Examples
1028    ///
1029    /// ```
1030    /// #![feature(f128)]
1031    /// # #[cfg(reliable_f128_math)] {
1032    ///
1033    /// let x = 1e-8_f128;
1034    ///
1035    /// // for very small x, ln(1 + x) is approximately x - x^2 / 2
1036    /// let approx = x - x * x / 2.0;
1037    /// let abs_difference = (x.ln_1p() - approx).abs();
1038    ///
1039    /// assert!(abs_difference < 1e-10);
1040    /// # }
1041    /// ```
1042    ///
1043    /// Out-of-range values:
1044    /// ```
1045    /// #![feature(f128)]
1046    /// # #[cfg(reliable_f128_math)] {
1047    ///
1048    /// assert_eq!((-1.0_f128).ln_1p(), f128::NEG_INFINITY);
1049    /// assert!((-2.0_f128).ln_1p().is_nan());
1050    /// # }
1051    /// ```
1052    #[inline]
1053    #[doc(alias = "log1p")]
1054    #[must_use = "method returns a new number and does not mutate the original value"]
1055    #[rustc_allow_incoherent_impl]
1056    #[unstable(feature = "f128", issue = "116909")]
1057    pub fn ln_1p(self) -> f128 {
1058        unsafe { cmath::log1pf128(self) }
1059    }
1060
1061    /// Hyperbolic sine function.
1062    ///
1063    /// # Unspecified precision
1064    ///
1065    /// The precision of this function is non-deterministic. This means it varies by platform,
1066    /// Rust version, and can even differ within the same execution from one invocation to the next.
1067    ///
1068    /// This function currently corresponds to the `sinhf128` from libc on Unix
1069    /// and Windows. Note that this might change in the future.
1070    ///
1071    /// # Examples
1072    ///
1073    /// ```
1074    /// #![feature(f128)]
1075    /// # #[cfg(reliable_f128_math)] {
1076    ///
1077    /// let e = std::f128::consts::E;
1078    /// let x = 1.0f128;
1079    ///
1080    /// let f = x.sinh();
1081    /// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
1082    /// let g = ((e * e) - 1.0) / (2.0 * e);
1083    /// let abs_difference = (f - g).abs();
1084    ///
1085    /// assert!(abs_difference <= f128::EPSILON);
1086    /// # }
1087    /// ```
1088    #[inline]
1089    #[rustc_allow_incoherent_impl]
1090    #[unstable(feature = "f128", issue = "116909")]
1091    #[must_use = "method returns a new number and does not mutate the original value"]
1092    pub fn sinh(self) -> f128 {
1093        unsafe { cmath::sinhf128(self) }
1094    }
1095
1096    /// Hyperbolic cosine function.
1097    ///
1098    /// # Unspecified precision
1099    ///
1100    /// The precision of this function is non-deterministic. This means it varies by platform,
1101    /// Rust version, and can even differ within the same execution from one invocation to the next.
1102    ///
1103    /// This function currently corresponds to the `coshf128` from libc on Unix
1104    /// and Windows. Note that this might change in the future.
1105    ///
1106    /// # Examples
1107    ///
1108    /// ```
1109    /// #![feature(f128)]
1110    /// # #[cfg(reliable_f128_math)] {
1111    ///
1112    /// let e = std::f128::consts::E;
1113    /// let x = 1.0f128;
1114    /// let f = x.cosh();
1115    /// // Solving cosh() at 1 gives this result
1116    /// let g = ((e * e) + 1.0) / (2.0 * e);
1117    /// let abs_difference = (f - g).abs();
1118    ///
1119    /// // Same result
1120    /// assert!(abs_difference <= f128::EPSILON);
1121    /// # }
1122    /// ```
1123    #[inline]
1124    #[rustc_allow_incoherent_impl]
1125    #[unstable(feature = "f128", issue = "116909")]
1126    #[must_use = "method returns a new number and does not mutate the original value"]
1127    pub fn cosh(self) -> f128 {
1128        unsafe { cmath::coshf128(self) }
1129    }
1130
1131    /// Hyperbolic tangent function.
1132    ///
1133    /// # Unspecified precision
1134    ///
1135    /// The precision of this function is non-deterministic. This means it varies by platform,
1136    /// Rust version, and can even differ within the same execution from one invocation to the next.
1137    ///
1138    /// This function currently corresponds to the `tanhf128` from libc on Unix
1139    /// and Windows. Note that this might change in the future.
1140    ///
1141    /// # Examples
1142    ///
1143    /// ```
1144    /// #![feature(f128)]
1145    /// # #[cfg(reliable_f128_math)] {
1146    ///
1147    /// let e = std::f128::consts::E;
1148    /// let x = 1.0f128;
1149    ///
1150    /// let f = x.tanh();
1151    /// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
1152    /// let g = (1.0 - e.powi(-2)) / (1.0 + e.powi(-2));
1153    /// let abs_difference = (f - g).abs();
1154    ///
1155    /// assert!(abs_difference <= f128::EPSILON);
1156    /// # }
1157    /// ```
1158    #[inline]
1159    #[rustc_allow_incoherent_impl]
1160    #[unstable(feature = "f128", issue = "116909")]
1161    #[must_use = "method returns a new number and does not mutate the original value"]
1162    pub fn tanh(self) -> f128 {
1163        unsafe { cmath::tanhf128(self) }
1164    }
1165
1166    /// Inverse hyperbolic sine function.
1167    ///
1168    /// # Unspecified precision
1169    ///
1170    /// The precision of this function is non-deterministic. This means it varies by platform,
1171    /// Rust version, and can even differ within the same execution from one invocation to the next.
1172    ///
1173    /// # Examples
1174    ///
1175    /// ```
1176    /// #![feature(f128)]
1177    /// # #[cfg(reliable_f128_math)] {
1178    ///
1179    /// let x = 1.0f128;
1180    /// let f = x.sinh().asinh();
1181    ///
1182    /// let abs_difference = (f - x).abs();
1183    ///
1184    /// assert!(abs_difference <= f128::EPSILON);
1185    /// # }
1186    /// ```
1187    #[inline]
1188    #[doc(alias = "arcsinh")]
1189    #[rustc_allow_incoherent_impl]
1190    #[unstable(feature = "f128", issue = "116909")]
1191    #[must_use = "method returns a new number and does not mutate the original value"]
1192    pub fn asinh(self) -> f128 {
1193        let ax = self.abs();
1194        let ix = 1.0 / ax;
1195        (ax + (ax / (Self::hypot(1.0, ix) + ix))).ln_1p().copysign(self)
1196    }
1197
1198    /// Inverse hyperbolic cosine function.
1199    ///
1200    /// # Unspecified precision
1201    ///
1202    /// The precision of this function is non-deterministic. This means it varies by platform,
1203    /// Rust version, and can even differ within the same execution from one invocation to the next.
1204    ///
1205    /// # Examples
1206    ///
1207    /// ```
1208    /// #![feature(f128)]
1209    /// # #[cfg(reliable_f128_math)] {
1210    ///
1211    /// let x = 1.0f128;
1212    /// let f = x.cosh().acosh();
1213    ///
1214    /// let abs_difference = (f - x).abs();
1215    ///
1216    /// assert!(abs_difference <= f128::EPSILON);
1217    /// # }
1218    /// ```
1219    #[inline]
1220    #[doc(alias = "arccosh")]
1221    #[rustc_allow_incoherent_impl]
1222    #[unstable(feature = "f128", issue = "116909")]
1223    #[must_use = "method returns a new number and does not mutate the original value"]
1224    pub fn acosh(self) -> f128 {
1225        if self < 1.0 {
1226            Self::NAN
1227        } else {
1228            (self + ((self - 1.0).sqrt() * (self + 1.0).sqrt())).ln()
1229        }
1230    }
1231
1232    /// Inverse hyperbolic tangent function.
1233    ///
1234    /// # Unspecified precision
1235    ///
1236    /// The precision of this function is non-deterministic. This means it varies by platform,
1237    /// Rust version, and can even differ within the same execution from one invocation to the next.
1238    ///
1239    /// # Examples
1240    ///
1241    /// ```
1242    /// #![feature(f128)]
1243    /// # #[cfg(reliable_f128_math)] {
1244    ///
1245    /// let e = std::f128::consts::E;
1246    /// let f = e.tanh().atanh();
1247    ///
1248    /// let abs_difference = (f - e).abs();
1249    ///
1250    /// assert!(abs_difference <= 1e-5);
1251    /// # }
1252    /// ```
1253    #[inline]
1254    #[doc(alias = "arctanh")]
1255    #[rustc_allow_incoherent_impl]
1256    #[unstable(feature = "f128", issue = "116909")]
1257    #[must_use = "method returns a new number and does not mutate the original value"]
1258    pub fn atanh(self) -> f128 {
1259        0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
1260    }
1261
1262    /// Gamma function.
1263    ///
1264    /// # Unspecified precision
1265    ///
1266    /// The precision of this function is non-deterministic. This means it varies by platform,
1267    /// Rust version, and can even differ within the same execution from one invocation to the next.
1268    ///
1269    /// This function currently corresponds to the `tgammaf128` from libc on Unix
1270    /// and Windows. Note that this might change in the future.
1271    ///
1272    /// # Examples
1273    ///
1274    /// ```
1275    /// #![feature(f128)]
1276    /// #![feature(float_gamma)]
1277    /// # #[cfg(reliable_f128_math)] {
1278    ///
1279    /// let x = 5.0f128;
1280    ///
1281    /// let abs_difference = (x.gamma() - 24.0).abs();
1282    ///
1283    /// assert!(abs_difference <= f128::EPSILON);
1284    /// # }
1285    /// ```
1286    #[inline]
1287    #[rustc_allow_incoherent_impl]
1288    #[unstable(feature = "f128", issue = "116909")]
1289    // #[unstable(feature = "float_gamma", issue = "99842")]
1290    #[must_use = "method returns a new number and does not mutate the original value"]
1291    pub fn gamma(self) -> f128 {
1292        unsafe { cmath::tgammaf128(self) }
1293    }
1294
1295    /// Natural logarithm of the absolute value of the gamma function
1296    ///
1297    /// The integer part of the tuple indicates the sign of the gamma function.
1298    ///
1299    /// # Unspecified precision
1300    ///
1301    /// The precision of this function is non-deterministic. This means it varies by platform,
1302    /// Rust version, and can even differ within the same execution from one invocation to the next.
1303    ///
1304    /// This function currently corresponds to the `lgammaf128_r` from libc on Unix
1305    /// and Windows. Note that this might change in the future.
1306    ///
1307    /// # Examples
1308    ///
1309    /// ```
1310    /// #![feature(f128)]
1311    /// #![feature(float_gamma)]
1312    /// # #[cfg(reliable_f128_math)] {
1313    ///
1314    /// let x = 2.0f128;
1315    ///
1316    /// let abs_difference = (x.ln_gamma().0 - 0.0).abs();
1317    ///
1318    /// assert!(abs_difference <= f128::EPSILON);
1319    /// # }
1320    /// ```
1321    #[inline]
1322    #[rustc_allow_incoherent_impl]
1323    #[unstable(feature = "f128", issue = "116909")]
1324    // #[unstable(feature = "float_gamma", issue = "99842")]
1325    #[must_use = "method returns a new number and does not mutate the original value"]
1326    pub fn ln_gamma(self) -> (f128, i32) {
1327        let mut signgamp: i32 = 0;
1328        let x = unsafe { cmath::lgammaf128_r(self, &mut signgamp) };
1329        (x, signgamp)
1330    }
1331
1332    /// Error function.
1333    ///
1334    /// # Unspecified precision
1335    ///
1336    /// The precision of this function is non-deterministic. This means it varies by platform,
1337    /// Rust version, and can even differ within the same execution from one invocation to the next.
1338    ///
1339    /// This function currently corresponds to the `erff128` from libc on Unix
1340    /// and Windows. Note that this might change in the future.
1341    ///
1342    /// # Examples
1343    ///
1344    /// ```
1345    /// #![feature(f128)]
1346    /// #![feature(float_erf)]
1347    /// # #[cfg(reliable_f128_math)] {
1348    /// /// The error function relates what percent of a normal distribution lies
1349    /// /// within `x` standard deviations (scaled by `1/sqrt(2)`).
1350    /// fn within_standard_deviations(x: f128) -> f128 {
1351    ///     (x * std::f128::consts::FRAC_1_SQRT_2).erf() * 100.0
1352    /// }
1353    ///
1354    /// // 68% of a normal distribution is within one standard deviation
1355    /// assert!((within_standard_deviations(1.0) - 68.269).abs() < 0.01);
1356    /// // 95% of a normal distribution is within two standard deviations
1357    /// assert!((within_standard_deviations(2.0) - 95.450).abs() < 0.01);
1358    /// // 99.7% of a normal distribution is within three standard deviations
1359    /// assert!((within_standard_deviations(3.0) - 99.730).abs() < 0.01);
1360    /// # }
1361    /// ```
1362    #[rustc_allow_incoherent_impl]
1363    #[must_use = "method returns a new number and does not mutate the original value"]
1364    #[unstable(feature = "f128", issue = "116909")]
1365    // #[unstable(feature = "float_erf", issue = "136321")]
1366    #[inline]
1367    pub fn erf(self) -> f128 {
1368        unsafe { cmath::erff128(self) }
1369    }
1370
1371    /// Complementary error function.
1372    ///
1373    /// # Unspecified precision
1374    ///
1375    /// The precision of this function is non-deterministic. This means it varies by platform,
1376    /// Rust version, and can even differ within the same execution from one invocation to the next.
1377    ///
1378    /// This function currently corresponds to the `erfcf128` from libc on Unix
1379    /// and Windows. Note that this might change in the future.
1380    ///
1381    /// # Examples
1382    ///
1383    /// ```
1384    /// #![feature(f128)]
1385    /// #![feature(float_erf)]
1386    /// # #[cfg(reliable_f128_math)] {
1387    /// let x: f128 = 0.123;
1388    ///
1389    /// let one = x.erf() + x.erfc();
1390    /// let abs_difference = (one - 1.0).abs();
1391    ///
1392    /// assert!(abs_difference <= f128::EPSILON);
1393    /// # }
1394    /// ```
1395    #[rustc_allow_incoherent_impl]
1396    #[must_use = "method returns a new number and does not mutate the original value"]
1397    #[unstable(feature = "f128", issue = "116909")]
1398    // #[unstable(feature = "float_erf", issue = "136321")]
1399    #[inline]
1400    pub fn erfc(self) -> f128 {
1401        unsafe { cmath::erfcf128(self) }
1402    }
1403}