]> git.lizzy.rs Git - rust.git/blob - src/libcore/num/f64.rs
Rollup merge of #67102 - Aaron1011:patch-3, r=Mark-Simulacrum
[rust.git] / src / libcore / num / f64.rs
1 //! This module provides constants which are specific to the implementation
2 //! of the `f64` floating point data type.
3 //!
4 //! *[See also the `f64` primitive type](../../std/primitive.f64.html).*
5 //!
6 //! Mathematically significant numbers are provided in the `consts` sub-module.
7
8 #![stable(feature = "rust1", since = "1.0.0")]
9
10 #[cfg(not(bootstrap))]
11 use crate::convert::FloatToInt;
12 #[cfg(not(test))]
13 use crate::intrinsics;
14 use crate::mem;
15 use crate::num::FpCategory;
16
17 /// The radix or base of the internal representation of `f64`.
18 #[stable(feature = "rust1", since = "1.0.0")]
19 pub const RADIX: u32 = 2;
20
21 /// Number of significant digits in base 2.
22 #[stable(feature = "rust1", since = "1.0.0")]
23 pub const MANTISSA_DIGITS: u32 = 53;
24 /// Approximate number of significant digits in base 10.
25 #[stable(feature = "rust1", since = "1.0.0")]
26 pub const DIGITS: u32 = 15;
27
28 /// [Machine epsilon] value for `f64`.
29 ///
30 /// This is the difference between `1.0` and the next larger representable number.
31 ///
32 /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
33 #[stable(feature = "rust1", since = "1.0.0")]
34 pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
35
36 /// Smallest finite `f64` value.
37 #[stable(feature = "rust1", since = "1.0.0")]
38 pub const MIN: f64 = -1.7976931348623157e+308_f64;
39 /// Smallest positive normal `f64` value.
40 #[stable(feature = "rust1", since = "1.0.0")]
41 pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64;
42 /// Largest finite `f64` value.
43 #[stable(feature = "rust1", since = "1.0.0")]
44 pub const MAX: f64 = 1.7976931348623157e+308_f64;
45
46 /// One greater than the minimum possible normal power of 2 exponent.
47 #[stable(feature = "rust1", since = "1.0.0")]
48 pub const MIN_EXP: i32 = -1021;
49 /// Maximum possible power of 2 exponent.
50 #[stable(feature = "rust1", since = "1.0.0")]
51 pub const MAX_EXP: i32 = 1024;
52
53 /// Minimum possible normal power of 10 exponent.
54 #[stable(feature = "rust1", since = "1.0.0")]
55 pub const MIN_10_EXP: i32 = -307;
56 /// Maximum possible power of 10 exponent.
57 #[stable(feature = "rust1", since = "1.0.0")]
58 pub const MAX_10_EXP: i32 = 308;
59
60 /// Not a Number (NaN).
61 #[stable(feature = "rust1", since = "1.0.0")]
62 pub const NAN: f64 = 0.0_f64 / 0.0_f64;
63 /// Infinity (∞).
64 #[stable(feature = "rust1", since = "1.0.0")]
65 pub const INFINITY: f64 = 1.0_f64 / 0.0_f64;
66 /// Negative infinity (-∞).
67 #[stable(feature = "rust1", since = "1.0.0")]
68 pub const NEG_INFINITY: f64 = -1.0_f64 / 0.0_f64;
69
70 /// Basic mathematical constants.
71 #[stable(feature = "rust1", since = "1.0.0")]
72 pub mod consts {
73     // FIXME: replace with mathematical constants from cmath.
74
75     /// Archimedes' constant (π)
76     #[stable(feature = "rust1", since = "1.0.0")]
77     pub const PI: f64 = 3.14159265358979323846264338327950288_f64;
78
79     /// The full circle constant (τ)
80     ///
81     /// Equal to 2π.
82     #[unstable(feature = "tau_constant", issue = "66770")]
83     pub const TAU: f64 = 6.28318530717958647692528676655900577_f64;
84
85     /// π/2
86     #[stable(feature = "rust1", since = "1.0.0")]
87     pub const FRAC_PI_2: f64 = 1.57079632679489661923132169163975144_f64;
88
89     /// π/3
90     #[stable(feature = "rust1", since = "1.0.0")]
91     pub const FRAC_PI_3: f64 = 1.04719755119659774615421446109316763_f64;
92
93     /// π/4
94     #[stable(feature = "rust1", since = "1.0.0")]
95     pub const FRAC_PI_4: f64 = 0.785398163397448309615660845819875721_f64;
96
97     /// π/6
98     #[stable(feature = "rust1", since = "1.0.0")]
99     pub const FRAC_PI_6: f64 = 0.52359877559829887307710723054658381_f64;
100
101     /// π/8
102     #[stable(feature = "rust1", since = "1.0.0")]
103     pub const FRAC_PI_8: f64 = 0.39269908169872415480783042290993786_f64;
104
105     /// 1/π
106     #[stable(feature = "rust1", since = "1.0.0")]
107     pub const FRAC_1_PI: f64 = 0.318309886183790671537767526745028724_f64;
108
109     /// 2/π
110     #[stable(feature = "rust1", since = "1.0.0")]
111     pub const FRAC_2_PI: f64 = 0.636619772367581343075535053490057448_f64;
112
113     /// 2/sqrt(π)
114     #[stable(feature = "rust1", since = "1.0.0")]
115     pub const FRAC_2_SQRT_PI: f64 = 1.12837916709551257389615890312154517_f64;
116
117     /// sqrt(2)
118     #[stable(feature = "rust1", since = "1.0.0")]
119     pub const SQRT_2: f64 = 1.41421356237309504880168872420969808_f64;
120
121     /// 1/sqrt(2)
122     #[stable(feature = "rust1", since = "1.0.0")]
123     pub const FRAC_1_SQRT_2: f64 = 0.707106781186547524400844362104849039_f64;
124
125     /// Euler's number (e)
126     #[stable(feature = "rust1", since = "1.0.0")]
127     pub const E: f64 = 2.71828182845904523536028747135266250_f64;
128
129     /// log<sub>2</sub>(10)
130     #[unstable(feature = "extra_log_consts", issue = "50540")]
131     pub const LOG2_10: f64 = 3.32192809488736234787031942948939018_f64;
132
133     /// log<sub>2</sub>(e)
134     #[stable(feature = "rust1", since = "1.0.0")]
135     pub const LOG2_E: f64 = 1.44269504088896340735992468100189214_f64;
136
137     /// log<sub>10</sub>(2)
138     #[unstable(feature = "extra_log_consts", issue = "50540")]
139     pub const LOG10_2: f64 = 0.301029995663981195213738894724493027_f64;
140
141     /// log<sub>10</sub>(e)
142     #[stable(feature = "rust1", since = "1.0.0")]
143     pub const LOG10_E: f64 = 0.434294481903251827651128918916605082_f64;
144
145     /// ln(2)
146     #[stable(feature = "rust1", since = "1.0.0")]
147     pub const LN_2: f64 = 0.693147180559945309417232121458176568_f64;
148
149     /// ln(10)
150     #[stable(feature = "rust1", since = "1.0.0")]
151     pub const LN_10: f64 = 2.30258509299404568401799145468436421_f64;
152 }
153
154 #[lang = "f64"]
155 #[cfg(not(test))]
156 impl f64 {
157     /// Returns `true` if this value is `NaN`.
158     ///
159     /// ```
160     /// use std::f64;
161     ///
162     /// let nan = f64::NAN;
163     /// let f = 7.0_f64;
164     ///
165     /// assert!(nan.is_nan());
166     /// assert!(!f.is_nan());
167     /// ```
168     #[stable(feature = "rust1", since = "1.0.0")]
169     #[inline]
170     pub fn is_nan(self) -> bool {
171         self != self
172     }
173
174     // FIXME(#50145): `abs` is publicly unavailable in libcore due to
175     // concerns about portability, so this implementation is for
176     // private use internally.
177     #[inline]
178     fn abs_private(self) -> f64 {
179         f64::from_bits(self.to_bits() & 0x7fff_ffff_ffff_ffff)
180     }
181
182     /// Returns `true` if this value is positive infinity or negative infinity, and
183     /// `false` otherwise.
184     ///
185     /// ```
186     /// use std::f64;
187     ///
188     /// let f = 7.0f64;
189     /// let inf = f64::INFINITY;
190     /// let neg_inf = f64::NEG_INFINITY;
191     /// let nan = f64::NAN;
192     ///
193     /// assert!(!f.is_infinite());
194     /// assert!(!nan.is_infinite());
195     ///
196     /// assert!(inf.is_infinite());
197     /// assert!(neg_inf.is_infinite());
198     /// ```
199     #[stable(feature = "rust1", since = "1.0.0")]
200     #[inline]
201     pub fn is_infinite(self) -> bool {
202         self.abs_private() == INFINITY
203     }
204
205     /// Returns `true` if this number is neither infinite nor `NaN`.
206     ///
207     /// ```
208     /// use std::f64;
209     ///
210     /// let f = 7.0f64;
211     /// let inf: f64 = f64::INFINITY;
212     /// let neg_inf: f64 = f64::NEG_INFINITY;
213     /// let nan: f64 = f64::NAN;
214     ///
215     /// assert!(f.is_finite());
216     ///
217     /// assert!(!nan.is_finite());
218     /// assert!(!inf.is_finite());
219     /// assert!(!neg_inf.is_finite());
220     /// ```
221     #[stable(feature = "rust1", since = "1.0.0")]
222     #[inline]
223     pub fn is_finite(self) -> bool {
224         // There's no need to handle NaN separately: if self is NaN,
225         // the comparison is not true, exactly as desired.
226         self.abs_private() < INFINITY
227     }
228
229     /// Returns `true` if the number is neither zero, infinite,
230     /// [subnormal][subnormal], or `NaN`.
231     ///
232     /// ```
233     /// use std::f64;
234     ///
235     /// let min = f64::MIN_POSITIVE; // 2.2250738585072014e-308f64
236     /// let max = f64::MAX;
237     /// let lower_than_min = 1.0e-308_f64;
238     /// let zero = 0.0f64;
239     ///
240     /// assert!(min.is_normal());
241     /// assert!(max.is_normal());
242     ///
243     /// assert!(!zero.is_normal());
244     /// assert!(!f64::NAN.is_normal());
245     /// assert!(!f64::INFINITY.is_normal());
246     /// // Values between `0` and `min` are Subnormal.
247     /// assert!(!lower_than_min.is_normal());
248     /// ```
249     /// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number
250     #[stable(feature = "rust1", since = "1.0.0")]
251     #[inline]
252     pub fn is_normal(self) -> bool {
253         self.classify() == FpCategory::Normal
254     }
255
256     /// Returns the floating point category of the number. If only one property
257     /// is going to be tested, it is generally faster to use the specific
258     /// predicate instead.
259     ///
260     /// ```
261     /// use std::num::FpCategory;
262     /// use std::f64;
263     ///
264     /// let num = 12.4_f64;
265     /// let inf = f64::INFINITY;
266     ///
267     /// assert_eq!(num.classify(), FpCategory::Normal);
268     /// assert_eq!(inf.classify(), FpCategory::Infinite);
269     /// ```
270     #[stable(feature = "rust1", since = "1.0.0")]
271     pub fn classify(self) -> FpCategory {
272         const EXP_MASK: u64 = 0x7ff0000000000000;
273         const MAN_MASK: u64 = 0x000fffffffffffff;
274
275         let bits = self.to_bits();
276         match (bits & MAN_MASK, bits & EXP_MASK) {
277             (0, 0) => FpCategory::Zero,
278             (_, 0) => FpCategory::Subnormal,
279             (0, EXP_MASK) => FpCategory::Infinite,
280             (_, EXP_MASK) => FpCategory::Nan,
281             _ => FpCategory::Normal,
282         }
283     }
284
285     /// Returns `true` if `self` has a positive sign, including `+0.0`, `NaN`s with
286     /// positive sign bit and positive infinity.
287     ///
288     /// ```
289     /// let f = 7.0_f64;
290     /// let g = -7.0_f64;
291     ///
292     /// assert!(f.is_sign_positive());
293     /// assert!(!g.is_sign_positive());
294     /// ```
295     #[stable(feature = "rust1", since = "1.0.0")]
296     #[inline]
297     pub fn is_sign_positive(self) -> bool {
298         !self.is_sign_negative()
299     }
300
301     #[stable(feature = "rust1", since = "1.0.0")]
302     #[rustc_deprecated(since = "1.0.0", reason = "renamed to is_sign_positive")]
303     #[inline]
304     #[doc(hidden)]
305     pub fn is_positive(self) -> bool {
306         self.is_sign_positive()
307     }
308
309     /// Returns `true` if `self` has a negative sign, including `-0.0`, `NaN`s with
310     /// negative sign bit and negative infinity.
311     ///
312     /// ```
313     /// let f = 7.0_f64;
314     /// let g = -7.0_f64;
315     ///
316     /// assert!(!f.is_sign_negative());
317     /// assert!(g.is_sign_negative());
318     /// ```
319     #[stable(feature = "rust1", since = "1.0.0")]
320     #[inline]
321     pub fn is_sign_negative(self) -> bool {
322         self.to_bits() & 0x8000_0000_0000_0000 != 0
323     }
324
325     #[stable(feature = "rust1", since = "1.0.0")]
326     #[rustc_deprecated(since = "1.0.0", reason = "renamed to is_sign_negative")]
327     #[inline]
328     #[doc(hidden)]
329     pub fn is_negative(self) -> bool {
330         self.is_sign_negative()
331     }
332
333     /// Takes the reciprocal (inverse) of a number, `1/x`.
334     ///
335     /// ```
336     /// let x = 2.0_f64;
337     /// let abs_difference = (x.recip() - (1.0 / x)).abs();
338     ///
339     /// assert!(abs_difference < 1e-10);
340     /// ```
341     #[stable(feature = "rust1", since = "1.0.0")]
342     #[inline]
343     pub fn recip(self) -> f64 {
344         1.0 / self
345     }
346
347     /// Converts radians to degrees.
348     ///
349     /// ```
350     /// use std::f64::consts;
351     ///
352     /// let angle = consts::PI;
353     ///
354     /// let abs_difference = (angle.to_degrees() - 180.0).abs();
355     ///
356     /// assert!(abs_difference < 1e-10);
357     /// ```
358     #[stable(feature = "rust1", since = "1.0.0")]
359     #[inline]
360     pub fn to_degrees(self) -> f64 {
361         // The division here is correctly rounded with respect to the true
362         // value of 180/π. (This differs from f32, where a constant must be
363         // used to ensure a correctly rounded result.)
364         self * (180.0f64 / consts::PI)
365     }
366
367     /// Converts degrees to radians.
368     ///
369     /// ```
370     /// use std::f64::consts;
371     ///
372     /// let angle = 180.0_f64;
373     ///
374     /// let abs_difference = (angle.to_radians() - consts::PI).abs();
375     ///
376     /// assert!(abs_difference < 1e-10);
377     /// ```
378     #[stable(feature = "rust1", since = "1.0.0")]
379     #[inline]
380     pub fn to_radians(self) -> f64 {
381         let value: f64 = consts::PI;
382         self * (value / 180.0)
383     }
384
385     /// Returns the maximum of the two numbers.
386     ///
387     /// ```
388     /// let x = 1.0_f64;
389     /// let y = 2.0_f64;
390     ///
391     /// assert_eq!(x.max(y), y);
392     /// ```
393     ///
394     /// If one of the arguments is NaN, then the other argument is returned.
395     #[stable(feature = "rust1", since = "1.0.0")]
396     #[inline]
397     pub fn max(self, other: f64) -> f64 {
398         intrinsics::maxnumf64(self, other)
399     }
400
401     /// Returns the minimum of the two numbers.
402     ///
403     /// ```
404     /// let x = 1.0_f64;
405     /// let y = 2.0_f64;
406     ///
407     /// assert_eq!(x.min(y), x);
408     /// ```
409     ///
410     /// If one of the arguments is NaN, then the other argument is returned.
411     #[stable(feature = "rust1", since = "1.0.0")]
412     #[inline]
413     pub fn min(self, other: f64) -> f64 {
414         intrinsics::minnumf64(self, other)
415     }
416
417     /// Rounds toward zero and converts to any primitive integer type,
418     /// assuming that the value is finite and fits in that type.
419     ///
420     /// ```
421     /// #![feature(float_approx_unchecked_to)]
422     ///
423     /// let value = 4.6_f32;
424     /// let rounded = unsafe { value.approx_unchecked_to::<u16>() };
425     /// assert_eq!(rounded, 4);
426     ///
427     /// let value = -128.9_f32;
428     /// let rounded = unsafe { value.approx_unchecked_to::<i8>() };
429     /// assert_eq!(rounded, std::i8::MIN);
430     /// ```
431     ///
432     /// # Safety
433     ///
434     /// The value must:
435     ///
436     /// * Not be `NaN`
437     /// * Not be infinite
438     /// * Be representable in the return type `Int`, after truncating off its fractional part
439     #[cfg(not(bootstrap))]
440     #[unstable(feature = "float_approx_unchecked_to", issue = "67058")]
441     #[inline]
442     pub unsafe fn approx_unchecked_to<Int>(self) -> Int where Self: FloatToInt<Int> {
443         FloatToInt::<Int>::approx_unchecked(self)
444     }
445
446     /// Raw transmutation to `u64`.
447     ///
448     /// This is currently identical to `transmute::<f64, u64>(self)` on all platforms.
449     ///
450     /// See `from_bits` for some discussion of the portability of this operation
451     /// (there are almost no issues).
452     ///
453     /// Note that this function is distinct from `as` casting, which attempts to
454     /// preserve the *numeric* value, and not the bitwise value.
455     ///
456     /// # Examples
457     ///
458     /// ```
459     /// assert!((1f64).to_bits() != 1f64 as u64); // to_bits() is not casting!
460     /// assert_eq!((12.5f64).to_bits(), 0x4029000000000000);
461     ///
462     /// ```
463     #[stable(feature = "float_bits_conv", since = "1.20.0")]
464     #[inline]
465     pub fn to_bits(self) -> u64 {
466         // SAFETY: `u64` is a plain old datatype so we can always transmute to it
467         unsafe { mem::transmute(self) }
468     }
469
470     /// Raw transmutation from `u64`.
471     ///
472     /// This is currently identical to `transmute::<u64, f64>(v)` on all platforms.
473     /// It turns out this is incredibly portable, for two reasons:
474     ///
475     /// * Floats and Ints have the same endianness on all supported platforms.
476     /// * IEEE-754 very precisely specifies the bit layout of floats.
477     ///
478     /// However there is one caveat: prior to the 2008 version of IEEE-754, how
479     /// to interpret the NaN signaling bit wasn't actually specified. Most platforms
480     /// (notably x86 and ARM) picked the interpretation that was ultimately
481     /// standardized in 2008, but some didn't (notably MIPS). As a result, all
482     /// signaling NaNs on MIPS are quiet NaNs on x86, and vice-versa.
483     ///
484     /// Rather than trying to preserve signaling-ness cross-platform, this
485     /// implementation favours preserving the exact bits. This means that
486     /// any payloads encoded in NaNs will be preserved even if the result of
487     /// this method is sent over the network from an x86 machine to a MIPS one.
488     ///
489     /// If the results of this method are only manipulated by the same
490     /// architecture that produced them, then there is no portability concern.
491     ///
492     /// If the input isn't NaN, then there is no portability concern.
493     ///
494     /// If you don't care about signalingness (very likely), then there is no
495     /// portability concern.
496     ///
497     /// Note that this function is distinct from `as` casting, which attempts to
498     /// preserve the *numeric* value, and not the bitwise value.
499     ///
500     /// # Examples
501     ///
502     /// ```
503     /// let v = f64::from_bits(0x4029000000000000);
504     /// assert_eq!(v, 12.5);
505     /// ```
506     #[stable(feature = "float_bits_conv", since = "1.20.0")]
507     #[inline]
508     pub fn from_bits(v: u64) -> Self {
509         // SAFETY: `u64` is a plain old datatype so we can always transmute from it
510         // It turns out the safety issues with sNaN were overblown! Hooray!
511         unsafe { mem::transmute(v) }
512     }
513
514     /// Return the memory representation of this floating point number as a byte array in
515     /// big-endian (network) byte order.
516     ///
517     /// # Examples
518     ///
519     /// ```
520     /// let bytes = 12.5f64.to_be_bytes();
521     /// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
522     /// ```
523     #[stable(feature = "float_to_from_bytes", since = "1.40.0")]
524     #[inline]
525     pub fn to_be_bytes(self) -> [u8; 8] {
526         self.to_bits().to_be_bytes()
527     }
528
529     /// Return the memory representation of this floating point number as a byte array in
530     /// little-endian byte order.
531     ///
532     /// # Examples
533     ///
534     /// ```
535     /// let bytes = 12.5f64.to_le_bytes();
536     /// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
537     /// ```
538     #[stable(feature = "float_to_from_bytes", since = "1.40.0")]
539     #[inline]
540     pub fn to_le_bytes(self) -> [u8; 8] {
541         self.to_bits().to_le_bytes()
542     }
543
544     /// Return the memory representation of this floating point number as a byte array in
545     /// native byte order.
546     ///
547     /// As the target platform's native endianness is used, portable code
548     /// should use [`to_be_bytes`] or [`to_le_bytes`], as appropriate, instead.
549     ///
550     /// [`to_be_bytes`]: #method.to_be_bytes
551     /// [`to_le_bytes`]: #method.to_le_bytes
552     ///
553     /// # Examples
554     ///
555     /// ```
556     /// let bytes = 12.5f64.to_ne_bytes();
557     /// assert_eq!(
558     ///     bytes,
559     ///     if cfg!(target_endian = "big") {
560     ///         [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
561     ///     } else {
562     ///         [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]
563     ///     }
564     /// );
565     /// ```
566     #[stable(feature = "float_to_from_bytes", since = "1.40.0")]
567     #[inline]
568     pub fn to_ne_bytes(self) -> [u8; 8] {
569         self.to_bits().to_ne_bytes()
570     }
571
572     /// Create a floating point value from its representation as a byte array in big endian.
573     ///
574     /// # Examples
575     ///
576     /// ```
577     /// let value = f64::from_be_bytes([0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
578     /// assert_eq!(value, 12.5);
579     /// ```
580     #[stable(feature = "float_to_from_bytes", since = "1.40.0")]
581     #[inline]
582     pub fn from_be_bytes(bytes: [u8; 8]) -> Self {
583         Self::from_bits(u64::from_be_bytes(bytes))
584     }
585
586     /// Create a floating point value from its representation as a byte array in little endian.
587     ///
588     /// # Examples
589     ///
590     /// ```
591     /// let value = f64::from_le_bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
592     /// assert_eq!(value, 12.5);
593     /// ```
594     #[stable(feature = "float_to_from_bytes", since = "1.40.0")]
595     #[inline]
596     pub fn from_le_bytes(bytes: [u8; 8]) -> Self {
597         Self::from_bits(u64::from_le_bytes(bytes))
598     }
599
600     /// Create a floating point value from its representation as a byte array in native endian.
601     ///
602     /// As the target platform's native endianness is used, portable code
603     /// likely wants to use [`from_be_bytes`] or [`from_le_bytes`], as
604     /// appropriate instead.
605     ///
606     /// [`from_be_bytes`]: #method.from_be_bytes
607     /// [`from_le_bytes`]: #method.from_le_bytes
608     ///
609     /// # Examples
610     ///
611     /// ```
612     /// let value = f64::from_ne_bytes(if cfg!(target_endian = "big") {
613     ///     [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
614     /// } else {
615     ///     [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]
616     /// });
617     /// assert_eq!(value, 12.5);
618     /// ```
619     #[stable(feature = "float_to_from_bytes", since = "1.40.0")]
620     #[inline]
621     pub fn from_ne_bytes(bytes: [u8; 8]) -> Self {
622         Self::from_bits(u64::from_ne_bytes(bytes))
623     }
624 }