Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SignedFixedDecimal and UnsignedFixedDecimal #5667

Open
wants to merge 131 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
b5517cb
First step into implementing the sign fixed decimal
younies Oct 8, 2024
c557cc0
implement SignedDecimal
younies Oct 10, 2024
89ee37f
Move important functions
younies Oct 10, 2024
8194482
Fix most unsinged int issues
younies Oct 10, 2024
1ec4607
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Oct 10, 2024
9c52868
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Oct 17, 2024
f3a4e1e
fix fmt
younies Oct 17, 2024
0819754
Add from_no_sign
younies Oct 17, 2024
b292bc7
Refactor module imports in fixed_decimal crate
younies Oct 17, 2024
797a27e
Refactor module imports and add rounding module
younies Oct 17, 2024
3488f02
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Oct 21, 2024
efaeb0b
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Oct 22, 2024
d0378db
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Oct 23, 2024
69f9a96
Refactor decimal module and rounding logic
younies Oct 23, 2024
69a4602
Refactor decimal module and rounding logic
younies Oct 23, 2024
0170adf
Refactor decimal module and rounding logic: Make internal expansion a…
younies Oct 23, 2024
eeb6c0b
Refactor decimal module and rounding logic: Improve handling of sign …
younies Oct 23, 2024
b17592e
fix the write to
younies Oct 23, 2024
f98341e
Import the needed test cases and functions
younies Oct 23, 2024
6f4bfa1
fix FrixedInteger
younies Oct 23, 2024
6f6c68e
fix decimal.rs
younies Oct 23, 2024
55a8074
fix fixed integer
younies Oct 23, 2024
0f3b6e8
copy rounding to signed_rounding
younies Oct 23, 2024
401a9fd
fix signed_rounding
younies Oct 23, 2024
6cd257b
fix rounding.rs
younies Oct 23, 2024
87734ef
small fixes
younies Oct 23, 2024
522969f
fix the formatter of fixed decimal
younies Oct 24, 2024
2dab6ae
Fix compact decimal
younies Oct 24, 2024
6b2f7cf
update permyriad.rs
younies Oct 24, 2024
2900aa4
add signed_fixed_decimal benchmark
younies Oct 24, 2024
f2a1d4a
Fix from f64
younies Oct 24, 2024
94ed10f
fix plurals
younies Oct 24, 2024
3c47291
fix datetime.rs
younies Oct 24, 2024
c7e0867
Refactor CompactDecimalFormatter to use SignedFixedDecimal instead of…
younies Oct 24, 2024
25af730
Refactor CompactDecimalFormatter to use SignedFixedDecimal instead of…
younies Oct 24, 2024
b5eb957
Refactor CompactDecimalFormatter to use SignedFixedDecimal instead of…
younies Oct 24, 2024
c862d66
Refactor CompactDecimalFormatter to use SignedFixedDecimal instead of…
younies Oct 24, 2024
126eb14
Refactor CompactDecimalFormatter to use SignedFixedDecimal instead of…
younies Oct 24, 2024
6eed793
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Oct 28, 2024
ca17e08
Refactor variable name in Signed struct
younies Oct 28, 2024
853b39b
Refactor variable name in Signed struct
younies Oct 28, 2024
62d40a8
Refactor FFI fixed decimal
younies Oct 28, 2024
b4ad9f4
Fix other places
younies Oct 28, 2024
b94836c
Refactor PluralOperands creation to use SignedFixedDecimal instead of…
younies Oct 28, 2024
a9fe703
Refactor variations.rs: Remove unused structs WithCompactExponent and…
younies Oct 28, 2024
86ec2b0
Refactor variations.rs: comment unused structs WithCompactExponent an…
younies Oct 29, 2024
9b8bb6e
Refactor variations.rs: move FloatPrecision
younies Oct 29, 2024
b69db8b
Refactor decimal.rs : fix types
younies Oct 29, 2024
6d75608
Refactor variations.rs: comment unused structs WithCompactExponent an…
younies Oct 29, 2024
8d2300e
Refactor compact.rs: Update struct name to SignedFixedDecimal
younies Oct 29, 2024
b8c65fb
Use `DeRef` and `DeRefMut`
younies Oct 29, 2024
25b6944
remove
younies Oct 29, 2024
18f9cdf
Refactor signed_decimal.rs: Remove unused methods and add TODOs
younies Oct 29, 2024
9e8f306
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Oct 30, 2024
a458474
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Nov 1, 2024
286e071
Refactor signed to delete multipy pow10 and rounding tests to use mul…
younies Nov 1, 2024
5ddfb1f
Refactor rounding modes to introduce SignedRoundingMode and UnsignedR…
younies Nov 1, 2024
4d404e2
Refactor signed decimal to use the new roundings
younies Nov 1, 2024
6de5ad7
Refactor rounding benchmarks to use new SignedRoundingMode and Unsign…
younies Nov 1, 2024
058a6ba
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Nov 4, 2024
65c96d2
Refactor rounding tests to use UnsignedRoundingMode enums
younies Nov 4, 2024
c8467ee
Refactor fixed_decimal example to use mutable variable for multiplica…
younies Nov 4, 2024
2d34dd3
Refactor format_fixed_decimal to use mutable variable for significand…
younies Nov 4, 2024
473df73
Refactor test_grouper to use mutable variable for SignedFixedDecimal …
younies Nov 4, 2024
f0af932
Remove unused half_ceil_to_increment_internal method from UnsignedFix…
younies Nov 4, 2024
df26d31
Remove unused half_floor_to_increment_internal method from UnsignedFi…
younies Nov 4, 2024
b863dea
Refactor SignedFixedDecimal multiplication to use mutable variable
younies Nov 4, 2024
c593589
Add separate rounding modes for unsigned and signed fixed decimals
younies Nov 4, 2024
dd16268
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Nov 5, 2024
89b6913
Merge branch 'main' into add-sign-fixeddecimal
younies Nov 5, 2024
047e075
Update examples in UnsignedFixedDecimal to use u32 literals for clarity
younies Nov 5, 2024
f4c99f1
Update documentation examples in CompactDecimal to use SignedFixedDec…
younies Nov 5, 2024
d495f1b
Remove floor and floored methods from UnsignedFixedDecimal and their …
younies Nov 5, 2024
37f832f
Remove floor_to_increment_internal method from UnsignedFixedDecimal
younies Nov 5, 2024
1a06ffa
Remove ceil and ceiled methods from UnsignedFixedDecimal and their as…
younies Nov 5, 2024
558087b
Remove outdated examples from UnsignedFixedDecimal documentation
younies Nov 5, 2024
3ed6989
Remove unused ceil_to_increment_internal method from UnsignedFixedDec…
younies Nov 5, 2024
5a3e800
Remove outdated rounding examples from UnsignedFixedDecimal documenta…
younies Nov 5, 2024
37658c8
Update UnsignedFixedDecimal documentation examples for clarity and re…
younies Nov 5, 2024
901934d
Refactor UnsignedFixedDecimal documentation: update examples for clar…
younies Nov 5, 2024
391807d
Update documentation for FixedDecimal: clarify API usage and examples…
younies Nov 5, 2024
5427740
Update examples in SignedRoundingMode documentation to use SignedFixe…
younies Nov 5, 2024
66f3dd6
Update documentation examples in SignedFixedDecimal to use SignedFixe…
younies Nov 5, 2024
34daff2
Refactor ScientificDecimal to use SignedFixedDecimal instead of Unsig…
younies Nov 5, 2024
840f41f
Update UnsignedFixedDecimal documentation to reflect error handling f…
younies Nov 5, 2024
09fc8d8
Update documentation and examples to use SignedFixedDecimal instead o…
younies Nov 5, 2024
ccfcfa7
Update documentation to use SignedFixedDecimal instead of FixedDecimal
younies Nov 5, 2024
1565d37
Remove test cases for negative inputs in UnsignedFixedDecimal tests
younies Nov 5, 2024
e808318
Merge branch 'main' into add-sign-fixeddecimal
younies Nov 5, 2024
89ab41b
Fix documentation to use SignedFixedDecimal instead of FixedDecimal i…
younies Nov 5, 2024
b717350
Update documentation to replace FixedDecimal with SignedFixedDecimal …
younies Nov 5, 2024
aefe9f4
Update documentation to clarify formatting requirements for FixedDeci…
younies Nov 6, 2024
9ad972d
Fix Diplomat: Refactor FixedDecimal to SignedFixedDecimal and update …
younies Nov 6, 2024
a40bd1f
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Nov 11, 2024
b8678e6
Refactor datetime formatting to use SignedFixedDecimal
younies Nov 11, 2024
8d05ac2
Refactor time zone formatting to use SignedFixedDecimal
younies Nov 11, 2024
922d8c0
Refactor rounding tests to remove negative cases and adjust expected …
younies Nov 11, 2024
9e512ee
Refactor imports in decimal modules to streamline dependencies
younies Nov 11, 2024
62f7a79
fix fmt
younies Nov 11, 2024
eafd3e6
Refactor duration formatting to eliminate unnecessary cloning and fix…
younies Nov 11, 2024
ee39ebe
Refactor imports in decimal modules to consolidate dependencies
younies Nov 11, 2024
0b09f57
Remove unused feature flag for ryu in fixed_decimal module
younies Nov 11, 2024
f2ce7ef
Update documentation to reference UnsignedFixedDecimal and SignedFixe…
younies Nov 11, 2024
5f522c6
Update documentation to reference UnsignedFixedDecimal in SignedFixed…
younies Nov 12, 2024
43199ae
Refactor rounding mode definitions: remove unused files and introduce…
younies Nov 12, 2024
459a608
fix fmt
younies Nov 12, 2024
c68e117
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Nov 12, 2024
989224e
Introduce a constructor for SignedFixedDecimal and refactor its usage…
younies Nov 12, 2024
6661a58
cargo make diplomat-coverage
younies Nov 12, 2024
ac916bd
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Nov 13, 2024
d98a628
Update references from FixedDecimal to SignedFixedDecimal and add mis…
younies Nov 13, 2024
630ee22
Replace FixedDecimal with SignedFixedDecimal in tests and format func…
younies Nov 13, 2024
2156d7f
Replace FixedDecimal with SignedFixedDecimal in fixeddecimal.cpp
younies Nov 13, 2024
772c685
Replace FixedDecimal with SignedFixedDecimal in JS and TypeScript tut…
younies Nov 13, 2024
5217ac0
Update documentation to replace FixedDecimal with SignedFixedDecimal …
younies Nov 13, 2024
226616e
Replace FixedDecimal with SignedFixedDecimal in ICU test
younies Nov 13, 2024
9d4b32f
Replace FixedDecimal with SignedFixedDecimal in JS tiny loader
younies Nov 13, 2024
c11070c
Replace SignedFixedDecimalFormatter references with FixedDecimalForma…
younies Nov 13, 2024
24dbcb4
Refactor benchmarks to use SignedFixedDecimal instead of UnsignedFixe…
younies Nov 13, 2024
b9a202d
Update documentation for rounding modes to clarify signed and unsigne…
younies Nov 13, 2024
a696144
Refactor documentation for SignedFixedDecimal to enhance clarity and …
younies Nov 13, 2024
def35eb
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Nov 19, 2024
accee4a
Replace FixedDecimal with SignedFixedDecimal in various components
younies Nov 19, 2024
236de88
Refactor format function signature for improved readability
younies Nov 19, 2024
e38f7b6
Update documentation to reflect change from FixedDecimal to SignedFix…
younies Nov 19, 2024
9b56fa5
Add missing API entries for SignedFixedDecimal and UnsignedFixedDecim…
younies Nov 19, 2024
a50c928
Clarify error handling for sign characters in UnsignedFixedDecimal input
younies Nov 19, 2024
87dfd16
Add test cases for syntax errors in decimal input strings
younies Nov 19, 2024
2dd420f
Remove leading plus sign from test case input strings and clean up un…
younies Nov 19, 2024
98e0518
Merge remote-tracking branch 'upstream/main' into add-sign-fixeddecimal
younies Nov 20, 2024
ff7706c
Update dependencies and versions in Cargo.lock
younies Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions components/datetime/src/format/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::time_zone::{
};

