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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
//! This file contains the implementation of the rounding algorithm and the related functions & types.
// Adapters to convert runtime dispatched calls into const-inlined methods.
// This allows reducing the codesize for the common case of no increment.
pub ;
pub
/// Mode used in a unsigned rounding operations.
///
/// # Comparative table of all the rounding modes, including the signed and unsigned ones.
///
/// | Value | `Ceil` | `Expand` | `Floor` | `Trunc` | `HalfCeil` | `HalfExpand` | `HalfFloor` | `HalfTrunc` | `HalfEven` |
/// |:-----:|:----:|:------:|:-----:|:-----:|:--------:|:----------:|:---------:|:---------:|:--------:|
/// | +1.8 | +2 | +2 | +1 | +1 | +2 | +2 | +2 | +2 | +2 |
/// | +1.5 | " | " | " | " | " | " | +1 | +1 | " |
/// | +1.2 | " | " | " | " | +1 | +1 | " | " | +1 |
/// | +0.8 | +1 | +1 | 0 | 0 | " | " | " | " | " |
/// | +0.5 | " | " | " | " | " | " | 0 | 0 | 0 |
/// | +0.2 | " | " | " | " | 0 | 0 | " | " | " |
/// | -0.2 | 0 | -1 | -1 | " | " | " | " | " | " |
/// | -0.5 | " | " | " | " | " | -1 | -1 | " | " |
/// | -0.8 | " | " | " | " | -1 | " | " | -1 | -1 |
/// | -1.2 | -1 | -2 | -2 | -1 | " | " | " | " | " |
/// | -1.5 | " | " | " | " | " | -2 | -2 | " | -2 |
/// | -1.8 | " | " | " | " | -2 | " | " | -2 | " |
///
/// NOTE:
/// - `Ceil`, `Floor`, `HalfCeil` and `HalfFloor` are part of the [`SignedRoundingMode`] enum.
/// Mode used in a signed rounding operations.
///
/// NOTE:
/// - You can find the comparative table of all the rounding modes in the [`UnsignedRoundingMode`] documentation.
/// Increment used in a rounding operation.
///
/// Forces a rounding operation to round to only multiples of the specified increment.
///
/// # Example
///
/// ```
/// use fixed_decimal::{Decimal, RoundingIncrement, SignedRoundingMode, UnsignedRoundingMode};
/// use writeable::assert_writeable_eq;
/// # use std::str::FromStr;
/// let dec = Decimal::from_str("-7.266").unwrap();
/// let mode = SignedRoundingMode::Unsigned(UnsignedRoundingMode::Expand);
/// let increments = [
/// // .266 normally expands to .27 when rounding on position -2...
/// (RoundingIncrement::MultiplesOf1, "-7.27"),
/// // ...however, when rounding to multiples of 2, .266 expands to .28, since the next multiple
/// // of 2 bigger than the least significant digit of the rounded value (7) is 8.
/// (RoundingIncrement::MultiplesOf2, "-7.28"),
/// // .266 expands to .30, since the next multiple of 5 bigger than 7 is 10.
/// (RoundingIncrement::MultiplesOf5, "-7.30"),
/// // .266 expands to .50, since the next multiple of 25 bigger than 27 is 50.
/// // Note how we compare against 27 instead of only 7, because the increment applies to
/// // the two least significant digits of the rounded value instead of only the least
/// // significant digit.
/// (RoundingIncrement::MultiplesOf25, "-7.50"),
/// ];
///
/// for (increment, expected) in increments {
/// assert_writeable_eq!(
/// dec.clone().rounded_with_mode_and_increment(
/// -2,
/// mode,
/// increment
/// ),
/// expected
/// );
/// }
/// ```
/// Specifies the precision of a floating point value when constructing a Decimal.
///
/// **The primary definition of this type is in the [`fixed_decimal`](https://docs.rs/fixed_decimal) crate. Other ICU4X crates re-export it for convenience.**
///
/// IEEE 754 is a representation of a point on the number line. On the other hand, Decimal
/// specifies not only the point on the number line but also the precision of the number to a
/// specific power of 10. This enum augments a floating-point value with the additional
/// information required by Decimal.