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

Remove unneeded to_f64 funciton #4839

Merged
merged 14 commits into from
May 14, 2024
Merged
2 changes: 1 addition & 1 deletion components/experimental/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ zerofrom = { workspace = true }
displaydoc = { workspace = true }
log = { workspace = true, optional = true }
num-bigint = { workspace = true }
num-rational = { workspace = true , features = ["num-bigint"]}
num-rational = { workspace = true, features = ["num-bigint"]}
num-traits = { workspace = true }
serde = { workspace = true, features = ["derive", "alloc"], optional = true }
smallvec = { workspace = true }
Expand Down
7 changes: 0 additions & 7 deletions components/experimental/src/units/ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use alloc::borrow::Cow;
use num_bigint::BigInt;
use num_rational::Ratio;
use num_traits::Signed;
use num_traits::ToPrimitive;
use num_traits::{One, Pow, Zero};

use super::provider::{Base, SiPrefix};
Expand Down Expand Up @@ -69,12 +68,6 @@ impl IcuRatio {
Self(self.0.recip())
}

// TODO: Make the function private after fixing the need for it in the tests.
/// Returns the value of the ratio as a `f64`.
pub fn to_f64(&self) -> Option<f64> {
Some(self.0.numer().to_f64()? / self.0.denom().to_f64()?)
}

/// Returns the absolute value of the ratio.
pub fn abs(&self) -> Self {
Self(self.0.abs())
Expand Down
6 changes: 3 additions & 3 deletions components/experimental/tests/units/units_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use icu_experimental::units::converter_factory::ConverterFactory;
use icu_experimental::units::ratio::IcuRatio;
use num_bigint::BigInt;
use num_rational::Ratio;
use num_traits::Signed;
use num_traits::{Signed, ToPrimitive};

#[test]
fn test_cldr_unit_tests() {
Expand Down Expand Up @@ -69,13 +69,13 @@ fn test_cldr_unit_tests() {
);
}

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

if diff_ratio_f64 > 0.000001 {
panic!(
"Failed test: Category: {:?}, Input Unit: {:?}, Output Unit: {:?}, Result: {:?}, Expected Result: {:?}",
test.category, test.input_unit, test.output_unit, result_f64, test.result
test.category, test.input_unit, test.output_unit, result_f64, test_result_f64
);
}
}
Expand Down