use core::fmt::{self, Write};
use fixed_decimal::FixedDecimal;
use fixed_decimal::{SignedFixedDecimal, UnsignedFixedDecimal};
use icu_calendar::types::{
FormattingEra, {DayOfWeekInMonth, IsoWeekday, MonthCode},
};
Expand All @@ -29,7 +29,7 @@ use writeable::{Part, Writeable};
fn try_write_number<W>(
result: &mut W,
fixed_decimal_format: Option<&FixedDecimalFormatter>,
mut num: FixedDecimal,
mut num: SignedFixedDecimal,
length: FieldLength,
) -> Result<Result<(), DateTimeWriteError>, fmt::Error>
where
Expand All @@ -39,20 +39,20 @@ where
match length {
FieldLength::One | FieldLength::NumericOverride(_) => {}
FieldLength::TwoDigit => {
num.pad_start(2);
num.set_max_position(2);
num.absolute.pad_start(2);
num.absolute.set_max_position(2);
}
FieldLength::Abbreviated => {
num.pad_start(3);
num.absolute.pad_start(3);
}
FieldLength::Wide => {
num.pad_start(4);
num.absolute.pad_start(4);
}
FieldLength::Narrow => {
num.pad_start(5);
num.absolute.pad_start(5);
}
FieldLength::Six => {
num.pad_start(6);
num.absolute.pad_start(6);
}
}

