1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
macro_rules! deprecated_from_float {
(fn $method:ident($Float:ident) -> $Fixed:ident<$Frac:ident>) => {
comment!(
"Creates a fixed-point number from `",
stringify!($Float),
"`.
This method has been replaced by [`checked_from_float`].
[`checked_from_float`]: #method.checked_from_float
";
#[deprecated(since = "0.2.0", note = "replaced by checked_from_float")]
#[inline]
pub fn $method(val: $Float) -> Option<$Fixed<$Frac>> {
Self::checked_from_float(val)
}
);
};
}
macro_rules! deprecated_to_float {
(fn $method:ident($Fixed:ident) -> $Float:ident) => {
comment!(
"Converts the fixed-point number to `",
stringify!($Float),
"`.
This method has been replaced by [`to_float`].
[`to_float`]: #method.to_float
";
#[deprecated(since = "0.2.0", note = "replaced by to_float")]
#[inline]
pub fn $method(self) -> $Float {
self.to_float()
}
);
};
}
macro_rules! fixed_deprecated {
($Fixed:ident($Inner:ty)) => {
#[inline]
#[deprecated(since = "0.3.0", note = "renamed to int_nbits")]
pub fn int_bits() -> u32 {
Self::int_nbits()
}
#[inline]
#[deprecated(since = "0.3.0", note = "renamed to frac_nbits")]
pub fn frac_bits() -> u32 {
Self::frac_nbits()
}
#[deprecated(since = "0.2.0", note = "use f.ceil().to_int::<_>() instead")]
#[inline]
pub fn to_int_ceil(self) -> $Inner {
if let Some(ceil) = self.checked_ceil() {
ceil.to_int()
} else {
self.floor().to_int::<$Inner>() + 1
}
}
#[deprecated(since = "0.2.0", note = "use f.floor().to_int::<_>() instead")]
#[inline]
pub fn to_int_floor(self) -> $Inner {
if let Some(floor) = self.checked_floor() {
floor.to_int()
} else {
self.ceil().to_int::<$Inner>() - 1
}
}
#[deprecated(since = "0.2.0", note = "use f.round().to_int::<_>() instead")]
#[inline]
pub fn to_int_round(self) -> $Inner {
if let Some(round) = self.checked_round() {
round.to_int()
} else if let Some(floor) = self.checked_floor() {
floor.to_int::<$Inner>() + 1
} else {
self.ceil().to_int::<$Inner>() - 1
}
}
#[cfg(feature = "f16")]
deprecated_from_float! { fn from_f16(f16) -> $Fixed<Frac> }
deprecated_from_float! { fn from_f32(f32) -> $Fixed<Frac> }
deprecated_from_float! { fn from_f64(f64) -> $Fixed<Frac> }
#[cfg(feature = "f16")]
deprecated_to_float! { fn to_f16($Fixed) -> f16 }
deprecated_to_float! { fn to_f32($Fixed) -> f32 }
deprecated_to_float! { fn to_f64($Fixed) -> f64 }
};
}