fast_posit/posit/quire/
convert.rs1use super::*;
2
3impl<
4 const N: u32,
5 const ES: u32,
6 Int: crate::Int,
7 const SIZE: usize,
8> From<Posit<N, ES, Int>> for Quire<N, ES, SIZE> {
9 fn from(value: Posit<N, ES, Int>) -> Self {
10 if value == Posit::ZERO {
11 Self::ZERO
12 } else if value == Posit::NAR {
13 Self::NAR
14 } else {
15 let mut quire = Self::ZERO;
16 let decoded = unsafe { value.decode_regular() };
18 unsafe { quire.accumulate_decoded(decoded) };
20 quire
21 }
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28 use malachite::rational::Rational;
29
30 #[test]
40 fn posit_10_1_exhaustive() {
41 type P = Posit::<10, 1, i16>;
42 type Q = Quire::<10, 1, 128>;
43 for a in P::cases_exhaustive_all() {
44 assert_eq!(Rational::try_from(a), Rational::try_from(Q::from(a)))
45 }
46 }
47
48 #[test]
49 fn posit_10_2_exhaustive() {
50 type P = Posit::<10, 2, i16>;
51 type Q = Quire::<10, 2, 128>;
52 for a in P::cases_exhaustive_all() {
53 assert_eq!(Rational::try_from(a), Rational::try_from(Q::from(a)))
54 }
55 }
56
57 #[test]
58 fn posit_10_3_exhaustive() {
59 type P = Posit::<10, 3, i16>;
60 type Q = Quire::<10, 3, 128>;
61 for a in P::cases_exhaustive_all() {
62 assert_eq!(Rational::try_from(a), Rational::try_from(Q::from(a)))
63 }
64 }
65
66 #[test]
76 fn p8_exhaustive() {
77 for a in crate::p8::cases_exhaustive_all() {
78 assert_eq!(Rational::try_from(a), Rational::try_from(crate::q8::from(a)))
79 }
80 }
81
82 #[test]
83 fn p16_exhaustive() {
84 for a in crate::p16::cases_exhaustive_all() {
85 assert_eq!(Rational::try_from(a), Rational::try_from(crate::q16::from(a)))
86 }
87 }
88
89 use proptest::prelude::*;
90 const PROPTEST_CASES: u32 = if cfg!(debug_assertions) {0x1_0000} else {0x80_0000};
91 proptest!{
92 #![proptest_config(ProptestConfig::with_cases(PROPTEST_CASES))]
93
94 #[test]
95 fn p32_proptest(a in crate::p32::cases_proptest()) {
96 assert_eq!(Rational::try_from(a), Rational::try_from(crate::q32::from(a)))
97 }
98
99 #[test]
100 fn p64_proptest(a in crate::p64::cases_proptest()) {
101 assert_eq!(Rational::try_from(a), Rational::try_from(crate::q64::from(a)))
102 }
103 }
104
105 }