Expand Down Expand Up @@ -417,13 +417,14 @@ where
}
(Some(second), Some(ns)) => {
// Formatting with fractional seconds
let mut s = FixedDecimal::from(usize::from(second));
let _infallible =
s.concatenate_end(FixedDecimal::from(usize::from(ns)).multiplied_pow10(-9));
let mut s = SignedFixedDecimal::from(usize::from(second));
let _infallible = s.absolute.concatenate_end(
UnsignedFixedDecimal::from(usize::from(ns)).multiplied_pow10(-9),
);
debug_assert!(_infallible.is_ok());
let position = -(decimal_second as i16);
s.trunc(position);
s.pad_end(position);
s.absolute.trunc(position);
s.absolute.pad_end(position);
try_write_number(w, fdf, s, l)?
}
}
Expand Down Expand Up @@ -614,7 +615,7 @@ mod tests {
try_write_number(
&mut writeable::adapters::CoreWriteAsPartsWrite(&mut s),
Some(&fixed_decimal_format),
FixedDecimal::from(*value),
SignedFixedDecimal::from(*value),
*length,
)
.unwrap()
Expand Down
36 changes: 18 additions & 18 deletions components/datetime/src/time_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
provider,
};
use core::fmt;
use fixed_decimal::FixedDecimal;
use fixed_decimal::SignedFixedDecimal;
use icu_calendar::{Date, Iso, Time};
use icu_decimal::FixedDecimalFormatter;
use icu_timezone::{TimeZoneBcp47Id, UtcOffset, ZoneVariant};
Expand Down Expand Up @@ -491,33 +491,33 @@ impl FormatTimeZone for LocalizedOffsetFormat {
&self,
sink: &mut S,
) -> fmt::Result {
self.fdf
.format(
&FixedDecimal::from(self.offset.hours_part())
.with_sign_display(fixed_decimal::SignDisplay::Always)
.padded_start(if self.length == FieldLength::Wide {
2
} else {
0
}),
)
.write_to(sink)?;
let mut signed_fdf = SignedFixedDecimal::from(self.offset.hours_part())
.with_sign_display(fixed_decimal::SignDisplay::Always);
signed_fdf
.absolute
.pad_start(if self.length == FieldLength::Wide {
2
} else {
0
});
self.fdf.format(&signed_fdf).write_to(sink)?;

if self.length == FieldLength::Wide
|| self.offset.minutes_part() != 0
|| self.offset.seconds_part() != 0
{
let mut signed_fdf = SignedFixedDecimal::from(self.offset.minutes_part());
signed_fdf.absolute.pad_start(2);
sink.write_str(self.separator)?;
self.fdf
.format(&FixedDecimal::from(self.offset.minutes_part()).padded_start(2))
.write_to(sink)?;
self.fdf.format(&signed_fdf).write_to(sink)?;
}

if self.offset.seconds_part() != 0 {
sink.write_str(self.separator)?;
self.fdf
.format(&FixedDecimal::from(self.offset.seconds_part()).padded_start(2))
.write_to(sink)?;

let mut signed_fdf = SignedFixedDecimal::from(self.offset.seconds_part());
signed_fdf.absolute.pad_start(2);
self.fdf.format(&signed_fdf).write_to(sink)?;
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions components/decimal/benches/fixed_decimal_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rand_pcg::Lcg64Xsh32;

use criterion::{black_box, criterion_group, criterion_main, Criterion};

use fixed_decimal::FixedDecimal;
use fixed_decimal::SignedFixedDecimal;
use icu_decimal::provider::DecimalSymbolsV1Marker;
use icu_decimal::FixedDecimalFormatter;
use icu_provider_adapters::fixed::FixedProvider;
Expand Down Expand Up @@ -38,7 +38,7 @@ fn overview_bench(c: &mut Criterion) {
)
.unwrap();
for &num in &nums {
let fd = FixedDecimal::from(black_box(num));
let fd = SignedFixedDecimal::from(black_box(num));
fdf.format_to_string(&fd);
}
});
Expand Down
8 changes: 4 additions & 4 deletions components/decimal/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use crate::grouper;
use crate::options::*;
use crate::provider::*;
use fixed_decimal::FixedDecimal;
use fixed_decimal::Sign;
use fixed_decimal::SignedFixedDecimal;
use writeable::Writeable;

