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 unsafe { intrinsics::rintf128(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 /// # Unspecified precision
472 ///
473 /// The precision of this function is non-deterministic. This means it varies by platform,
474 /// Rust version, and can even differ within the same execution from one invocation to the next.
475 ///
476 /// # Examples
477 ///
478 /// ```
479 /// #![feature(f128)]
480 /// # #[cfg(reliable_f128_math)] {
481 ///
482 /// let one = 1.0f128;
483 /// // e^1
484 /// let e = one.exp();
485 ///
486 /// // ln(e) - 1 == 0
487 /// let abs_difference = (e.ln() - 1.0).abs();
488 ///
489 /// assert!(abs_difference <= f128::EPSILON);
490 /// # }
491 /// ```
492 #[inline]
493 #[rustc_allow_incoherent_impl]
494 #[unstable(feature = "f128", issue = "116909")]
495 #[must_use = "method returns a new number and does not mutate the original value"]
496 pub fn ln(self) -> f128 {
497 unsafe { intrinsics::logf128(self) }
498 }
499
500 /// Returns the logarithm of the number with respect to an arbitrary base.
501 ///
502 /// The result might not be correctly rounded owing to implementation details;
503 /// `self.log2()` can produce more accurate results for base 2, and
504 /// `self.log10()` can produce more accurate results for base 10.
505 ///
506 /// # Unspecified precision
507 ///
508 /// The precision of this function is non-deterministic. This means it varies by platform,
509 /// Rust version, and can even differ within the same execution from one invocation to the next.
510 ///
511 /// # Examples
512 ///
513 /// ```
514 /// #![feature(f128)]
515 /// # #[cfg(reliable_f128_math)] {
516 ///
517 /// let five = 5.0f128;
518 ///
519 /// // log5(5) - 1 == 0
520 /// let abs_difference = (five.log(5.0) - 1.0).abs();
521 ///
522 /// assert!(abs_difference <= f128::EPSILON);
523 /// # }
524 /// ```
525 #[inline]
526 #[rustc_allow_incoherent_impl]
527 #[unstable(feature = "f128", issue = "116909")]
528 #[must_use = "method returns a new number and does not mutate the original value"]
529 pub fn log(self, base: f128) -> f128 {
530 self.ln() / base.ln()
531 }
532
533 /// Returns the base 2 logarithm of the number.
534 ///
535 /// # Unspecified precision
536 ///
537 /// The precision of this function is non-deterministic. This means it varies by platform,
538 /// Rust version, and can even differ within the same execution from one invocation to the next.
539 ///
540 /// # Examples
541 ///
542 /// ```
543 /// #![feature(f128)]
544 /// # #[cfg(reliable_f128_math)] {
545 ///
546 /// let two = 2.0f128;
547 ///
548 /// // log2(2) - 1 == 0
549 /// let abs_difference = (two.log2() - 1.0).abs();
550 ///
551 /// assert!(abs_difference <= f128::EPSILON);
552 /// # }
553 /// ```
554 #[inline]
555 #[rustc_allow_incoherent_impl]
556 #[unstable(feature = "f128", issue = "116909")]
557 #[must_use = "method returns a new number and does not mutate the original value"]
558 pub fn log2(self) -> f128 {
559 unsafe { intrinsics::log2f128(self) }
560 }
561
562 /// Returns the base 10 logarithm of the number.
563 ///
564 /// # Unspecified precision
565 ///
566 /// The precision of this function is non-deterministic. This means it varies by platform,
567 /// Rust version, and can even differ within the same execution from one invocation to the next.
568 ///
569 /// # Examples
570 ///
571 /// ```
572 /// #![feature(f128)]
573 /// # #[cfg(reliable_f128_math)] {
574 ///
575 /// let ten = 10.0f128;
576 ///
577 /// // log10(10) - 1 == 0
578 /// let abs_difference = (ten.log10() - 1.0).abs();
579 ///
580 /// assert!(abs_difference <= f128::EPSILON);
581 /// # }
582 /// ```
583 #[inline]
584 #[rustc_allow_incoherent_impl]
585 #[unstable(feature = "f128", issue = "116909")]
586 #[must_use = "method returns a new number and does not mutate the original value"]
587 pub fn log10(self) -> f128 {
588 unsafe { intrinsics::log10f128(self) }
589 }
590
591 /// Returns the cube root of a number.
592 ///
593 /// # Unspecified precision
594 ///
595 /// The precision of this function is non-deterministic. This means it varies by platform,
596 /// Rust version, and can even differ within the same execution from one invocation to the next.
597 ///
598 ///
599 /// This function currently corresponds to the `cbrtf128` from libc on Unix
600 /// and Windows. Note that this might change in the future.
601 ///
602 /// # Examples
603 ///
604 /// ```
605 /// #![feature(f128)]
606 /// # #[cfg(reliable_f128_math)] {
607 ///
608 /// let x = 8.0f128;
609 ///
610 /// // x^(1/3) - 2 == 0
611 /// let abs_difference = (x.cbrt() - 2.0).abs();
612 ///
613 /// assert!(abs_difference <= f128::EPSILON);
614 /// # }
615 /// ```
616 #[inline]
617 #[rustc_allow_incoherent_impl]
618 #[unstable(feature = "f128", issue = "116909")]
619 #[must_use = "method returns a new number and does not mutate the original value"]
620 pub fn cbrt(self) -> f128 {
621 unsafe { cmath::cbrtf128(self) }
622 }
623
624 /// Compute the distance between the origin and a point (`x`, `y`) on the
625 /// Euclidean plane. Equivalently, compute the length of the hypotenuse of a
626 /// right-angle triangle with other sides having length `x.abs()` and
627 /// `y.abs()`.
628 ///
629 /// # Unspecified precision
630 ///
631 /// The precision of this function is non-deterministic. This means it varies by platform,
632 /// Rust version, and can even differ within the same execution from one invocation to the next.
633 ///
634 ///
635 /// This function currently corresponds to the `hypotf128` from libc on Unix
636 /// and Windows. Note that this might change in the future.
637 ///
638 /// # Examples
639 ///
640 /// ```
641 /// #![feature(f128)]
642 /// # #[cfg(reliable_f128_math)] {
643 ///
644 /// let x = 2.0f128;
645 /// let y = 3.0f128;
646 ///
647 /// // sqrt(x^2 + y^2)
648 /// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();
649 ///
650 /// assert!(abs_difference <= f128::EPSILON);
651 /// # }
652 /// ```
653 #[inline]
654 #[rustc_allow_incoherent_impl]
655 #[unstable(feature = "f128", issue = "116909")]
656 #[must_use = "method returns a new number and does not mutate the original value"]
657 pub fn hypot(self, other: f128) -> f128 {
658 unsafe { cmath::hypotf128(self, other) }
659 }
660
661 /// Computes the sine of a number (in radians).
662 ///
663 /// # Unspecified precision
664 ///
665 /// The precision of this function is non-deterministic. This means it varies by platform,
666 /// Rust version, and can even differ within the same execution from one invocation to the next.
667 ///
668 /// # Examples
669 ///
670 /// ```
671 /// #![feature(f128)]
672 /// # #[cfg(reliable_f128_math)] {
673 ///
674 /// let x = std::f128::consts::FRAC_PI_2;
675 ///
676 /// let abs_difference = (x.sin() - 1.0).abs();
677 ///
678 /// assert!(abs_difference <= f128::EPSILON);
679 /// # }
680 /// ```
681 #[inline]
682 #[rustc_allow_incoherent_impl]
683 #[unstable(feature = "f128", issue = "116909")]
684 #[must_use = "method returns a new number and does not mutate the original value"]
685 pub fn sin(self) -> f128 {
686 unsafe { intrinsics::sinf128(self) }
687 }
688
689 /// Computes the cosine of a number (in radians).
690 ///
691 /// # Unspecified precision
692 ///
693 /// The precision of this function is non-deterministic. This means it varies by platform,
694 /// Rust version, and can even differ within the same execution from one invocation to the next.
695 ///
696 /// # Examples
697 ///
698 /// ```
699 /// #![feature(f128)]
700 /// # #[cfg(reliable_f128_math)] {
701 ///
702 /// let x = 2.0 * std::f128::consts::PI;
703 ///
704 /// let abs_difference = (x.cos() - 1.0).abs();
705 ///
706 /// assert!(abs_difference <= f128::EPSILON);
707 /// # }
708 /// ```
709 #[inline]
710 #[rustc_allow_incoherent_impl]
711 #[unstable(feature = "f128", issue = "116909")]
712 #[must_use = "method returns a new number and does not mutate the original value"]
713 pub fn cos(self) -> f128 {
714 unsafe { intrinsics::cosf128(self) }
715 }
716
717 /// Computes the tangent of a number (in radians).
718 ///
719 /// # Unspecified precision
720 ///
721 /// The precision of this function is non-deterministic. This means it varies by platform,
722 /// Rust version, and can even differ within the same execution from one invocation to the next.
723 ///
724 /// This function currently corresponds to the `tanf128` from libc on Unix and
725 /// Windows. Note that this might change in the future.
726 ///
727 /// # Examples
728 ///
729 /// ```
730 /// #![feature(f128)]
731 /// # #[cfg(reliable_f128_math)] {
732 ///
733 /// let x = std::f128::consts::FRAC_PI_4;
734 /// let abs_difference = (x.tan() - 1.0).abs();
735 ///
736 /// assert!(abs_difference <= f128::EPSILON);
737 /// # }
738 /// ```
739 #[inline]
740 #[rustc_allow_incoherent_impl]
741 #[unstable(feature = "f128", issue = "116909")]
742 #[must_use = "method returns a new number and does not mutate the original value"]
743 pub fn tan(self) -> f128 {
744 unsafe { cmath::tanf128(self) }
745 }
746
747 /// Computes the arcsine of a number. Return value is in radians in
748 /// the range [-pi/2, pi/2] or NaN if the number is outside the range
749 /// [-1, 1].
750 ///
751 /// # Unspecified precision
752 ///
753 /// The precision of this function is non-deterministic. This means it varies by platform,
754 /// Rust version, and can even differ within the same execution from one invocation to the next.
755 ///
756 /// This function currently corresponds to the `asinf128` from libc on Unix
757 /// and Windows. Note that this might change in the future.
758 ///
759 /// # Examples
760 ///
761 /// ```
762 /// #![feature(f128)]
763 /// # #[cfg(reliable_f128_math)] {
764 ///
765 /// let f = std::f128::consts::FRAC_PI_2;
766 ///
767 /// // asin(sin(pi/2))
768 /// let abs_difference = (f.sin().asin() - std::f128::consts::FRAC_PI_2).abs();
769 ///
770 /// assert!(abs_difference <= f128::EPSILON);
771 /// # }
772 /// ```
773 #[inline]
774 #[doc(alias = "arcsin")]
775 #[rustc_allow_incoherent_impl]
776 #[unstable(feature = "f128", issue = "116909")]
777 #[must_use = "method returns a new number and does not mutate the original value"]
778 pub fn asin(self) -> f128 {
779 unsafe { cmath::asinf128(self) }
780 }
781
782 /// Computes the arccosine of a number. Return value is in radians in
783 /// the range [0, pi] or NaN if the number is outside the range
784 /// [-1, 1].
785 ///
786 /// # Unspecified precision
787 ///
788 /// The precision of this function is non-deterministic. This means it varies by platform,
789 /// Rust version, and can even differ within the same execution from one invocation to the next.
790 ///
791 /// This function currently corresponds to the `acosf128` from libc on Unix
792 /// and Windows. Note that this might change in the future.
793 ///
794 /// # Examples
795 ///
796 /// ```
797 /// #![feature(f128)]
798 /// # #[cfg(reliable_f128_math)] {
799 ///
800 /// let f = std::f128::consts::FRAC_PI_4;
801 ///
802 /// // acos(cos(pi/4))
803 /// let abs_difference = (f.cos().acos() - std::f128::consts::FRAC_PI_4).abs();
804 ///
805 /// assert!(abs_difference <= f128::EPSILON);
806 /// # }
807 /// ```
808 #[inline]
809 #[doc(alias = "arccos")]
810 #[rustc_allow_incoherent_impl]
811 #[unstable(feature = "f128", issue = "116909")]
812 #[must_use = "method returns a new number and does not mutate the original value"]
813 pub fn acos(self) -> f128 {
814 unsafe { cmath::acosf128(self) }
815 }
816
817 /// Computes the arctangent of a number. Return value is in radians in the
818 /// range [-pi/2, pi/2];
819 ///
820 /// # Unspecified precision
821 ///
822 /// The precision of this function is non-deterministic. This means it varies by platform,
823 /// Rust version, and can even differ within the same execution from one invocation to the next.
824 ///
825 /// This function currently corresponds to the `atanf128` from libc on Unix
826 /// and Windows. Note that this might change in the future.
827 ///
828 /// # Examples
829 ///
830 /// ```
831 /// #![feature(f128)]
832 /// # #[cfg(reliable_f128_math)] {
833 ///
834 /// let f = 1.0f128;
835 ///
836 /// // atan(tan(1))
837 /// let abs_difference = (f.tan().atan() - 1.0).abs();
838 ///
839 /// assert!(abs_difference <= f128::EPSILON);
840 /// # }
841 /// ```
842 #[inline]
843 #[doc(alias = "arctan")]
844 #[rustc_allow_incoherent_impl]
845 #[unstable(feature = "f128", issue = "116909")]
846 #[must_use = "method returns a new number and does not mutate the original value"]
847 pub fn atan(self) -> f128 {
848 unsafe { cmath::atanf128(self) }
849 }
850
851 /// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
852 ///
853 /// * `x = 0`, `y = 0`: `0`
854 /// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]`
855 /// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
856 /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
857 ///
858 /// # Unspecified precision
859 ///
860 /// The precision of this function is non-deterministic. This means it varies by platform,
861 /// Rust version, and can even differ within the same execution from one invocation to the next.
862 ///
863 /// This function currently corresponds to the `atan2f128` from libc on Unix
864 /// and Windows. Note that this might change in the future.
865 ///
866 /// # Examples
867 ///
868 /// ```
869 /// #![feature(f128)]
870 /// # #[cfg(reliable_f128_math)] {
871 ///
872 /// // Positive angles measured counter-clockwise
873 /// // from positive x axis
874 /// // -pi/4 radians (45 deg clockwise)
875 /// let x1 = 3.0f128;
876 /// let y1 = -3.0f128;
877 ///
878 /// // 3pi/4 radians (135 deg counter-clockwise)
879 /// let x2 = -3.0f128;
880 /// let y2 = 3.0f128;
881 ///
882 /// let abs_difference_1 = (y1.atan2(x1) - (-std::f128::consts::FRAC_PI_4)).abs();
883 /// let abs_difference_2 = (y2.atan2(x2) - (3.0 * std::f128::consts::FRAC_PI_4)).abs();
884 ///
885 /// assert!(abs_difference_1 <= f128::EPSILON);
886 /// assert!(abs_difference_2 <= f128::EPSILON);
887 /// # }
888 /// ```
889 #[inline]
890 #[rustc_allow_incoherent_impl]
891 #[unstable(feature = "f128", issue = "116909")]
892 #[must_use = "method returns a new number and does not mutate the original value"]
893 pub fn atan2(self, other: f128) -> f128 {
894 unsafe { cmath::atan2f128(self, other) }
895 }
896
897 /// Simultaneously computes the sine and cosine of the number, `x`. Returns
898 /// `(sin(x), cos(x))`.
899 ///
900 /// # Unspecified precision
901 ///
902 /// The precision of this function is non-deterministic. This means it varies by platform,
903 /// Rust version, and can even differ within the same execution from one invocation to the next.
904 ///
905 /// This function currently corresponds to the `(f128::sin(x),
906 /// f128::cos(x))`. Note that this might change in the future.
907 ///
908 /// # Examples
909 ///
910 /// ```
911 /// #![feature(f128)]
912 /// # #[cfg(reliable_f128_math)] {
913 ///
914 /// let x = std::f128::consts::FRAC_PI_4;
915 /// let f = x.sin_cos();
916 ///
917 /// let abs_difference_0 = (f.0 - x.sin()).abs();
918 /// let abs_difference_1 = (f.1 - x.cos()).abs();
919 ///
920 /// assert!(abs_difference_0 <= f128::EPSILON);
921 /// assert!(abs_difference_1 <= f128::EPSILON);
922 /// # }
923 /// ```
924 #[inline]
925 #[doc(alias = "sincos")]
926 #[rustc_allow_incoherent_impl]
927 #[unstable(feature = "f128", issue = "116909")]
928 pub fn sin_cos(self) -> (f128, f128) {
929 (self.sin(), self.cos())
930 }
931
932 /// Returns `e^(self) - 1` in a way that is accurate even if the
933 /// number is close to zero.
934 ///
935 /// # Unspecified precision
936 ///
937 /// The precision of this function is non-deterministic. This means it varies by platform,
938 /// Rust version, and can even differ within the same execution from one invocation to the next.
939 ///
940 /// This function currently corresponds to the `expm1f128` from libc on Unix
941 /// and Windows. Note that this might change in the future.
942 ///
943 /// # Examples
944 ///
945 /// ```
946 /// #![feature(f128)]
947 /// # #[cfg(reliable_f128_math)] {
948 ///
949 /// let x = 1e-8_f128;
950 ///
951 /// // for very small x, e^x is approximately 1 + x + x^2 / 2
952 /// let approx = x + x * x / 2.0;
953 /// let abs_difference = (x.exp_m1() - approx).abs();
954 ///
955 /// assert!(abs_difference < 1e-10);
956 /// # }
957 /// ```
958 #[inline]
959 #[rustc_allow_incoherent_impl]
960 #[unstable(feature = "f128", issue = "116909")]
961 #[must_use = "method returns a new number and does not mutate the original value"]
962 pub fn exp_m1(self) -> f128 {
963 unsafe { cmath::expm1f128(self) }
964 }
965
966 /// Returns `ln(1+n)` (natural logarithm) more accurately than if
967 /// the operations were performed separately.
968 ///
969 /// # Unspecified precision
970 ///
971 /// The precision of this function is non-deterministic. This means it varies by platform,
972 /// Rust version, and can even differ within the same execution from one invocation to the next.
973 ///
974 /// This function currently corresponds to the `log1pf128` from libc on Unix
975 /// and Windows. Note that this might change in the future.
976 ///
977 /// # Examples
978 ///
979 /// ```
980 /// #![feature(f128)]
981 /// # #[cfg(reliable_f128_math)] {
982 ///
983 /// let x = 1e-8_f128;
984 ///
985 /// // for very small x, ln(1 + x) is approximately x - x^2 / 2
986 /// let approx = x - x * x / 2.0;
987 /// let abs_difference = (x.ln_1p() - approx).abs();
988 ///
989 /// assert!(abs_difference < 1e-10);
990 /// # }
991 /// ```
992 #[inline]
993 #[doc(alias = "log1p")]
994 #[must_use = "method returns a new number and does not mutate the original value"]
995 #[rustc_allow_incoherent_impl]
996 #[unstable(feature = "f128", issue = "116909")]
997 pub fn ln_1p(self) -> f128 {
998 unsafe { cmath::log1pf128(self) }
999 }
1000
1001 /// Hyperbolic sine function.
1002 ///
1003 /// # Unspecified precision
1004 ///
1005 /// The precision of this function is non-deterministic. This means it varies by platform,
1006 /// Rust version, and can even differ within the same execution from one invocation to the next.
1007 ///
1008 /// This function currently corresponds to the `sinhf128` from libc on Unix
1009 /// and Windows. Note that this might change in the future.
1010 ///
1011 /// # Examples
1012 ///
1013 /// ```
1014 /// #![feature(f128)]
1015 /// # #[cfg(reliable_f128_math)] {
1016 ///
1017 /// let e = std::f128::consts::E;
1018 /// let x = 1.0f128;
1019 ///
1020 /// let f = x.sinh();
1021 /// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
1022 /// let g = ((e * e) - 1.0) / (2.0 * e);
1023 /// let abs_difference = (f - g).abs();
1024 ///
1025 /// assert!(abs_difference <= f128::EPSILON);
1026 /// # }
1027 /// ```
1028 #[inline]
1029 #[rustc_allow_incoherent_impl]
1030 #[unstable(feature = "f128", issue = "116909")]
1031 #[must_use = "method returns a new number and does not mutate the original value"]
1032 pub fn sinh(self) -> f128 {
1033 unsafe { cmath::sinhf128(self) }
1034 }
1035
1036 /// Hyperbolic cosine function.
1037 ///
1038 /// # Unspecified precision
1039 ///
1040 /// The precision of this function is non-deterministic. This means it varies by platform,
1041 /// Rust version, and can even differ within the same execution from one invocation to the next.
1042 ///
1043 /// This function currently corresponds to the `coshf128` from libc on Unix
1044 /// and Windows. Note that this might change in the future.
1045 ///
1046 /// # Examples
1047 ///
1048 /// ```
1049 /// #![feature(f128)]
1050 /// # #[cfg(reliable_f128_math)] {
1051 ///
1052 /// let e = std::f128::consts::E;
1053 /// let x = 1.0f128;
1054 /// let f = x.cosh();
1055 /// // Solving cosh() at 1 gives this result
1056 /// let g = ((e * e) + 1.0) / (2.0 * e);
1057 /// let abs_difference = (f - g).abs();
1058 ///
1059 /// // Same result
1060 /// assert!(abs_difference <= f128::EPSILON);
1061 /// # }
1062 /// ```
1063 #[inline]
1064 #[rustc_allow_incoherent_impl]
1065 #[unstable(feature = "f128", issue = "116909")]
1066 #[must_use = "method returns a new number and does not mutate the original value"]
1067 pub fn cosh(self) -> f128 {
1068 unsafe { cmath::coshf128(self) }
1069 }
1070
1071 /// Hyperbolic tangent function.
1072 ///
1073 /// # Unspecified precision
1074 ///
1075 /// The precision of this function is non-deterministic. This means it varies by platform,
1076 /// Rust version, and can even differ within the same execution from one invocation to the next.
1077 ///
1078 /// This function currently corresponds to the `tanhf128` from libc on Unix
1079 /// and Windows. Note that this might change in the future.
1080 ///
1081 /// # Examples
1082 ///
1083 /// ```
1084 /// #![feature(f128)]
1085 /// # #[cfg(reliable_f128_math)] {
1086 ///
1087 /// let e = std::f128::consts::E;
1088 /// let x = 1.0f128;
1089 ///
1090 /// let f = x.tanh();
1091 /// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
1092 /// let g = (1.0 - e.powi(-2)) / (1.0 + e.powi(-2));
1093 /// let abs_difference = (f - g).abs();
1094 ///
1095 /// assert!(abs_difference <= f128::EPSILON);
1096 /// # }
1097 /// ```
1098 #[inline]
1099 #[rustc_allow_incoherent_impl]
1100 #[unstable(feature = "f128", issue = "116909")]
1101 #[must_use = "method returns a new number and does not mutate the original value"]
1102 pub fn tanh(self) -> f128 {
1103 unsafe { cmath::tanhf128(self) }
1104 }
1105
1106 /// Inverse hyperbolic sine function.
1107 ///
1108 /// # Unspecified precision
1109 ///
1110 /// The precision of this function is non-deterministic. This means it varies by platform,
1111 /// Rust version, and can even differ within the same execution from one invocation to the next.
1112 ///
1113 /// # Examples
1114 ///
1115 /// ```
1116 /// #![feature(f128)]
1117 /// # #[cfg(reliable_f128_math)] {
1118 ///
1119 /// let x = 1.0f128;
1120 /// let f = x.sinh().asinh();
1121 ///
1122 /// let abs_difference = (f - x).abs();
1123 ///
1124 /// assert!(abs_difference <= f128::EPSILON);
1125 /// # }
1126 /// ```
1127 #[inline]
1128 #[doc(alias = "arcsinh")]
1129 #[rustc_allow_incoherent_impl]
1130 #[unstable(feature = "f128", issue = "116909")]
1131 #[must_use = "method returns a new number and does not mutate the original value"]
1132 pub fn asinh(self) -> f128 {
1133 let ax = self.abs();
1134 let ix = 1.0 / ax;
1135 (ax + (ax / (Self::hypot(1.0, ix) + ix))).ln_1p().copysign(self)
1136 }
1137
1138 /// Inverse hyperbolic cosine function.
1139 ///
1140 /// # Unspecified precision
1141 ///
1142 /// The precision of this function is non-deterministic. This means it varies by platform,
1143 /// Rust version, and can even differ within the same execution from one invocation to the next.
1144 ///
1145 /// # Examples
1146 ///
1147 /// ```
1148 /// #![feature(f128)]
1149 /// # #[cfg(reliable_f128_math)] {
1150 ///
1151 /// let x = 1.0f128;
1152 /// let f = x.cosh().acosh();
1153 ///
1154 /// let abs_difference = (f - x).abs();
1155 ///
1156 /// assert!(abs_difference <= f128::EPSILON);
1157 /// # }
1158 /// ```
1159 #[inline]
1160 #[doc(alias = "arccosh")]
1161 #[rustc_allow_incoherent_impl]
1162 #[unstable(feature = "f128", issue = "116909")]
1163 #[must_use = "method returns a new number and does not mutate the original value"]
1164 pub fn acosh(self) -> f128 {
1165 if self < 1.0 {
1166 Self::NAN
1167 } else {
1168 (self + ((self - 1.0).sqrt() * (self + 1.0).sqrt())).ln()
1169 }
1170 }
1171
1172 /// Inverse hyperbolic tangent function.
1173 ///
1174 /// # Unspecified precision
1175 ///
1176 /// The precision of this function is non-deterministic. This means it varies by platform,
1177 /// Rust version, and can even differ within the same execution from one invocation to the next.
1178 ///
1179 /// # Examples
1180 ///
1181 /// ```
1182 /// #![feature(f128)]
1183 /// # #[cfg(reliable_f128_math)] {
1184 ///
1185 /// let e = std::f128::consts::E;
1186 /// let f = e.tanh().atanh();
1187 ///
1188 /// let abs_difference = (f - e).abs();
1189 ///
1190 /// assert!(abs_difference <= 1e-5);
1191 /// # }
1192 /// ```
1193 #[inline]
1194 #[doc(alias = "arctanh")]
1195 #[rustc_allow_incoherent_impl]
1196 #[unstable(feature = "f128", issue = "116909")]
1197 #[must_use = "method returns a new number and does not mutate the original value"]
1198 pub fn atanh(self) -> f128 {
1199 0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
1200 }
1201
1202 /// Gamma function.
1203 ///
1204 /// # Unspecified precision
1205 ///
1206 /// The precision of this function is non-deterministic. This means it varies by platform,
1207 /// Rust version, and can even differ within the same execution from one invocation to the next.
1208 ///
1209 /// This function currently corresponds to the `tgammaf128` from libc on Unix
1210 /// and Windows. Note that this might change in the future.
1211 ///
1212 /// # Examples
1213 ///
1214 /// ```
1215 /// #![feature(f128)]
1216 /// #![feature(float_gamma)]
1217 /// # #[cfg(reliable_f128_math)] {
1218 ///
1219 /// let x = 5.0f128;
1220 ///
1221 /// let abs_difference = (x.gamma() - 24.0).abs();
1222 ///
1223 /// assert!(abs_difference <= f128::EPSILON);
1224 /// # }
1225 /// ```
1226 #[inline]
1227 #[rustc_allow_incoherent_impl]
1228 #[unstable(feature = "f128", issue = "116909")]
1229 // #[unstable(feature = "float_gamma", issue = "99842")]
1230 #[must_use = "method returns a new number and does not mutate the original value"]
1231 pub fn gamma(self) -> f128 {
1232 unsafe { cmath::tgammaf128(self) }
1233 }
1234
1235 /// Natural logarithm of the absolute value of the gamma function
1236 ///
1237 /// The integer part of the tuple indicates the sign of the gamma function.
1238 ///
1239 /// # Unspecified precision
1240 ///
1241 /// The precision of this function is non-deterministic. This means it varies by platform,
1242 /// Rust version, and can even differ within the same execution from one invocation to the next.
1243 ///
1244 /// This function currently corresponds to the `lgammaf128_r` from libc on Unix
1245 /// and Windows. Note that this might change in the future.
1246 ///
1247 /// # Examples
1248 ///
1249 /// ```
1250 /// #![feature(f128)]
1251 /// #![feature(float_gamma)]
1252 /// # #[cfg(reliable_f128_math)] {
1253 ///
1254 /// let x = 2.0f128;
1255 ///
1256 /// let abs_difference = (x.ln_gamma().0 - 0.0).abs();
1257 ///
1258 /// assert!(abs_difference <= f128::EPSILON);
1259 /// # }
1260 /// ```
1261 #[inline]
1262 #[rustc_allow_incoherent_impl]
1263 #[unstable(feature = "f128", issue = "116909")]
1264 // #[unstable(feature = "float_gamma", issue = "99842")]
1265 #[must_use = "method returns a new number and does not mutate the original value"]
1266 pub fn ln_gamma(self) -> (f128, i32) {
1267 let mut signgamp: i32 = 0;
1268 let x = unsafe { cmath::lgammaf128_r(self, &mut signgamp) };
1269 (x, signgamp)
1270 }
1271
1272 /// Error function.
1273 ///
1274 /// # Unspecified precision
1275 ///
1276 /// The precision of this function is non-deterministic. This means it varies by platform,
1277 /// Rust version, and can even differ within the same execution from one invocation to the next.
1278 ///
1279 /// This function currently corresponds to the `erff128` from libc on Unix
1280 /// and Windows. Note that this might change in the future.
1281 ///
1282 /// # Examples
1283 ///
1284 /// ```
1285 /// #![feature(f128)]
1286 /// #![feature(float_erf)]
1287 /// # #[cfg(reliable_f128_math)] {
1288 /// /// The error function relates what percent of a normal distribution lies
1289 /// /// within `x` standard deviations (scaled by `1/sqrt(2)`).
1290 /// fn within_standard_deviations(x: f128) -> f128 {
1291 /// (x * std::f128::consts::FRAC_1_SQRT_2).erf() * 100.0
1292 /// }
1293 ///
1294 /// // 68% of a normal distribution is within one standard deviation
1295 /// assert!((within_standard_deviations(1.0) - 68.269).abs() < 0.01);
1296 /// // 95% of a normal distribution is within two standard deviations
1297 /// assert!((within_standard_deviations(2.0) - 95.450).abs() < 0.01);
1298 /// // 99.7% of a normal distribution is within three standard deviations
1299 /// assert!((within_standard_deviations(3.0) - 99.730).abs() < 0.01);
1300 /// # }
1301 /// ```
1302 #[rustc_allow_incoherent_impl]
1303 #[must_use = "method returns a new number and does not mutate the original value"]
1304 #[unstable(feature = "f128", issue = "116909")]
1305 // #[unstable(feature = "float_erf", issue = "136321")]
1306 #[inline]
1307 pub fn erf(self) -> f128 {
1308 unsafe { cmath::erff128(self) }
1309 }
1310
1311 /// Complementary error function.
1312 ///
1313 /// # Unspecified precision
1314 ///
1315 /// The precision of this function is non-deterministic. This means it varies by platform,
1316 /// Rust version, and can even differ within the same execution from one invocation to the next.
1317 ///
1318 /// This function currently corresponds to the `erfcf128` from libc on Unix
1319 /// and Windows. Note that this might change in the future.
1320 ///
1321 /// # Examples
1322 ///
1323 /// ```
1324 /// #![feature(f128)]
1325 /// #![feature(float_erf)]
1326 /// # #[cfg(reliable_f128_math)] {
1327 /// let x: f128 = 0.123;
1328 ///
1329 /// let one = x.erf() + x.erfc();
1330 /// let abs_difference = (one - 1.0).abs();
1331 ///
1332 /// assert!(abs_difference <= f128::EPSILON);
1333 /// # }
1334 /// ```
1335 #[rustc_allow_incoherent_impl]
1336 #[must_use = "method returns a new number and does not mutate the original value"]
1337 #[unstable(feature = "f128", issue = "116909")]
1338 // #[unstable(feature = "float_erf", issue = "136321")]
1339 #[inline]
1340 pub fn erfc(self) -> f128 {
1341 unsafe { cmath::erfcf128(self) }
1342 }
1343}