Skip to content

Commit afe6679

Browse files
authored
Remove unneeded to_f64 funciton (#4839)
1 parent 1ada2eb commit afe6679

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

components/experimental/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ zerofrom = { workspace = true }
4747
displaydoc = { workspace = true }
4848
log = { workspace = true, optional = true }
4949
num-bigint = { workspace = true }
50-
num-rational = { workspace = true , features = ["num-bigint"]}
50+
num-rational = { workspace = true, features = ["num-bigint"]}
5151
num-traits = { workspace = true }
5252
serde = { workspace = true, features = ["derive", "alloc"], optional = true }
5353
smallvec = { workspace = true }

components/experimental/src/units/ratio.rs

-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use alloc::borrow::Cow;
1111
use num_bigint::BigInt;
1212
use num_rational::Ratio;
1313
use num_traits::Signed;
14-
use num_traits::ToPrimitive;
1514
use num_traits::{One, Pow, Zero};
1615

1716
use super::provider::{Base, SiPrefix};
@@ -69,12 +68,6 @@ impl IcuRatio {
6968
Self(self.0.recip())
7069
}
7170

72-
// TODO: Make the function private after fixing the need for it in the tests.
73-
/// Returns the value of the ratio as a `f64`.
74-
pub fn to_f64(&self) -> Option<f64> {
75-
Some(self.0.numer().to_f64()? / self.0.denom().to_f64()?)
76-
}
77-
7871
/// Returns the absolute value of the ratio.
7972
pub fn abs(&self) -> Self {
8073
Self(self.0.abs())

components/experimental/tests/units/units_test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use icu_experimental::units::converter_factory::ConverterFactory;
99
use icu_experimental::units::ratio::IcuRatio;
1010
use num_bigint::BigInt;
1111
use num_rational::Ratio;
12-
use num_traits::Signed;
12+
use num_traits::{Signed, ToPrimitive};
1313

1414
#[test]
1515
fn test_cldr_unit_tests() {
@@ -69,13 +69,13 @@ fn test_cldr_unit_tests() {
6969
);
7070
}
7171

72-
let test_result_f64 = test.result.to_f64().unwrap();
72+
let test_result_f64 = test.result.get_ratio().to_f64().unwrap();
7373
let diff_ratio_f64 = ((test_result_f64 - result_f64) / test_result_f64).abs();
7474

7575
if diff_ratio_f64 > 0.000001 {
7676
panic!(
7777
"Failed test: Category: {:?}, Input Unit: {:?}, Output Unit: {:?}, Result: {:?}, Expected Result: {:?}",
78-
test.category, test.input_unit, test.output_unit, result_f64, test.result
78+
test.category, test.input_unit, test.output_unit, result_f64, test_result_f64
7979
);
8080
}
8181
}

0 commit comments

Comments
 (0)