/// An intermediate structure returned by [`FixedDecimalFormatter`](crate::FixedDecimalFormatter).
/// Use [`Writeable`][Writeable] to render the formatted decimal to a string or buffer.
#[derive(Debug, PartialEq, Clone)]
pub struct FormattedFixedDecimal<'l> {
pub(crate) value: &'l FixedDecimal,
pub(crate) value: &'l SignedFixedDecimal,
pub(crate) options: &'l FixedDecimalFormatterOptions,
pub(crate) symbols: &'l DecimalSymbolsV1<'l>,
}
Expand All @@ -39,14 +39,14 @@ impl Writeable for FormattedFixedDecimal<'_> {
if let Some(affixes) = affixes {
sink.write_str(&affixes.prefix)?;
}
let range = self.value.magnitude_range();
let range = self.value.absolute.magnitude_range();
let upper_magnitude = *range.end();
for m in range.rev() {
if m == -1 {
sink.write_str(&self.symbols.decimal_separator)?;
}
#[allow(clippy::indexing_slicing)] // digit_at in 0..=9
sink.write_char(self.symbols.digits[self.value.digit_at(m) as usize])?;
sink.write_char(self.symbols.digits[self.value.absolute.digit_at(m) as usize])?;
if grouper::check(
upper_magnitude,
m,
Expand Down
4 changes: 2 additions & 2 deletions components/decimal/src/grouper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn test_grouper() {
use crate::options;
use crate::provider::*;
use crate::FixedDecimalFormatter;
use fixed_decimal::FixedDecimal;
use fixed_decimal::SignedFixedDecimal;
use icu_provider::prelude::*;
use icu_provider_adapters::fixed::FixedProvider;
use writeable::assert_writeable_eq;
Expand Down Expand Up @@ -153,7 +153,7 @@ fn test_grouper() {
];
for cas in &cases {
for i in 0..4 {
let dec = FixedDecimal::from(1).multiplied_pow10((i as i16) + 3);
let dec = SignedFixedDecimal::from(1).multiplied_pow10((i as i16) + 3);
let provider = FixedProvider::<DecimalSymbolsV1Marker>::from_owned(
crate::provider::DecimalSymbolsV1 {
grouping_sizes: cas.sizes,
Expand Down
6 changes: 3 additions & 3 deletions components/decimal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub mod provider;
pub use format::FormattedFixedDecimal;

use alloc::string::String;
use fixed_decimal::FixedDecimal;
use fixed_decimal::SignedFixedDecimal;
use icu_provider::prelude::*;
use writeable::Writeable;

Expand Down Expand Up @@ -157,7 +157,7 @@ impl FixedDecimalFormatter {
}

/// Formats a [`FixedDecimal`], returning a [`FormattedFixedDecimal`].
pub fn format<'l>(&'l self, value: &'l FixedDecimal) -> FormattedFixedDecimal<'l> {
pub fn format<'l>(&'l self, value: &'l SignedFixedDecimal) -> FormattedFixedDecimal<'l> {
FormattedFixedDecimal {
value,
options: &self.options,
Expand All @@ -166,7 +166,7 @@ impl FixedDecimalFormatter {
}

/// Formats a [`FixedDecimal`], returning a [`String`].
pub fn format_to_string(&self, value: &FixedDecimal) -> String {
pub fn format_to_string(&self, value: &SignedFixedDecimal) -> String {
self.format(value).write_to_string().into_owned()
}
}
4 changes: 2 additions & 2 deletions components/experimental/src/compactdecimal/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use alloc::borrow::Cow;
use fixed_decimal::{CompactDecimal, FixedDecimal};
use fixed_decimal::{CompactDecimal, SignedFixedDecimal};
use writeable::Writeable;
use zerovec::maps::ZeroMap2dCursor;

Expand Down Expand Up @@ -62,7 +62,7 @@ impl Writeable for FormattedCompactDecimal<'_> {
} else {
let plural_map = self.plural_map.as_ref().ok_or(core::fmt::Error)?;
let chosen_pattern = (|| {
if self.value.significand() == &FixedDecimal::from(1) {
if self.value.significand() == &SignedFixedDecimal::from(1) {
if let Some(pattern) = plural_map.get1(&Count::Explicit1) {
return Some(pattern);
}
Expand Down
19 changes: 10 additions & 9 deletions components/experimental/src/compactdecimal/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::compactdecimal::{
};
use alloc::borrow::Cow;
use core::convert::TryFrom;
use fixed_decimal::{CompactDecimal, FixedDecimal};
use fixed_decimal::{CompactDecimal, SignedFixedDecimal};
use icu_decimal::FixedDecimalFormatter;
use icu_plurals::PluralRules;
use icu_provider::DataError;
Expand Down Expand Up @@ -280,7 +280,7 @@ impl CompactDecimalFormatter {
/// assert_writeable_eq!(short_english.format_i64(-1_172_700), "-1.2M");
/// ```
pub fn format_i64(&self, value: i64) -> FormattedCompactDecimal<'_> {
let unrounded = FixedDecimal::from(value);
let unrounded = SignedFixedDecimal::from(value);
self.format_fixed_decimal(unrounded)
}

Expand Down Expand Up @@ -345,7 +345,7 @@ impl CompactDecimalFormatter {
use fixed_decimal::FloatPrecision::RoundTrip;
// NOTE: This first gets the shortest representation of the f64, which
// manifests as double rounding.
let partly_rounded = FixedDecimal::try_from_f64(value, RoundTrip)?;
let partly_rounded = SignedFixedDecimal::try_from_f64(value, RoundTrip)?;
Ok(self.format_fixed_decimal(partly_rounded))
}

Expand Down Expand Up @@ -447,20 +447,21 @@ impl CompactDecimalFormatter {
/// "-1.2M"
/// );
/// ```
pub fn format_fixed_decimal(&self, value: FixedDecimal) -> FormattedCompactDecimal<'_> {
let log10_type = value.nonzero_magnitude_start();
pub fn format_fixed_decimal(&self, value: SignedFixedDecimal) -> FormattedCompactDecimal<'_> {
let log10_type = value.absolute.nonzero_magnitude_start();
let (mut plural_map, mut exponent) = self.plural_map_and_exponent_for_magnitude(log10_type);
let mut significand = value.multiplied_pow10(-i16::from(exponent));
// If we have just one digit before the decimal point…
if significand.nonzero_magnitude_start() == 0 {
if significand.absolute.nonzero_magnitude_start() == 0 {
// …round to one fractional digit…
significand.round(-1);
} else {
// …otherwise, we have at least 2 digits before the decimal point,
// so round to eliminate the fractional part.
significand.round(0);
}
let rounded_magnitude = significand.nonzero_magnitude_start() + i16::from(exponent);
let rounded_magnitude =
significand.absolute.nonzero_magnitude_start() + i16::from(exponent);
if rounded_magnitude > log10_type {
// We got bumped up a magnitude by rounding.
// This means that `significand` is a power of 10.
Expand All @@ -476,7 +477,7 @@ impl CompactDecimalFormatter {
// only have become larger, it is already the correct rounding of
// `unrounded` to the precision we want to show.
}
significand.trim_end();
significand.absolute.trim_end();
FormattedCompactDecimal {
formatter: self,
plural_map,
Expand Down Expand Up @@ -589,7 +590,7 @@ impl CompactDecimalFormatter {
value: &'l CompactDecimal,
) -> Result<FormattedCompactDecimal<'l>, ExponentError> {
let log10_type =
value.significand().nonzero_magnitude_start() + i16::from(value.exponent());
value.significand().absolute.nonzero_magnitude_start() + i16::from(value.exponent());

let (plural_map, expected_exponent) =
self.plural_map_and_exponent_for_magnitude(log10_type);
Expand Down
4 changes: 2 additions & 2 deletions components/experimental/src/dimension/currency/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use fixed_decimal::FixedDecimal;
use fixed_decimal::SignedFixedDecimal;

use icu_decimal::FixedDecimalFormatter;
use writeable::Writeable;
Expand All @@ -14,7 +14,7 @@ use crate::dimension::provider::currency;
use crate::dimension::provider::currency::CurrencyEssentialsV1;

pub struct FormattedCurrency<'l> {
pub(crate) value: &'l FixedDecimal,
pub(crate) value: &'l SignedFixedDecimal,
pub(crate) currency_code: CurrencyCode,
pub(crate) options: &'l CurrencyFormatterOptions,
pub(crate) essential: &'l CurrencyEssentialsV1<'l>,
Expand Down
4 changes: 2 additions & 2 deletions components/experimental/src/dimension/currency/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

//! Experimental.

use fixed_decimal::FixedDecimal;
use fixed_decimal::SignedFixedDecimal;
use icu_decimal::{options::FixedDecimalFormatterOptions, FixedDecimalFormatter};
use icu_provider::prelude::*;

Expand Down Expand Up @@ -123,7 +123,7 @@ impl CurrencyFormatter {
/// ```
pub fn format_fixed_decimal<'l>(
&'l self,
value: &'l FixedDecimal,
value: &'l SignedFixedDecimal,
currency_code: CurrencyCode,
) -> FormattedCurrency<'l> {
FormattedCurrency {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use fixed_decimal::FixedDecimal;
use fixed_decimal::SignedFixedDecimal;

use icu_decimal::FixedDecimalFormatter;
use icu_plurals::PluralRules;
Expand All @@ -14,7 +14,7 @@ use crate::dimension::provider::extended_currency::CurrencyExtendedDataV1;
use super::CurrencyCode;

pub struct LongFormattedCurrency<'l> {
pub(crate) value: &'l FixedDecimal,
pub(crate) value: &'l SignedFixedDecimal,
// TODO: use this if the display name is not exist and make the extended data optional.
pub(crate) _currency_code: CurrencyCode,
pub(crate) extended: &'l CurrencyExtendedDataV1<'l>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

//! Experimental.

use fixed_decimal::FixedDecimal;
use fixed_decimal::SignedFixedDecimal;
use icu_decimal::{options::FixedDecimalFormatterOptions, FixedDecimalFormatter};
use icu_plurals::PluralRules;
use icu_provider::prelude::*;
Expand Down Expand Up @@ -158,7 +158,7 @@ impl LongCurrencyFormatter {
/// ```
pub fn format_fixed_decimal<'l>(
&'l self,
value: &'l FixedDecimal,
value: &'l SignedFixedDecimal,
currency_code: CurrencyCode,
) -> LongFormattedCurrency<'l> {
LongFormattedCurrency {
Expand Down
Loading
Loading