@@ -27,9 +27,9 @@ pub(crate) mod convert;
27
27
/// A 16-bit floating point type implementing the [`bfloat16`] format.
28
28
///
29
29
/// The [`bfloat16`] floating point format is a truncated 16-bit version of the IEEE 754 standard
30
- /// `binary32`, a.k.a [`f32`]. [`bf16`] has approximately the same dynamic range as [`f32`] by
31
- /// having a lower precision than [`f16`][crate::f16]. While [`f16`][crate::f16] has a precision of
32
- /// 11 bits, [`bf16`] has a precision of only 8 bits.
30
+ /// `binary32`, a.k.a [`f32`]. [`struct@ bf16`] has approximately the same dynamic range as [`f32`] by
31
+ /// having a lower precision than [`struct@ f16`][crate::f16]. While [`struct@ f16`][crate::f16] has a precision of
32
+ /// 11 bits, [`struct@ bf16`] has a precision of only 8 bits.
33
33
///
34
34
/// [`bfloat16`]: https://en.wikipedia.org/wiki/Bfloat16_floating-point_format
35
35
#[ allow( non_camel_case_types) ]
@@ -47,14 +47,14 @@ pub(crate) mod convert;
47
47
pub struct bf16 ( u16 ) ;
48
48
49
49
impl bf16 {
50
- /// Constructs a [`bf16`] value from the raw bits.
50
+ /// Constructs a [`struct@ bf16`] value from the raw bits.
51
51
#[ inline]
52
52
#[ must_use]
53
53
pub const fn from_bits ( bits : u16 ) -> bf16 {
54
54
bf16 ( bits)
55
55
}
56
56
57
- /// Constructs a [`bf16`] value from a 32-bit floating point value.
57
+ /// Constructs a [`struct@ bf16`] value from a 32-bit floating point value.
58
58
///
59
59
/// This operation is lossy. If the 32-bit value is too large to fit, ±∞ will result. NaN values
60
60
/// are preserved. Subnormal values that are too tiny to be represented will result in ±0. All
@@ -65,7 +65,7 @@ impl bf16 {
65
65
Self :: from_f32_const ( value)
66
66
}
67
67
68
- /// Constructs a [`bf16`] value from a 32-bit floating point value.
68
+ /// Constructs a [`struct@ bf16`] value from a 32-bit floating point value.
69
69
///
70
70
/// This function is identical to [`from_f32`][Self::from_f32] except it never uses hardware
71
71
/// intrinsics, which allows it to be `const`. [`from_f32`][Self::from_f32] should be preferred
@@ -80,7 +80,7 @@ impl bf16 {
80
80
bf16 ( convert:: f32_to_bf16 ( value) )
81
81
}
82
82
83
- /// Constructs a [`bf16`] value from a 64-bit floating point value.
83
+ /// Constructs a [`struct@ bf16`] value from a 64-bit floating point value.
84
84
///
85
85
/// This operation is lossy. If the 64-bit value is to large to fit, ±∞ will result. NaN values
86
86
/// are preserved. 64-bit subnormal values are too tiny to be represented and result in ±0.
@@ -92,7 +92,7 @@ impl bf16 {
92
92
Self :: from_f64_const ( value)
93
93
}
94
94
95
- /// Constructs a [`bf16`] value from a 64-bit floating point value.
95
+ /// Constructs a [`struct@ bf16`] value from a 64-bit floating point value.
96
96
///
97
97
/// This function is identical to [`from_f64`][Self::from_f64] except it never uses hardware
98
98
/// intrinsics, which allows it to be `const`. [`from_f64`][Self::from_f64] should be preferred
@@ -108,7 +108,7 @@ impl bf16 {
108
108
bf16 ( convert:: f64_to_bf16 ( value) )
109
109
}
110
110
111
- /// Converts a [`bf16`] into the underlying bit representation.
111
+ /// Converts a [`struct@ bf16`] into the underlying bit representation.
112
112
#[ inline]
113
113
#[ must_use]
114
114
pub const fn to_bits ( self ) -> u16 {
@@ -224,7 +224,7 @@ impl bf16 {
224
224
bf16:: from_bits ( u16:: from_ne_bytes ( bytes) )
225
225
}
226
226
227
- /// Converts a [`bf16`] value into an [`f32`] value.
227
+ /// Converts a [`struct@ bf16`] value into an [`f32`] value.
228
228
///
229
229
/// This conversion is lossless as all values can be represented exactly in [`f32`].
230
230
#[ inline]
@@ -233,7 +233,7 @@ impl bf16 {
233
233
self . to_f32_const ( )
234
234
}
235
235
236
- /// Converts a [`bf16`] value into an [`f32`] value.
236
+ /// Converts a [`struct@ bf16`] value into an [`f32`] value.
237
237
///
238
238
/// This function is identical to [`to_f32`][Self::to_f32] except it never uses hardware
239
239
/// intrinsics, which allows it to be `const`. [`to_f32`][Self::to_f32] should be preferred
@@ -246,7 +246,7 @@ impl bf16 {
246
246
convert:: bf16_to_f32 ( self . 0 )
247
247
}
248
248
249
- /// Converts a [`bf16`] value into an [`f64`] value.
249
+ /// Converts a [`struct@ bf16`] value into an [`f64`] value.
250
250
///
251
251
/// This conversion is lossless as all values can be represented exactly in [`f64`].
252
252
#[ inline]
@@ -255,7 +255,7 @@ impl bf16 {
255
255
self . to_f64_const ( )
256
256
}
257
257
258
- /// Converts a [`bf16`] value into an [`f64`] value.
258
+ /// Converts a [`struct@ bf16`] value into an [`f64`] value.
259
259
///
260
260
/// This function is identical to [`to_f64`][Self::to_f64] except it never uses hardware
261
261
/// intrinsics, which allows it to be `const`. [`to_f64`][Self::to_f64] should be preferred
@@ -649,7 +649,7 @@ impl bf16 {
649
649
650
650
/// Alternate serialize adapter for serializing as a float.
651
651
///
652
- /// By default, [`bf16`] serializes as a newtype of [`u16`]. This is an alternate serialize
652
+ /// By default, [`struct@ bf16`] serializes as a newtype of [`u16`]. This is an alternate serialize
653
653
/// implementation that serializes as an [`f32`] value. It is designed for use with
654
654
/// `serialize_with` serde attributes. Deserialization from `f32` values is already supported by
655
655
/// the default deserialize implementation.
@@ -675,7 +675,7 @@ impl bf16 {
675
675
676
676
/// Alternate serialize adapter for serializing as a string.
677
677
///
678
- /// By default, [`bf16`] serializes as a newtype of [`u16`]. This is an alternate serialize
678
+ /// By default, [`struct@ bf16`] serializes as a newtype of [`u16`]. This is an alternate serialize
679
679
/// implementation that serializes as a string value. It is designed for use with
680
680
/// `serialize_with` serde attributes. Deserialization from string values is already supported
681
681
/// by the default deserialize implementation.
@@ -702,87 +702,87 @@ impl bf16 {
702
702
serializer. serialize_str ( & self . to_string ( ) )
703
703
}
704
704
705
- /// Approximate number of [`bf16`] significant digits in base 10
705
+ /// Approximate number of [`struct@ bf16`] significant digits in base 10
706
706
pub const DIGITS : u32 = 2 ;
707
- /// [`bf16`]
707
+ /// [`struct@ bf16`]
708
708
/// [machine epsilon](https://en.wikipedia.org/wiki/Machine_epsilon) value
709
709
///
710
710
/// This is the difference between 1.0 and the next largest representable number.
711
711
pub const EPSILON : bf16 = bf16 ( 0x3C00u16 ) ;
712
- /// [`bf16`] positive Infinity (+∞)
712
+ /// [`struct@ bf16`] positive Infinity (+∞)
713
713
pub const INFINITY : bf16 = bf16 ( 0x7F80u16 ) ;
714
- /// Number of [`bf16`] significant digits in base 2
714
+ /// Number of [`struct@ bf16`] significant digits in base 2
715
715
pub const MANTISSA_DIGITS : u32 = 8 ;
716
- /// Largest finite [`bf16`] value
716
+ /// Largest finite [`struct@ bf16`] value
717
717
pub const MAX : bf16 = bf16 ( 0x7F7F ) ;
718
- /// Maximum possible [`bf16`] power of 10 exponent
718
+ /// Maximum possible [`struct@ bf16`] power of 10 exponent
719
719
pub const MAX_10_EXP : i32 = 38 ;
720
- /// Maximum possible [`bf16`] power of 2 exponent
720
+ /// Maximum possible [`struct@ bf16`] power of 2 exponent
721
721
pub const MAX_EXP : i32 = 128 ;
722
- /// Smallest finite [`bf16`] value
722
+ /// Smallest finite [`struct@ bf16`] value
723
723
pub const MIN : bf16 = bf16 ( 0xFF7F ) ;
724
- /// Minimum possible normal [`bf16`] power of 10 exponent
724
+ /// Minimum possible normal [`struct@ bf16`] power of 10 exponent
725
725
pub const MIN_10_EXP : i32 = -37 ;
726
- /// One greater than the minimum possible normal [`bf16`] power of 2 exponent
726
+ /// One greater than the minimum possible normal [`struct@ bf16`] power of 2 exponent
727
727
pub const MIN_EXP : i32 = -125 ;
728
- /// Smallest positive normal [`bf16`] value
728
+ /// Smallest positive normal [`struct@ bf16`] value
729
729
pub const MIN_POSITIVE : bf16 = bf16 ( 0x0080u16 ) ;
730
- /// [`bf16`] Not a Number (NaN)
730
+ /// [`struct@ bf16`] Not a Number (NaN)
731
731
pub const NAN : bf16 = bf16 ( 0x7FC0u16 ) ;
732
- /// [`bf16`] negative infinity (-∞).
732
+ /// [`struct@ bf16`] negative infinity (-∞).
733
733
pub const NEG_INFINITY : bf16 = bf16 ( 0xFF80u16 ) ;
734
- /// The radix or base of the internal representation of [`bf16`]
734
+ /// The radix or base of the internal representation of [`struct@ bf16`]
735
735
pub const RADIX : u32 = 2 ;
736
736
737
- /// Minimum positive subnormal [`bf16`] value
737
+ /// Minimum positive subnormal [`struct@ bf16`] value
738
738
pub const MIN_POSITIVE_SUBNORMAL : bf16 = bf16 ( 0x0001u16 ) ;
739
- /// Maximum subnormal [`bf16`] value
739
+ /// Maximum subnormal [`struct@ bf16`] value
740
740
pub const MAX_SUBNORMAL : bf16 = bf16 ( 0x007Fu16 ) ;
741
741
742
- /// [`bf16`] 1
742
+ /// [`struct@ bf16`] 1
743
743
pub const ONE : bf16 = bf16 ( 0x3F80u16 ) ;
744
- /// [`bf16`] 0
744
+ /// [`struct@ bf16`] 0
745
745
pub const ZERO : bf16 = bf16 ( 0x0000u16 ) ;
746
- /// [`bf16`] -0
746
+ /// [`struct@ bf16`] -0
747
747
pub const NEG_ZERO : bf16 = bf16 ( 0x8000u16 ) ;
748
- /// [`bf16`] -1
748
+ /// [`struct@ bf16`] -1
749
749
pub const NEG_ONE : bf16 = bf16 ( 0xBF80u16 ) ;
750
750
751
- /// [`bf16`] Euler's number (ℯ)
751
+ /// [`struct@ bf16`] Euler's number (ℯ)
752
752
pub const E : bf16 = bf16 ( 0x402Eu16 ) ;
753
- /// [`bf16`] Archimedes' constant (π)
753
+ /// [`struct@ bf16`] Archimedes' constant (π)
754
754
pub const PI : bf16 = bf16 ( 0x4049u16 ) ;
755
- /// [`bf16`] 1/π
755
+ /// [`struct@ bf16`] 1/π
756
756
pub const FRAC_1_PI : bf16 = bf16 ( 0x3EA3u16 ) ;
757
- /// [`bf16`] 1/√2
757
+ /// [`struct@ bf16`] 1/√2
758
758
pub const FRAC_1_SQRT_2 : bf16 = bf16 ( 0x3F35u16 ) ;
759
- /// [`bf16`] 2/π
759
+ /// [`struct@ bf16`] 2/π
760
760
pub const FRAC_2_PI : bf16 = bf16 ( 0x3F23u16 ) ;
761
- /// [`bf16`] 2/√π
761
+ /// [`struct@ bf16`] 2/√π
762
762
pub const FRAC_2_SQRT_PI : bf16 = bf16 ( 0x3F90u16 ) ;
763
- /// [`bf16`] π/2
763
+ /// [`struct@ bf16`] π/2
764
764
pub const FRAC_PI_2 : bf16 = bf16 ( 0x3FC9u16 ) ;
765
- /// [`bf16`] π/3
765
+ /// [`struct@ bf16`] π/3
766
766
pub const FRAC_PI_3 : bf16 = bf16 ( 0x3F86u16 ) ;
767
- /// [`bf16`] π/4
767
+ /// [`struct@ bf16`] π/4
768
768
pub const FRAC_PI_4 : bf16 = bf16 ( 0x3F49u16 ) ;
769
- /// [`bf16`] π/6
769
+ /// [`struct@ bf16`] π/6
770
770
pub const FRAC_PI_6 : bf16 = bf16 ( 0x3F06u16 ) ;
771
- /// [`bf16`] π/8
771
+ /// [`struct@ bf16`] π/8
772
772
pub const FRAC_PI_8 : bf16 = bf16 ( 0x3EC9u16 ) ;
773
- /// [`bf16`] 𝗅𝗇 10
773
+ /// [`struct@ bf16`] 𝗅𝗇 10
774
774
pub const LN_10 : bf16 = bf16 ( 0x4013u16 ) ;
775
- /// [`bf16`] 𝗅𝗇 2
775
+ /// [`struct@ bf16`] 𝗅𝗇 2
776
776
pub const LN_2 : bf16 = bf16 ( 0x3F31u16 ) ;
777
- /// [`bf16`] 𝗅𝗈𝗀₁₀ℯ
777
+ /// [`struct@ bf16`] 𝗅𝗈𝗀₁₀ℯ
778
778
pub const LOG10_E : bf16 = bf16 ( 0x3EDEu16 ) ;
779
- /// [`bf16`] 𝗅𝗈𝗀₁₀2
779
+ /// [`struct@ bf16`] 𝗅𝗈𝗀₁₀2
780
780
pub const LOG10_2 : bf16 = bf16 ( 0x3E9Au16 ) ;
781
- /// [`bf16`] 𝗅𝗈𝗀₂ℯ
781
+ /// [`struct@ bf16`] 𝗅𝗈𝗀₂ℯ
782
782
pub const LOG2_E : bf16 = bf16 ( 0x3FB9u16 ) ;
783
- /// [`bf16`] 𝗅𝗈𝗀₂10
783
+ /// [`struct@ bf16`] 𝗅𝗈𝗀₂10
784
784
pub const LOG2_10 : bf16 = bf16 ( 0x4055u16 ) ;
785
- /// [`bf16`] √2
785
+ /// [`struct@ bf16`] √2
786
786
pub const SQRT_2 : bf16 = bf16 ( 0x3FB5u16 ) ;
787
787
}
788
788
0 commit comments