std/
f16.rs

1//! Constants for the `f16` half-precision floating point type.
2//!
3//! *[See also the `f16` primitive type](primitive@f16).*
4//!
5//! Mathematically significant numbers are provided in the `consts` sub-module.
6
7#[unstable(feature = "f16", issue = "116909")]
8pub use core::f16::consts;
9
10#[cfg(not(test))]
11use crate::intrinsics;
12#[cfg(not(test))]
13use crate::sys::cmath;
14
15#[cfg(not(test))]
16impl f16 {
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(f16)]
25    /// # #[cfg(reliable_f16_math)] {
26    ///
27    /// let f = 3.7_f16;
28    /// let g = 3.0_f16;
29    /// let h = -3.7_f16;
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 = "f16", issue = "116909")]
39    #[must_use = "method returns a new number and does not mutate the original value"]
40    pub fn floor(self) -> f16 {
41        unsafe { intrinsics::floorf16(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(f16)]
52    /// # #[cfg(reliable_f16_math)] {
53    ///
54    /// let f = 3.01_f16;
55    /// let g = 4.0_f16;
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 = "f16", issue = "116909")]
65    #[must_use = "method returns a new number and does not mutate the original value"]
66    pub fn ceil(self) -> f16 {
67        unsafe { intrinsics::ceilf16(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(f16)]
79    /// # #[cfg(reliable_f16_math)] {
80    ///
81    /// let f = 3.3_f16;
82    /// let g = -3.3_f16;
83    /// let h = -3.7_f16;
84    /// let i = 3.5_f16;
85    /// let j = 4.5_f16;
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 = "f16", issue = "116909")]
97    #[must_use = "method returns a new number and does not mutate the original value"]
98    pub fn round(self) -> f16 {
99        unsafe { intrinsics::roundf16(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(f16)]
111    /// # #[cfg(reliable_f16_math)] {
112    ///
113    /// let f = 3.3_f16;
114    /// let g = -3.3_f16;
115    /// let h = 3.5_f16;
116    /// let i = 4.5_f16;
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 = "f16", issue = "116909")]
127    #[must_use = "method returns a new number and does not mutate the original value"]
128    pub fn round_ties_even(self) -> f16 {
129        unsafe { intrinsics::rintf16(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(f16)]
141    /// # #[cfg(reliable_f16_math)] {
142    ///
143    /// let f = 3.7_f16;
144    /// let g = 3.0_f16;
145    /// let h = -3.7_f16;
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 = "f16", issue = "116909")]
156    #[must_use = "method returns a new number and does not mutate the original value"]
157    pub fn trunc(self) -> f16 {
158        unsafe { intrinsics::truncf16(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(f16)]
169    /// # #[cfg(reliable_f16_math)] {
170    ///
171    /// let x = 3.6_f16;
172    /// let y = -3.6_f16;
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 <= f16::EPSILON);
177    /// assert!(abs_difference_y <= f16::EPSILON);
178    /// # }
179    /// ```
180    #[inline]
181    #[rustc_allow_incoherent_impl]
182    #[unstable(feature = "f16", issue = "116909")]
183    #[must_use = "method returns a new number and does not mutate the original value"]
184    pub fn fract(self) -> f16 {
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(f16)]
206    /// # #[cfg(reliable_f16_math)] {
207    ///
208    /// let m = 10.0_f16;
209    /// let x = 4.0_f16;
210    /// let b = 60.0_f16;
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_f16 + f16::EPSILON;
216    /// let one_minus_eps = 1.0_f16 - f16::EPSILON;
217    /// let minus_one = -1.0_f16;
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), -f16::EPSILON * f16::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    #[unstable(feature = "f16", issue = "116909")]
228    #[doc(alias = "fmaf16", alias = "fusedMultiplyAdd")]
229    #[must_use = "method returns a new number and does not mutate the original value"]
230    pub fn mul_add(self, a: f16, b: f16) -> f16 {
231        unsafe { intrinsics::fmaf16(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(f16)]
250    /// # #[cfg(reliable_f16_math)] {
251    ///
252    /// let a: f16 = 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 = "f16", issue = "116909")]
263    #[must_use = "method returns a new number and does not mutate the original value"]
264    pub fn div_euclid(self, rhs: f16) -> f16 {
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(f16)]
292    /// # #[cfg(reliable_f16_math)] {
293    ///
294    /// let a: f16 = 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!((-f16::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 = "f16", issue = "116909")]
308    #[must_use = "method returns a new number and does not mutate the original value"]
309    pub fn rem_euclid(self, rhs: f16) -> f16 {
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(f16)]
329    /// # #[cfg(reliable_f16_math)] {
330    ///
331    /// let x = 2.0_f16;
332    /// let abs_difference = (x.powi(2) - (x * x)).abs();
333    /// assert!(abs_difference <= f16::EPSILON);
334    ///
335    /// assert_eq!(f16::powi(f16::NAN, 0), 1.0);
336    /// # }
337    /// ```
338    #[inline]
339    #[rustc_allow_incoherent_impl]
340    #[unstable(feature = "f16", issue = "116909")]
341    #[must_use = "method returns a new number and does not mutate the original value"]
342    pub fn powi(self, n: i32) -> f16 {
343        unsafe { intrinsics::powif16(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(f16)]
357    /// # #[cfg(reliable_f16_math)] {
358    ///
359    /// let x = 2.0_f16;
360    /// let abs_difference = (x.powf(2.0) - (x * x)).abs();
361    /// assert!(abs_difference <= f16::EPSILON);
362    ///
363    /// assert_eq!(f16::powf(1.0, f16::NAN), 1.0);
364    /// assert_eq!(f16::powf(f16::NAN, 0.0), 1.0);
365    /// # }
366    /// ```
367    #[inline]
368    #[rustc_allow_incoherent_impl]
369    #[unstable(feature = "f16", issue = "116909")]
370    #[must_use = "method returns a new number and does not mutate the original value"]
371    pub fn powf(self, n: f16) -> f16 {
372        unsafe { intrinsics::powf16(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(f16)]
389    /// # #[cfg(reliable_f16_math)] {
390    ///
391    /// let positive = 4.0_f16;
392    /// let negative = -4.0_f16;
393    /// let negative_zero = -0.0_f16;
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 = "f16", issue = "116909")]
404    #[must_use = "method returns a new number and does not mutate the original value"]
405    pub fn sqrt(self) -> f16 {
406        unsafe { intrinsics::sqrtf16(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(f16)]
420    /// # #[cfg(reliable_f16_math)] {
421    ///
422    /// let one = 1.0f16;
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 <= f16::EPSILON);
430    /// # }
431    /// ```
432    #[inline]
433    #[rustc_allow_incoherent_impl]
434    #[unstable(feature = "f16", issue = "116909")]
435    #[must_use = "method returns a new number and does not mutate the original value"]
436    pub fn exp(self) -> f16 {
437        unsafe { intrinsics::expf16(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(f16)]
451    /// # #[cfg(reliable_f16_math)] {
452    ///
453    /// let f = 2.0f16;
454    ///
455    /// // 2^2 - 4 == 0
456    /// let abs_difference = (f.exp2() - 4.0).abs();
457    ///
458    /// assert!(abs_difference <= f16::EPSILON);
459    /// # }
460    /// ```
461    #[inline]
462    #[rustc_allow_incoherent_impl]
463    #[unstable(feature = "f16", issue = "116909")]
464    #[must_use = "method returns a new number and does not mutate the original value"]
465    pub fn exp2(self) -> f16 {
466        unsafe { intrinsics::exp2f16(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(f16)]
480    /// # #[cfg(reliable_f16_math)] {
481    ///
482    /// let one = 1.0f16;
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 <= f16::EPSILON);
490    /// # }
491    /// ```
492    #[inline]
493    #[rustc_allow_incoherent_impl]
494    #[unstable(feature = "f16", issue = "116909")]
495    #[must_use = "method returns a new number and does not mutate the original value"]
496    pub fn ln(self) -> f16 {
497        unsafe { intrinsics::logf16(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(f16)]
515    /// # #[cfg(reliable_f16_math)] {
516    ///
517    /// let five = 5.0f16;
518    ///
519    /// // log5(5) - 1 == 0
520    /// let abs_difference = (five.log(5.0) - 1.0).abs();
521    ///
522    /// assert!(abs_difference <= f16::EPSILON);
523    /// # }
524    /// ```
525    #[inline]
526    #[rustc_allow_incoherent_impl]
527    #[unstable(feature = "f16", issue = "116909")]
528    #[must_use = "method returns a new number and does not mutate the original value"]
529    pub fn log(self, base: f16) -> f16 {
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(f16)]
544    /// # #[cfg(reliable_f16_math)] {
545    ///
546    /// let two = 2.0f16;
547    ///
548    /// // log2(2) - 1 == 0
549    /// let abs_difference = (two.log2() - 1.0).abs();
550    ///
551    /// assert!(abs_difference <= f16::EPSILON);
552    /// # }
553    /// ```
554    #[inline]
555    #[rustc_allow_incoherent_impl]
556    #[unstable(feature = "f16", issue = "116909")]
557    #[must_use = "method returns a new number and does not mutate the original value"]
558    pub fn log2(self) -> f16 {
559        unsafe { intrinsics::log2f16(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(f16)]
573    /// # #[cfg(reliable_f16_math)] {
574    ///
575    /// let ten = 10.0f16;
576    ///
577    /// // log10(10) - 1 == 0
578    /// let abs_difference = (ten.log10() - 1.0).abs();
579    ///
580    /// assert!(abs_difference <= f16::EPSILON);
581    /// # }
582    /// ```
583    #[inline]
584    #[rustc_allow_incoherent_impl]
585    #[unstable(feature = "f16", issue = "116909")]
586    #[must_use = "method returns a new number and does not mutate the original value"]
587    pub fn log10(self) -> f16 {
588        unsafe { intrinsics::log10f16(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    /// This function currently corresponds to the `cbrtf` from libc on Unix
599    /// and Windows. Note that this might change in the future.
600    ///
601    /// # Examples
602    ///
603    /// ```
604    /// #![feature(f16)]
605    /// # #[cfg(reliable_f16_math)] {
606    ///
607    /// let x = 8.0f16;
608    ///
609    /// // x^(1/3) - 2 == 0
610    /// let abs_difference = (x.cbrt() - 2.0).abs();
611    ///
612    /// assert!(abs_difference <= f16::EPSILON);
613    /// # }
614    /// ```
615    #[inline]
616    #[rustc_allow_incoherent_impl]
617    #[unstable(feature = "f16", issue = "116909")]
618    #[must_use = "method returns a new number and does not mutate the original value"]
619    pub fn cbrt(self) -> f16 {
620        (unsafe { cmath::cbrtf(self as f32) }) as f16
621    }
622
623    /// Compute the distance between the origin and a point (`x`, `y`) on the
624    /// Euclidean plane. Equivalently, compute the length of the hypotenuse of a
625    /// right-angle triangle with other sides having length `x.abs()` and
626    /// `y.abs()`.
627    ///
628    /// # Unspecified precision
629    ///
630    /// The precision of this function is non-deterministic. This means it varies by platform,
631    /// Rust version, and can even differ within the same execution from one invocation to the next.
632    ///
633    /// This function currently corresponds to the `hypotf` from libc on Unix
634    /// and Windows. Note that this might change in the future.
635    ///
636    /// # Examples
637    ///
638    /// ```
639    /// #![feature(f16)]
640    /// # #[cfg(reliable_f16_math)] {
641    ///
642    /// let x = 2.0f16;
643    /// let y = 3.0f16;
644    ///
645    /// // sqrt(x^2 + y^2)
646    /// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();
647    ///
648    /// assert!(abs_difference <= f16::EPSILON);
649    /// # }
650    /// ```
651    #[inline]
652    #[rustc_allow_incoherent_impl]
653    #[unstable(feature = "f16", issue = "116909")]
654    #[must_use = "method returns a new number and does not mutate the original value"]
655    pub fn hypot(self, other: f16) -> f16 {
656        (unsafe { cmath::hypotf(self as f32, other as f32) }) as f16
657    }
658
659    /// Computes the sine of a number (in radians).
660    ///
661    /// # Unspecified precision
662    ///
663    /// The precision of this function is non-deterministic. This means it varies by platform,
664    /// Rust version, and can even differ within the same execution from one invocation to the next.
665    ///
666    /// # Examples
667    ///
668    /// ```
669    /// #![feature(f16)]
670    /// # #[cfg(reliable_f16_math)] {
671    ///
672    /// let x = std::f16::consts::FRAC_PI_2;
673    ///
674    /// let abs_difference = (x.sin() - 1.0).abs();
675    ///
676    /// assert!(abs_difference <= f16::EPSILON);
677    /// # }
678    /// ```
679    #[inline]
680    #[rustc_allow_incoherent_impl]
681    #[unstable(feature = "f16", issue = "116909")]
682    #[must_use = "method returns a new number and does not mutate the original value"]
683    pub fn sin(self) -> f16 {
684        unsafe { intrinsics::sinf16(self) }
685    }
686
687    /// Computes the cosine of a number (in radians).
688    ///
689    /// # Unspecified precision
690    ///
691    /// The precision of this function is non-deterministic. This means it varies by platform,
692    /// Rust version, and can even differ within the same execution from one invocation to the next.
693    ///
694    /// # Examples
695    ///
696    /// ```
697    /// #![feature(f16)]
698    /// # #[cfg(reliable_f16_math)] {
699    ///
700    /// let x = 2.0 * std::f16::consts::PI;
701    ///
702    /// let abs_difference = (x.cos() - 1.0).abs();
703    ///
704    /// assert!(abs_difference <= f16::EPSILON);
705    /// # }
706    /// ```
707    #[inline]
708    #[rustc_allow_incoherent_impl]
709    #[unstable(feature = "f16", issue = "116909")]
710    #[must_use = "method returns a new number and does not mutate the original value"]
711    pub fn cos(self) -> f16 {
712        unsafe { intrinsics::cosf16(self) }
713    }
714
715    /// Computes the tangent of a number (in radians).
716    ///
717    /// # Unspecified precision
718    ///
719    /// The precision of this function is non-deterministic. This means it varies by platform,
720    /// Rust version, and can even differ within the same execution from one invocation to the next.
721    ///
722    /// This function currently corresponds to the `tanf` from libc on Unix and
723    /// Windows. Note that this might change in the future.
724    ///
725    /// # Examples
726    ///
727    /// ```
728    /// #![feature(f16)]
729    /// # #[cfg(reliable_f16_math)] {
730    ///
731    /// let x = std::f16::consts::FRAC_PI_4;
732    /// let abs_difference = (x.tan() - 1.0).abs();
733    ///
734    /// assert!(abs_difference <= f16::EPSILON);
735    /// # }
736    /// ```
737    #[inline]
738    #[rustc_allow_incoherent_impl]
739    #[unstable(feature = "f16", issue = "116909")]
740    #[must_use = "method returns a new number and does not mutate the original value"]
741    pub fn tan(self) -> f16 {
742        (unsafe { cmath::tanf(self as f32) }) as f16
743    }
744
745    /// Computes the arcsine of a number. Return value is in radians in
746    /// the range [-pi/2, pi/2] or NaN if the number is outside the range
747    /// [-1, 1].
748    ///
749    /// # Unspecified precision
750    ///
751    /// The precision of this function is non-deterministic. This means it varies by platform,
752    /// Rust version, and can even differ within the same execution from one invocation to the next.
753    ///
754    /// This function currently corresponds to the `asinf` from libc on Unix
755    /// and Windows. Note that this might change in the future.
756    ///
757    /// # Examples
758    ///
759    /// ```
760    /// #![feature(f16)]
761    /// # #[cfg(reliable_f16_math)] {
762    ///
763    /// let f = std::f16::consts::FRAC_PI_2;
764    ///
765    /// // asin(sin(pi/2))
766    /// let abs_difference = (f.sin().asin() - std::f16::consts::FRAC_PI_2).abs();
767    ///
768    /// assert!(abs_difference <= f16::EPSILON);
769    /// # }
770    /// ```
771    #[inline]
772    #[doc(alias = "arcsin")]
773    #[rustc_allow_incoherent_impl]
774    #[unstable(feature = "f16", issue = "116909")]
775    #[must_use = "method returns a new number and does not mutate the original value"]
776    pub fn asin(self) -> f16 {
777        (unsafe { cmath::asinf(self as f32) }) as f16
778    }
779
780    /// Computes the arccosine of a number. Return value is in radians in
781    /// the range [0, pi] or NaN if the number is outside the range
782    /// [-1, 1].
783    ///
784    /// # Unspecified precision
785    ///
786    /// The precision of this function is non-deterministic. This means it varies by platform,
787    /// Rust version, and can even differ within the same execution from one invocation to the next.
788    ///
789    /// This function currently corresponds to the `acosf` from libc on Unix
790    /// and Windows. Note that this might change in the future.
791    ///
792    /// # Examples
793    ///
794    /// ```
795    /// #![feature(f16)]
796    /// # #[cfg(reliable_f16_math)] {
797    ///
798    /// let f = std::f16::consts::FRAC_PI_4;
799    ///
800    /// // acos(cos(pi/4))
801    /// let abs_difference = (f.cos().acos() - std::f16::consts::FRAC_PI_4).abs();
802    ///
803    /// assert!(abs_difference <= f16::EPSILON);
804    /// # }
805    /// ```
806    #[inline]
807    #[doc(alias = "arccos")]
808    #[rustc_allow_incoherent_impl]
809    #[unstable(feature = "f16", issue = "116909")]
810    #[must_use = "method returns a new number and does not mutate the original value"]
811    pub fn acos(self) -> f16 {
812        (unsafe { cmath::acosf(self as f32) }) as f16
813    }
814
815    /// Computes the arctangent of a number. Return value is in radians in the
816    /// range [-pi/2, pi/2];
817    ///
818    /// # Unspecified precision
819    ///
820    /// The precision of this function is non-deterministic. This means it varies by platform,
821    /// Rust version, and can even differ within the same execution from one invocation to the next.
822    ///
823    /// This function currently corresponds to the `atanf` from libc on Unix
824    /// and Windows. Note that this might change in the future.
825    ///
826    /// # Examples
827    ///
828    /// ```
829    /// #![feature(f16)]
830    /// # #[cfg(reliable_f16_math)] {
831    ///
832    /// let f = 1.0f16;
833    ///
834    /// // atan(tan(1))
835    /// let abs_difference = (f.tan().atan() - 1.0).abs();
836    ///
837    /// assert!(abs_difference <= f16::EPSILON);
838    /// # }
839    /// ```
840    #[inline]
841    #[doc(alias = "arctan")]
842    #[rustc_allow_incoherent_impl]
843    #[unstable(feature = "f16", issue = "116909")]
844    #[must_use = "method returns a new number and does not mutate the original value"]
845    pub fn atan(self) -> f16 {
846        (unsafe { cmath::atanf(self as f32) }) as f16
847    }
848
849    /// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
850    ///
851    /// * `x = 0`, `y = 0`: `0`
852    /// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]`
853    /// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
854    /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
855    ///
856    /// # Unspecified precision
857    ///
858    /// The precision of this function is non-deterministic. This means it varies by platform,
859    /// Rust version, and can even differ within the same execution from one invocation to the next.
860    ///
861    /// This function currently corresponds to the `atan2f` from libc on Unix
862    /// and Windows. Note that this might change in the future.
863    ///
864    /// # Examples
865    ///
866    /// ```
867    /// #![feature(f16)]
868    /// # #[cfg(reliable_f16_math)] {
869    ///
870    /// // Positive angles measured counter-clockwise
871    /// // from positive x axis
872    /// // -pi/4 radians (45 deg clockwise)
873    /// let x1 = 3.0f16;
874    /// let y1 = -3.0f16;
875    ///
876    /// // 3pi/4 radians (135 deg counter-clockwise)
877    /// let x2 = -3.0f16;
878    /// let y2 = 3.0f16;
879    ///
880    /// let abs_difference_1 = (y1.atan2(x1) - (-std::f16::consts::FRAC_PI_4)).abs();
881    /// let abs_difference_2 = (y2.atan2(x2) - (3.0 * std::f16::consts::FRAC_PI_4)).abs();
882    ///
883    /// assert!(abs_difference_1 <= f16::EPSILON);
884    /// assert!(abs_difference_2 <= f16::EPSILON);
885    /// # }
886    /// ```
887    #[inline]
888    #[rustc_allow_incoherent_impl]
889    #[unstable(feature = "f16", issue = "116909")]
890    #[must_use = "method returns a new number and does not mutate the original value"]
891    pub fn atan2(self, other: f16) -> f16 {
892        (unsafe { cmath::atan2f(self as f32, other as f32) }) as f16
893    }
894
895    /// Simultaneously computes the sine and cosine of the number, `x`. Returns
896    /// `(sin(x), cos(x))`.
897    ///
898    /// # Unspecified precision
899    ///
900    /// The precision of this function is non-deterministic. This means it varies by platform,
901    /// Rust version, and can even differ within the same execution from one invocation to the next.
902    ///
903    /// This function currently corresponds to the `(f16::sin(x),
904    /// f16::cos(x))`. Note that this might change in the future.
905    ///
906    /// # Examples
907    ///
908    /// ```
909    /// #![feature(f16)]
910    /// # #[cfg(reliable_f16_math)] {
911    ///
912    /// let x = std::f16::consts::FRAC_PI_4;
913    /// let f = x.sin_cos();
914    ///
915    /// let abs_difference_0 = (f.0 - x.sin()).abs();
916    /// let abs_difference_1 = (f.1 - x.cos()).abs();
917    ///
918    /// assert!(abs_difference_0 <= f16::EPSILON);
919    /// assert!(abs_difference_1 <= f16::EPSILON);
920    /// # }
921    /// ```
922    #[inline]
923    #[doc(alias = "sincos")]
924    #[rustc_allow_incoherent_impl]
925    #[unstable(feature = "f16", issue = "116909")]
926    pub fn sin_cos(self) -> (f16, f16) {
927        (self.sin(), self.cos())
928    }
929
930    /// Returns `e^(self) - 1` in a way that is accurate even if the
931    /// number is close to zero.
932    ///
933    /// # Unspecified precision
934    ///
935    /// The precision of this function is non-deterministic. This means it varies by platform,
936    /// Rust version, and can even differ within the same execution from one invocation to the next.
937    ///
938    /// This function currently corresponds to the `expm1f` from libc on Unix
939    /// and Windows. Note that this might change in the future.
940    ///
941    /// # Examples
942    ///
943    /// ```
944    /// #![feature(f16)]
945    /// # #[cfg(reliable_f16_math)] {
946    ///
947    /// let x = 1e-4_f16;
948    ///
949    /// // for very small x, e^x is approximately 1 + x + x^2 / 2
950    /// let approx = x + x * x / 2.0;
951    /// let abs_difference = (x.exp_m1() - approx).abs();
952    ///
953    /// assert!(abs_difference < 1e-4);
954    /// # }
955    /// ```
956    #[inline]
957    #[rustc_allow_incoherent_impl]
958    #[unstable(feature = "f16", issue = "116909")]
959    #[must_use = "method returns a new number and does not mutate the original value"]
960    pub fn exp_m1(self) -> f16 {
961        (unsafe { cmath::expm1f(self as f32) }) as f16
962    }
963
964    /// Returns `ln(1+n)` (natural logarithm) more accurately than if
965    /// the operations were performed separately.
966    ///
967    /// # Unspecified precision
968    ///
969    /// The precision of this function is non-deterministic. This means it varies by platform,
970    /// Rust version, and can even differ within the same execution from one invocation to the next.
971    ///
972    /// This function currently corresponds to the `log1pf` from libc on Unix
973    /// and Windows. Note that this might change in the future.
974    ///
975    /// # Examples
976    ///
977    /// ```
978    /// #![feature(f16)]
979    /// # #[cfg(reliable_f16_math)] {
980    ///
981    /// let x = 1e-4_f16;
982    ///
983    /// // for very small x, ln(1 + x) is approximately x - x^2 / 2
984    /// let approx = x - x * x / 2.0;
985    /// let abs_difference = (x.ln_1p() - approx).abs();
986    ///
987    /// assert!(abs_difference < 1e-4);
988    /// # }
989    /// ```
990    #[inline]
991    #[doc(alias = "log1p")]
992    #[rustc_allow_incoherent_impl]
993    #[unstable(feature = "f16", issue = "116909")]
994    #[must_use = "method returns a new number and does not mutate the original value"]
995    pub fn ln_1p(self) -> f16 {
996        (unsafe { cmath::log1pf(self as f32) }) as f16
997    }
998
999    /// Hyperbolic sine function.
1000    ///
1001    /// # Unspecified precision
1002    ///
1003    /// The precision of this function is non-deterministic. This means it varies by platform,
1004    /// Rust version, and can even differ within the same execution from one invocation to the next.
1005    ///
1006    /// This function currently corresponds to the `sinhf` from libc on Unix
1007    /// and Windows. Note that this might change in the future.
1008    ///
1009    /// # Examples
1010    ///
1011    /// ```
1012    /// #![feature(f16)]
1013    /// # #[cfg(reliable_f16_math)] {
1014    ///
1015    /// let e = std::f16::consts::E;
1016    /// let x = 1.0f16;
1017    ///
1018    /// let f = x.sinh();
1019    /// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
1020    /// let g = ((e * e) - 1.0) / (2.0 * e);
1021    /// let abs_difference = (f - g).abs();
1022    ///
1023    /// assert!(abs_difference <= f16::EPSILON);
1024    /// # }
1025    /// ```
1026    #[inline]
1027    #[rustc_allow_incoherent_impl]
1028    #[unstable(feature = "f16", issue = "116909")]
1029    #[must_use = "method returns a new number and does not mutate the original value"]
1030    pub fn sinh(self) -> f16 {
1031        (unsafe { cmath::sinhf(self as f32) }) as f16
1032    }
1033
1034    /// Hyperbolic cosine function.
1035    ///
1036    /// # Unspecified precision
1037    ///
1038    /// The precision of this function is non-deterministic. This means it varies by platform,
1039    /// Rust version, and can even differ within the same execution from one invocation to the next.
1040    ///
1041    /// This function currently corresponds to the `coshf` from libc on Unix
1042    /// and Windows. Note that this might change in the future.
1043    ///
1044    /// # Examples
1045    ///
1046    /// ```
1047    /// #![feature(f16)]
1048    /// # #[cfg(reliable_f16_math)] {
1049    ///
1050    /// let e = std::f16::consts::E;
1051    /// let x = 1.0f16;
1052    /// let f = x.cosh();
1053    /// // Solving cosh() at 1 gives this result
1054    /// let g = ((e * e) + 1.0) / (2.0 * e);
1055    /// let abs_difference = (f - g).abs();
1056    ///
1057    /// // Same result
1058    /// assert!(abs_difference <= f16::EPSILON);
1059    /// # }
1060    /// ```
1061    #[inline]
1062    #[rustc_allow_incoherent_impl]
1063    #[unstable(feature = "f16", issue = "116909")]
1064    #[must_use = "method returns a new number and does not mutate the original value"]
1065    pub fn cosh(self) -> f16 {
1066        (unsafe { cmath::coshf(self as f32) }) as f16
1067    }
1068
1069    /// Hyperbolic tangent function.
1070    ///
1071    /// # Unspecified precision
1072    ///
1073    /// The precision of this function is non-deterministic. This means it varies by platform,
1074    /// Rust version, and can even differ within the same execution from one invocation to the next.
1075    ///
1076    /// This function currently corresponds to the `tanhf` from libc on Unix
1077    /// and Windows. Note that this might change in the future.
1078    ///
1079    /// # Examples
1080    ///
1081    /// ```
1082    /// #![feature(f16)]
1083    /// # #[cfg(reliable_f16_math)] {
1084    ///
1085    /// let e = std::f16::consts::E;
1086    /// let x = 1.0f16;
1087    ///
1088    /// let f = x.tanh();
1089    /// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
1090    /// let g = (1.0 - e.powi(-2)) / (1.0 + e.powi(-2));
1091    /// let abs_difference = (f - g).abs();
1092    ///
1093    /// assert!(abs_difference <= f16::EPSILON);
1094    /// # }
1095    /// ```
1096    #[inline]
1097    #[rustc_allow_incoherent_impl]
1098    #[unstable(feature = "f16", issue = "116909")]
1099    #[must_use = "method returns a new number and does not mutate the original value"]
1100    pub fn tanh(self) -> f16 {
1101        (unsafe { cmath::tanhf(self as f32) }) as f16
1102    }
1103
1104    /// Inverse hyperbolic sine function.
1105    ///
1106    /// # Unspecified precision
1107    ///
1108    /// The precision of this function is non-deterministic. This means it varies by platform,
1109    /// Rust version, and can even differ within the same execution from one invocation to the next.
1110    ///
1111    /// # Examples
1112    ///
1113    /// ```
1114    /// #![feature(f16)]
1115    /// # #[cfg(reliable_f16_math)] {
1116    ///
1117    /// let x = 1.0f16;
1118    /// let f = x.sinh().asinh();
1119    ///
1120    /// let abs_difference = (f - x).abs();
1121    ///
1122    /// assert!(abs_difference <= f16::EPSILON);
1123    /// # }
1124    /// ```
1125    #[inline]
1126    #[doc(alias = "arcsinh")]
1127    #[rustc_allow_incoherent_impl]
1128    #[unstable(feature = "f16", issue = "116909")]
1129    #[must_use = "method returns a new number and does not mutate the original value"]
1130    pub fn asinh(self) -> f16 {
1131        let ax = self.abs();
1132        let ix = 1.0 / ax;
1133        (ax + (ax / (Self::hypot(1.0, ix) + ix))).ln_1p().copysign(self)
1134    }
1135
1136    /// Inverse hyperbolic cosine function.
1137    ///
1138    /// # Unspecified precision
1139    ///
1140    /// The precision of this function is non-deterministic. This means it varies by platform,
1141    /// Rust version, and can even differ within the same execution from one invocation to the next.
1142    ///
1143    /// # Examples
1144    ///
1145    /// ```
1146    /// #![feature(f16)]
1147    /// # #[cfg(reliable_f16_math)] {
1148    ///
1149    /// let x = 1.0f16;
1150    /// let f = x.cosh().acosh();
1151    ///
1152    /// let abs_difference = (f - x).abs();
1153    ///
1154    /// assert!(abs_difference <= f16::EPSILON);
1155    /// # }
1156    /// ```
1157    #[inline]
1158    #[doc(alias = "arccosh")]
1159    #[rustc_allow_incoherent_impl]
1160    #[unstable(feature = "f16", issue = "116909")]
1161    #[must_use = "method returns a new number and does not mutate the original value"]
1162    pub fn acosh(self) -> f16 {
1163        if self < 1.0 {
1164            Self::NAN
1165        } else {
1166            (self + ((self - 1.0).sqrt() * (self + 1.0).sqrt())).ln()
1167        }
1168    }
1169
1170    /// Inverse hyperbolic tangent function.
1171    ///
1172    /// # Unspecified precision
1173    ///
1174    /// The precision of this function is non-deterministic. This means it varies by platform,
1175    /// Rust version, and can even differ within the same execution from one invocation to the next.
1176    ///
1177    /// # Examples
1178    ///
1179    /// ```
1180    /// #![feature(f16)]
1181    /// # #[cfg(reliable_f16_math)] {
1182    ///
1183    /// let e = std::f16::consts::E;
1184    /// let f = e.tanh().atanh();
1185    ///
1186    /// let abs_difference = (f - e).abs();
1187    ///
1188    /// assert!(abs_difference <= 0.01);
1189    /// # }
1190    /// ```
1191    #[inline]
1192    #[doc(alias = "arctanh")]
1193    #[rustc_allow_incoherent_impl]
1194    #[unstable(feature = "f16", issue = "116909")]
1195    #[must_use = "method returns a new number and does not mutate the original value"]
1196    pub fn atanh(self) -> f16 {
1197        0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
1198    }
1199
1200    /// Gamma function.
1201    ///
1202    /// # Unspecified precision
1203    ///
1204    /// The precision of this function is non-deterministic. This means it varies by platform,
1205    /// Rust version, and can even differ within the same execution from one invocation to the next.
1206    ///
1207    /// This function currently corresponds to the `tgammaf` from libc on Unix
1208    /// and Windows. Note that this might change in the future.
1209    ///
1210    /// # Examples
1211    ///
1212    /// ```
1213    /// #![feature(f16)]
1214    /// #![feature(float_gamma)]
1215    /// # #[cfg(reliable_f16_math)] {
1216    ///
1217    /// let x = 5.0f16;
1218    ///
1219    /// let abs_difference = (x.gamma() - 24.0).abs();
1220    ///
1221    /// assert!(abs_difference <= f16::EPSILON);
1222    /// # }
1223    /// ```
1224    #[inline]
1225    #[rustc_allow_incoherent_impl]
1226    #[unstable(feature = "f16", issue = "116909")]
1227    // #[unstable(feature = "float_gamma", issue = "99842")]
1228    #[must_use = "method returns a new number and does not mutate the original value"]
1229    pub fn gamma(self) -> f16 {
1230        (unsafe { cmath::tgammaf(self as f32) }) as f16
1231    }
1232
1233    /// Natural logarithm of the absolute value of the gamma function
1234    ///
1235    /// The integer part of the tuple indicates the sign of the gamma function.
1236    ///
1237    /// # Unspecified precision
1238    ///
1239    /// The precision of this function is non-deterministic. This means it varies by platform,
1240    /// Rust version, and can even differ within the same execution from one invocation to the next.
1241    ///
1242    /// This function currently corresponds to the `lgamma_r` from libc on Unix
1243    /// and Windows. Note that this might change in the future.
1244    ///
1245    /// # Examples
1246    ///
1247    /// ```
1248    /// #![feature(f16)]
1249    /// #![feature(float_gamma)]
1250    /// # #[cfg(reliable_f16_math)] {
1251    ///
1252    /// let x = 2.0f16;
1253    ///
1254    /// let abs_difference = (x.ln_gamma().0 - 0.0).abs();
1255    ///
1256    /// assert!(abs_difference <= f16::EPSILON);
1257    /// # }
1258    /// ```
1259    #[inline]
1260    #[rustc_allow_incoherent_impl]
1261    #[unstable(feature = "f16", issue = "116909")]
1262    // #[unstable(feature = "float_gamma", issue = "99842")]
1263    #[must_use = "method returns a new number and does not mutate the original value"]
1264    pub fn ln_gamma(self) -> (f16, i32) {
1265        let mut signgamp: i32 = 0;
1266        let x = (unsafe { cmath::lgammaf_r(self as f32, &mut signgamp) }) as f16;
1267        (x, signgamp)
1268    }
1269
1270    /// Error function.
1271    ///
1272    /// # Unspecified precision
1273    ///
1274    /// The precision of this function is non-deterministic. This means it varies by platform,
1275    /// Rust version, and can even differ within the same execution from one invocation to the next.
1276    ///
1277    /// This function currently corresponds to the `erff` from libc on Unix
1278    /// and Windows. Note that this might change in the future.
1279    ///
1280    /// # Examples
1281    ///
1282    /// ```
1283    /// #![feature(f16)]
1284    /// #![feature(float_erf)]
1285    /// # #[cfg(reliable_f16_math)] {
1286    /// /// The error function relates what percent of a normal distribution lies
1287    /// /// within `x` standard deviations (scaled by `1/sqrt(2)`).
1288    /// fn within_standard_deviations(x: f16) -> f16 {
1289    ///     (x * std::f16::consts::FRAC_1_SQRT_2).erf() * 100.0
1290    /// }
1291    ///
1292    /// // 68% of a normal distribution is within one standard deviation
1293    /// assert!((within_standard_deviations(1.0) - 68.269).abs() < 0.1);
1294    /// // 95% of a normal distribution is within two standard deviations
1295    /// assert!((within_standard_deviations(2.0) - 95.450).abs() < 0.1);
1296    /// // 99.7% of a normal distribution is within three standard deviations
1297    /// assert!((within_standard_deviations(3.0) - 99.730).abs() < 0.1);
1298    /// # }
1299    /// ```
1300    #[rustc_allow_incoherent_impl]
1301    #[must_use = "method returns a new number and does not mutate the original value"]
1302    #[unstable(feature = "f16", issue = "116909")]
1303    // #[unstable(feature = "float_erf", issue = "136321")]
1304    #[inline]
1305    pub fn erf(self) -> f16 {
1306        (unsafe { cmath::erff(self as f32) }) as f16
1307    }
1308
1309    /// Complementary error function.
1310    ///
1311    /// # Unspecified precision
1312    ///
1313    /// The precision of this function is non-deterministic. This means it varies by platform,
1314    /// Rust version, and can even differ within the same execution from one invocation to the next.
1315    ///
1316    /// This function currently corresponds to the `erfcf` from libc on Unix
1317    /// and Windows. Note that this might change in the future.
1318    ///
1319    /// # Examples
1320    ///
1321    /// ```
1322    /// #![feature(f16)]
1323    /// #![feature(float_erf)]
1324    /// let x: f16 = 0.123;
1325    ///
1326    /// let one = x.erf() + x.erfc();
1327    /// let abs_difference = (one - 1.0).abs();
1328    ///
1329    /// assert!(abs_difference <= f16::EPSILON);
1330    /// ```
1331    #[rustc_allow_incoherent_impl]
1332    #[must_use = "method returns a new number and does not mutate the original value"]
1333    #[unstable(feature = "f16", issue = "116909")]
1334    // #[unstable(feature = "float_erf", issue = "136321")]
1335    #[inline]
1336    pub fn erfc(self) -> f16 {
1337        (unsafe { cmath::erfcf(self as f32) }) as f16
1338    }
1339}