• Home
  • Raw
  • Download

Lines Matching refs:bf16

37 pub struct bf16(u16);  struct
39 impl bf16 { impl
42 pub const fn from_bits(bits: u16) -> bf16 { in from_bits() argument
43 bf16(bits) in from_bits()
52 pub fn from_f32(value: f32) -> bf16 { in from_f32() argument
53 bf16(convert::f32_to_bf16(value)) in from_f32()
63 pub fn from_f64(value: f64) -> bf16 { in from_f64() argument
64 bf16(convert::f64_to_bf16(value)) in from_f64()
135 pub fn from_le_bytes(bytes: [u8; 2]) -> bf16 { in from_le_bytes() argument
136 bf16::from_bits(u16::from_le_bytes(bytes))
149 pub fn from_be_bytes(bytes: [u8; 2]) -> bf16 { in from_be_bytes() argument
150 bf16::from_bits(u16::from_be_bytes(bytes))
170 pub fn from_ne_bytes(bytes: [u8; 2]) -> bf16 { in from_ne_bytes() argument
171 bf16::from_bits(u16::from_ne_bytes(bytes))
328 pub fn signum(self) -> bf16 { in signum() argument
332 bf16::from_f32(-1.0) in signum()
334 bf16::from_f32(1.0) in signum()
388 pub const EPSILON: bf16 = bf16(0x3C00u16);
390 pub const INFINITY: bf16 = bf16(0x7F80u16);
394 pub const MAX: bf16 = bf16(0x7F7F);
400 pub const MIN: bf16 = bf16(0xFF7F);
406 pub const MIN_POSITIVE: bf16 = bf16(0x0080u16);
408 pub const NAN: bf16 = bf16(0x7FC0u16);
410 pub const NEG_INFINITY: bf16 = bf16(0xFF80u16);
415 pub const MIN_POSITIVE_SUBNORMAL: bf16 = bf16(0x0001u16);
417 pub const MAX_SUBNORMAL: bf16 = bf16(0x007Fu16);
420 pub const ONE: bf16 = bf16(0x3F80u16);
422 pub const ZERO: bf16 = bf16(0x0000u16);
424 pub const NEG_ZERO: bf16 = bf16(0x8000u16);
427 pub const E: bf16 = bf16(0x402Eu16);
429 pub const PI: bf16 = bf16(0x4049u16);
431 pub const FRAC_1_PI: bf16 = bf16(0x3EA3u16);
433 pub const FRAC_1_SQRT_2: bf16 = bf16(0x3F35u16);
435 pub const FRAC_2_PI: bf16 = bf16(0x3F23u16);
437 pub const FRAC_2_SQRT_PI: bf16 = bf16(0x3F90u16);
439 pub const FRAC_PI_2: bf16 = bf16(0x3FC9u16);
441 pub const FRAC_PI_3: bf16 = bf16(0x3F86u16);
443 pub const FRAC_PI_4: bf16 = bf16(0x3F49u16);
445 pub const FRAC_PI_6: bf16 = bf16(0x3F06u16);
447 pub const FRAC_PI_8: bf16 = bf16(0x3EC9u16);
449 pub const LN_10: bf16 = bf16(0x4013u16);
451 pub const LN_2: bf16 = bf16(0x3F31u16);
453 pub const LOG10_E: bf16 = bf16(0x3EDEu16);
455 pub const LOG10_2: bf16 = bf16(0x3E9Au16);
457 pub const LOG2_E: bf16 = bf16(0x3FB9u16);
459 pub const LOG2_10: bf16 = bf16(0x4055u16);
461 pub const SQRT_2: bf16 = bf16(0x3FB5u16);
464 impl From<bf16> for f32 {
466 fn from(x: bf16) -> f32 { in from()
471 impl From<bf16> for f64 {
473 fn from(x: bf16) -> f64 { in from()
478 impl From<i8> for bf16 { implementation
480 fn from(x: i8) -> bf16 { in from() argument
482 bf16::from_f32(f32::from(x)) in from()
486 impl From<u8> for bf16 { implementation
488 fn from(x: u8) -> bf16 { in from() argument
490 bf16::from_f32(f32::from(x)) in from()
494 impl PartialEq for bf16 { implementation
495 fn eq(&self, other: &bf16) -> bool { in eq()
504 impl PartialOrd for bf16 { implementation
505 fn partial_cmp(&self, other: &bf16) -> Option<Ordering> { in partial_cmp()
532 fn lt(&self, other: &bf16) -> bool { in lt()
547 fn le(&self, other: &bf16) -> bool { in le()
562 fn gt(&self, other: &bf16) -> bool { in gt()
577 fn ge(&self, other: &bf16) -> bool { in ge()
593 impl FromStr for bf16 { implementation
595 fn from_str(src: &str) -> Result<bf16, ParseFloatError> { in from_str() argument
596 f32::from_str(src).map(bf16::from_f32) in from_str()
600 impl Debug for bf16 { implementation
606 impl Display for bf16 { implementation
612 impl LowerExp for bf16 { implementation
618 impl UpperExp for bf16 { implementation
624 impl Binary for bf16 { implementation
630 impl Octal for bf16 { implementation
636 impl LowerHex for bf16 { implementation
642 impl UpperHex for bf16 { implementation
650 use super::bf16;
653 impl ToPrimitive for bf16 { implementation
686 impl FromPrimitive for bf16 { implementation
734 let one = bf16::from_f32(1.0); in test_bf16_consts_from_f32()
735 let zero = bf16::from_f32(0.0); in test_bf16_consts_from_f32()
736 let neg_zero = bf16::from_f32(-0.0); in test_bf16_consts_from_f32()
737 let inf = bf16::from_f32(core::f32::INFINITY); in test_bf16_consts_from_f32()
738 let neg_inf = bf16::from_f32(core::f32::NEG_INFINITY); in test_bf16_consts_from_f32()
739 let nan = bf16::from_f32(core::f32::NAN); in test_bf16_consts_from_f32()
741 assert_eq!(bf16::ONE, one); in test_bf16_consts_from_f32()
742 assert_eq!(bf16::ZERO, zero); in test_bf16_consts_from_f32()
743 assert_eq!(bf16::NEG_ZERO, neg_zero); in test_bf16_consts_from_f32()
744 assert_eq!(bf16::INFINITY, inf); in test_bf16_consts_from_f32()
745 assert_eq!(bf16::NEG_INFINITY, neg_inf); in test_bf16_consts_from_f32()
747 assert!(bf16::NAN.is_nan()); in test_bf16_consts_from_f32()
749 let e = bf16::from_f32(core::f32::consts::E); in test_bf16_consts_from_f32()
750 let pi = bf16::from_f32(core::f32::consts::PI); in test_bf16_consts_from_f32()
751 let frac_1_pi = bf16::from_f32(core::f32::consts::FRAC_1_PI); in test_bf16_consts_from_f32()
752 let frac_1_sqrt_2 = bf16::from_f32(core::f32::consts::FRAC_1_SQRT_2); in test_bf16_consts_from_f32()
753 let frac_2_pi = bf16::from_f32(core::f32::consts::FRAC_2_PI); in test_bf16_consts_from_f32()
754 let frac_2_sqrt_pi = bf16::from_f32(core::f32::consts::FRAC_2_SQRT_PI); in test_bf16_consts_from_f32()
755 let frac_pi_2 = bf16::from_f32(core::f32::consts::FRAC_PI_2); in test_bf16_consts_from_f32()
756 let frac_pi_3 = bf16::from_f32(core::f32::consts::FRAC_PI_3); in test_bf16_consts_from_f32()
757 let frac_pi_4 = bf16::from_f32(core::f32::consts::FRAC_PI_4); in test_bf16_consts_from_f32()
758 let frac_pi_6 = bf16::from_f32(core::f32::consts::FRAC_PI_6); in test_bf16_consts_from_f32()
759 let frac_pi_8 = bf16::from_f32(core::f32::consts::FRAC_PI_8); in test_bf16_consts_from_f32()
760 let ln_10 = bf16::from_f32(core::f32::consts::LN_10); in test_bf16_consts_from_f32()
761 let ln_2 = bf16::from_f32(core::f32::consts::LN_2); in test_bf16_consts_from_f32()
762 let log10_e = bf16::from_f32(core::f32::consts::LOG10_E); in test_bf16_consts_from_f32()
764 let log10_2 = bf16::from_f32(2f32.log10()); in test_bf16_consts_from_f32()
765 let log2_e = bf16::from_f32(core::f32::consts::LOG2_E); in test_bf16_consts_from_f32()
767 let log2_10 = bf16::from_f32(10f32.log2()); in test_bf16_consts_from_f32()
768 let sqrt_2 = bf16::from_f32(core::f32::consts::SQRT_2); in test_bf16_consts_from_f32()
770 assert_eq!(bf16::E, e); in test_bf16_consts_from_f32()
771 assert_eq!(bf16::PI, pi); in test_bf16_consts_from_f32()
772 assert_eq!(bf16::FRAC_1_PI, frac_1_pi); in test_bf16_consts_from_f32()
773 assert_eq!(bf16::FRAC_1_SQRT_2, frac_1_sqrt_2); in test_bf16_consts_from_f32()
774 assert_eq!(bf16::FRAC_2_PI, frac_2_pi); in test_bf16_consts_from_f32()
775 assert_eq!(bf16::FRAC_2_SQRT_PI, frac_2_sqrt_pi); in test_bf16_consts_from_f32()
776 assert_eq!(bf16::FRAC_PI_2, frac_pi_2); in test_bf16_consts_from_f32()
777 assert_eq!(bf16::FRAC_PI_3, frac_pi_3); in test_bf16_consts_from_f32()
778 assert_eq!(bf16::FRAC_PI_4, frac_pi_4); in test_bf16_consts_from_f32()
779 assert_eq!(bf16::FRAC_PI_6, frac_pi_6); in test_bf16_consts_from_f32()
780 assert_eq!(bf16::FRAC_PI_8, frac_pi_8); in test_bf16_consts_from_f32()
781 assert_eq!(bf16::LN_10, ln_10); in test_bf16_consts_from_f32()
782 assert_eq!(bf16::LN_2, ln_2); in test_bf16_consts_from_f32()
783 assert_eq!(bf16::LOG10_E, log10_e); in test_bf16_consts_from_f32()
784 assert_eq!(bf16::LOG10_2, log10_2); in test_bf16_consts_from_f32()
785 assert_eq!(bf16::LOG2_E, log2_e); in test_bf16_consts_from_f32()
786 assert_eq!(bf16::LOG2_10, log2_10); in test_bf16_consts_from_f32()
787 assert_eq!(bf16::SQRT_2, sqrt_2); in test_bf16_consts_from_f32()
792 let one = bf16::from_f64(1.0); in test_bf16_consts_from_f64()
793 let zero = bf16::from_f64(0.0); in test_bf16_consts_from_f64()
794 let neg_zero = bf16::from_f64(-0.0); in test_bf16_consts_from_f64()
795 let inf = bf16::from_f64(core::f64::INFINITY); in test_bf16_consts_from_f64()
796 let neg_inf = bf16::from_f64(core::f64::NEG_INFINITY); in test_bf16_consts_from_f64()
797 let nan = bf16::from_f64(core::f64::NAN); in test_bf16_consts_from_f64()
799 assert_eq!(bf16::ONE, one); in test_bf16_consts_from_f64()
800 assert_eq!(bf16::ZERO, zero); in test_bf16_consts_from_f64()
801 assert_eq!(bf16::NEG_ZERO, neg_zero); in test_bf16_consts_from_f64()
802 assert_eq!(bf16::INFINITY, inf); in test_bf16_consts_from_f64()
803 assert_eq!(bf16::NEG_INFINITY, neg_inf); in test_bf16_consts_from_f64()
805 assert!(bf16::NAN.is_nan()); in test_bf16_consts_from_f64()
807 let e = bf16::from_f64(core::f64::consts::E); in test_bf16_consts_from_f64()
808 let pi = bf16::from_f64(core::f64::consts::PI); in test_bf16_consts_from_f64()
809 let frac_1_pi = bf16::from_f64(core::f64::consts::FRAC_1_PI); in test_bf16_consts_from_f64()
810 let frac_1_sqrt_2 = bf16::from_f64(core::f64::consts::FRAC_1_SQRT_2); in test_bf16_consts_from_f64()
811 let frac_2_pi = bf16::from_f64(core::f64::consts::FRAC_2_PI); in test_bf16_consts_from_f64()
812 let frac_2_sqrt_pi = bf16::from_f64(core::f64::consts::FRAC_2_SQRT_PI); in test_bf16_consts_from_f64()
813 let frac_pi_2 = bf16::from_f64(core::f64::consts::FRAC_PI_2); in test_bf16_consts_from_f64()
814 let frac_pi_3 = bf16::from_f64(core::f64::consts::FRAC_PI_3); in test_bf16_consts_from_f64()
815 let frac_pi_4 = bf16::from_f64(core::f64::consts::FRAC_PI_4); in test_bf16_consts_from_f64()
816 let frac_pi_6 = bf16::from_f64(core::f64::consts::FRAC_PI_6); in test_bf16_consts_from_f64()
817 let frac_pi_8 = bf16::from_f64(core::f64::consts::FRAC_PI_8); in test_bf16_consts_from_f64()
818 let ln_10 = bf16::from_f64(core::f64::consts::LN_10); in test_bf16_consts_from_f64()
819 let ln_2 = bf16::from_f64(core::f64::consts::LN_2); in test_bf16_consts_from_f64()
820 let log10_e = bf16::from_f64(core::f64::consts::LOG10_E); in test_bf16_consts_from_f64()
822 let log10_2 = bf16::from_f64(2f64.log10()); in test_bf16_consts_from_f64()
823 let log2_e = bf16::from_f64(core::f64::consts::LOG2_E); in test_bf16_consts_from_f64()
825 let log2_10 = bf16::from_f64(10f64.log2()); in test_bf16_consts_from_f64()
826 let sqrt_2 = bf16::from_f64(core::f64::consts::SQRT_2); in test_bf16_consts_from_f64()
828 assert_eq!(bf16::E, e); in test_bf16_consts_from_f64()
829 assert_eq!(bf16::PI, pi); in test_bf16_consts_from_f64()
830 assert_eq!(bf16::FRAC_1_PI, frac_1_pi); in test_bf16_consts_from_f64()
831 assert_eq!(bf16::FRAC_1_SQRT_2, frac_1_sqrt_2); in test_bf16_consts_from_f64()
832 assert_eq!(bf16::FRAC_2_PI, frac_2_pi); in test_bf16_consts_from_f64()
833 assert_eq!(bf16::FRAC_2_SQRT_PI, frac_2_sqrt_pi); in test_bf16_consts_from_f64()
834 assert_eq!(bf16::FRAC_PI_2, frac_pi_2); in test_bf16_consts_from_f64()
835 assert_eq!(bf16::FRAC_PI_3, frac_pi_3); in test_bf16_consts_from_f64()
836 assert_eq!(bf16::FRAC_PI_4, frac_pi_4); in test_bf16_consts_from_f64()
837 assert_eq!(bf16::FRAC_PI_6, frac_pi_6); in test_bf16_consts_from_f64()
838 assert_eq!(bf16::FRAC_PI_8, frac_pi_8); in test_bf16_consts_from_f64()
839 assert_eq!(bf16::LN_10, ln_10); in test_bf16_consts_from_f64()
840 assert_eq!(bf16::LN_2, ln_2); in test_bf16_consts_from_f64()
841 assert_eq!(bf16::LOG10_E, log10_e); in test_bf16_consts_from_f64()
842 assert_eq!(bf16::LOG10_2, log10_2); in test_bf16_consts_from_f64()
843 assert_eq!(bf16::LOG2_E, log2_e); in test_bf16_consts_from_f64()
844 assert_eq!(bf16::LOG2_10, log2_10); in test_bf16_consts_from_f64()
845 assert_eq!(bf16::SQRT_2, sqrt_2); in test_bf16_consts_from_f64()
856 let nan16_from_64 = bf16::from_f64(nan64); in test_nan_conversion_to_smaller()
857 let neg_nan16_from_64 = bf16::from_f64(neg_nan64); in test_nan_conversion_to_smaller()
858 let nan16_from_32 = bf16::from_f32(nan32); in test_nan_conversion_to_smaller()
859 let neg_nan16_from_32 = bf16::from_f32(neg_nan32); in test_nan_conversion_to_smaller()
875 let nan16 = bf16::from_bits(0x7F81u16); in test_nan_conversion_to_larger()
876 let neg_nan16 = bf16::from_bits(0xFF81u16); in test_nan_conversion_to_larger()
900 let f = bf16::from_f32(7.0); in test_bf16_to_f32()
904 let f = bf16::from_f32(7.1); in test_bf16_to_f32()
907 assert!(diff <= 4.0 * bf16::EPSILON.to_f32()); in test_bf16_to_f32()
910 assert_eq!(bf16::from_bits(0x0001).to_f32(), tiny32); in test_bf16_to_f32()
911 assert_eq!(bf16::from_bits(0x0005).to_f32(), 5.0 * tiny32); in test_bf16_to_f32()
913 assert_eq!(bf16::from_bits(0x0001), bf16::from_f32(tiny32)); in test_bf16_to_f32()
914 assert_eq!(bf16::from_bits(0x0005), bf16::from_f32(5.0 * tiny32)); in test_bf16_to_f32()
919 let f = bf16::from_f64(7.0); in test_bf16_to_f64()
923 let f = bf16::from_f64(7.1); in test_bf16_to_f64()
926 assert!(diff <= 4.0 * bf16::EPSILON.to_f64()); in test_bf16_to_f64()
929 assert_eq!(bf16::from_bits(0x0001).to_f64(), tiny64); in test_bf16_to_f64()
930 assert_eq!(bf16::from_bits(0x0005).to_f64(), 5.0 * tiny64); in test_bf16_to_f64()
932 assert_eq!(bf16::from_bits(0x0001), bf16::from_f64(tiny64)); in test_bf16_to_f64()
933 assert_eq!(bf16::from_bits(0x0005), bf16::from_f64(5.0 * tiny64)); in test_bf16_to_f64()
938 let zero = bf16::from_f64(0.0); in test_comparisons()
939 let one = bf16::from_f64(1.0); in test_comparisons()
940 let neg_zero = bf16::from_f64(-0.0); in test_comparisons()
941 let neg_one = bf16::from_f64(-1.0); in test_comparisons()
993 let min_sub = bf16::from_bits(1); in round_to_even_f32()
995 assert_eq!(bf16::from_f32(min_sub_f).to_bits(), min_sub.to_bits()); in round_to_even_f32()
1002 bf16::from_f32(min_sub_f * 0.49).to_bits(), in round_to_even_f32()
1006 bf16::from_f32(min_sub_f * 0.50).to_bits(), in round_to_even_f32()
1010 bf16::from_f32(min_sub_f * 0.51).to_bits(), in round_to_even_f32()
1018 bf16::from_f32(min_sub_f * 1.49).to_bits(), in round_to_even_f32()
1022 bf16::from_f32(min_sub_f * 1.50).to_bits(), in round_to_even_f32()
1026 bf16::from_f32(min_sub_f * 1.51).to_bits(), in round_to_even_f32()
1034 bf16::from_f32(min_sub_f * 2.49).to_bits(), in round_to_even_f32()
1038 bf16::from_f32(min_sub_f * 2.50).to_bits(), in round_to_even_f32()
1042 bf16::from_f32(min_sub_f * 2.51).to_bits(), in round_to_even_f32()
1047 bf16::from_f32(250.49f32).to_bits(), in round_to_even_f32()
1048 bf16::from_f32(250.0).to_bits() in round_to_even_f32()
1051 bf16::from_f32(250.50f32).to_bits(), in round_to_even_f32()
1052 bf16::from_f32(250.0).to_bits() in round_to_even_f32()
1055 bf16::from_f32(250.51f32).to_bits(), in round_to_even_f32()
1056 bf16::from_f32(251.0).to_bits() in round_to_even_f32()
1059 bf16::from_f32(251.49f32).to_bits(), in round_to_even_f32()
1060 bf16::from_f32(251.0).to_bits() in round_to_even_f32()
1063 bf16::from_f32(251.50f32).to_bits(), in round_to_even_f32()
1064 bf16::from_f32(252.0).to_bits() in round_to_even_f32()
1067 bf16::from_f32(251.51f32).to_bits(), in round_to_even_f32()
1068 bf16::from_f32(252.0).to_bits() in round_to_even_f32()
1071 bf16::from_f32(252.49f32).to_bits(), in round_to_even_f32()
1072 bf16::from_f32(252.0).to_bits() in round_to_even_f32()
1075 bf16::from_f32(252.50f32).to_bits(), in round_to_even_f32()
1076 bf16::from_f32(252.0).to_bits() in round_to_even_f32()
1079 bf16::from_f32(252.51f32).to_bits(), in round_to_even_f32()
1080 bf16::from_f32(253.0).to_bits() in round_to_even_f32()
1088 let min_sub = bf16::from_bits(1); in round_to_even_f64()
1090 assert_eq!(bf16::from_f64(min_sub_f).to_bits(), min_sub.to_bits()); in round_to_even_f64()
1097 bf16::from_f64(min_sub_f * 0.49).to_bits(), in round_to_even_f64()
1101 bf16::from_f64(min_sub_f * 0.50).to_bits(), in round_to_even_f64()
1105 bf16::from_f64(min_sub_f * 0.51).to_bits(), in round_to_even_f64()
1113 bf16::from_f64(min_sub_f * 1.49).to_bits(), in round_to_even_f64()
1117 bf16::from_f64(min_sub_f * 1.50).to_bits(), in round_to_even_f64()
1121 bf16::from_f64(min_sub_f * 1.51).to_bits(), in round_to_even_f64()
1129 bf16::from_f64(min_sub_f * 2.49).to_bits(), in round_to_even_f64()
1133 bf16::from_f64(min_sub_f * 2.50).to_bits(), in round_to_even_f64()
1137 bf16::from_f64(min_sub_f * 2.51).to_bits(), in round_to_even_f64()
1142 bf16::from_f64(250.49f64).to_bits(), in round_to_even_f64()
1143 bf16::from_f64(250.0).to_bits() in round_to_even_f64()
1146 bf16::from_f64(250.50f64).to_bits(), in round_to_even_f64()
1147 bf16::from_f64(250.0).to_bits() in round_to_even_f64()
1150 bf16::from_f64(250.51f64).to_bits(), in round_to_even_f64()
1151 bf16::from_f64(251.0).to_bits() in round_to_even_f64()
1154 bf16::from_f64(251.49f64).to_bits(), in round_to_even_f64()
1155 bf16::from_f64(251.0).to_bits() in round_to_even_f64()
1158 bf16::from_f64(251.50f64).to_bits(), in round_to_even_f64()
1159 bf16::from_f64(252.0).to_bits() in round_to_even_f64()
1162 bf16::from_f64(251.51f64).to_bits(), in round_to_even_f64()
1163 bf16::from_f64(252.0).to_bits() in round_to_even_f64()
1166 bf16::from_f64(252.49f64).to_bits(), in round_to_even_f64()
1167 bf16::from_f64(252.0).to_bits() in round_to_even_f64()
1170 bf16::from_f64(252.50f64).to_bits(), in round_to_even_f64()
1171 bf16::from_f64(252.0).to_bits() in round_to_even_f64()
1174 bf16::from_f64(252.51f64).to_bits(), in round_to_even_f64()
1175 bf16::from_f64(253.0).to_bits() in round_to_even_f64()
1179 impl quickcheck::Arbitrary for bf16 { implementation
1182 bf16(g.gen()) in arbitrary()
1187 fn qc_roundtrip_bf16_f32_is_identity(f: bf16) -> bool { in qc_roundtrip_bf16_f32_is_identity()
1188 let roundtrip = bf16::from_f32(f.to_f32()); in qc_roundtrip_bf16_f32_is_identity()
1197 fn qc_roundtrip_bf16_f64_is_identity(f: bf16) -> bool { in qc_roundtrip_bf16_f64_is_identity()
1198 let roundtrip = bf16::from_f64(f.to_f64()); in qc_roundtrip_bf16_f64_is_identity()