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 LinearConverter #4404

Merged
merged 146 commits into from
Feb 5, 2024

Conversation

younies
Copy link
Member

@younies younies commented Dec 3, 2023

No description provided.

sffc
sffc previously approved these changes Feb 1, 2024
/// The conversion is not possible due to an internal error.
InternalError,
/// The needed data is not found.
DataNotFoundError,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there's information in the DataError that you should propagate. Just to be clear, I'm saying this variant should be

Suggested change
DataNotFoundError,
Data(DataError),

However, as far as I can tell this is actually unused if you address all my comments.

experimental/unitsconversion/src/converter.rs Show resolved Hide resolved
Comment on lines +182 to +189
match si_prefix.base {
Base::Decimal => {
*ratio *= Ratio::<BigInt>::from_integer(10.into()).pow(si_prefix.power as i32);
}
Base::Binary => {
*ratio *= Ratio::<BigInt>::from_integer(2.into()).pow(si_prefix.power as i32);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, core::ops::Mul does not have to be with the same type. Because this involves a mutable type you'd have to use core::ops::MulAssign though:

impl core::ops::MulAssign<SiPrefix> for IcuRatio {
    fn mul_assign(&mut self, x: Ratio) -> {
      ...
    }
}

This is the idiomatic way to do this. You can then write:

conversion_info_factor *= unit.item.si_prefix;

This requires having an IcuRatio type as @sffc suggested.

Comment on lines 227 to 230
let sign = match Sign::from_unaligned(*sign_ule) {
Sign::Positive => num_bigint::Sign::Plus,
Sign::Negative => num_bigint::Sign::Minus,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rusty way to do this:

impl Into<num_bigint::Sign> for Sign {
  ...
}

experimental/unitsconversion/Cargo.toml Outdated Show resolved Hide resolved
experimental/unitsconversion/src/converter.rs Outdated Show resolved Hide resolved
experimental/unitsconversion/src/converter.rs Outdated Show resolved Hide resolved
experimental/unitsconversion/src/converter.rs Outdated Show resolved Hide resolved
experimental/unitsconversion/src/converter.rs Outdated Show resolved Hide resolved
experimental/unitsconversion/src/converter.rs Show resolved Hide resolved
sffc
sffc previously approved these changes Feb 2, 2024
/// NOTE:
/// The converter is not able to convert between two units that are not single. such as "foot-and-inch" to "meter".
#[derive(Debug)]
pub struct LinearConverter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sounds like a bikeshed for later

Comment on lines +182 to +189
match si_prefix.base {
Base::Decimal => {
*ratio *= Ratio::<BigInt>::from_integer(10.into()).pow(si_prefix.power as i32);
}
Base::Binary => {
*ratio *= Ratio::<BigInt>::from_integer(2.into()).pow(si_prefix.power as i32);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's raising to a power, not multiplying

experimental/unitsconversion/src/converter.rs Outdated Show resolved Hide resolved
sffc
sffc previously approved these changes Feb 2, 2024
robertbastian
robertbastian previously approved these changes Feb 5, 2024
Comment on lines +182 to +189
match si_prefix.base {
Base::Decimal => {
*ratio *= Ratio::<BigInt>::from_integer(10.into()).pow(si_prefix.power as i32);
}
Base::Binary => {
*ratio *= Ratio::<BigInt>::from_integer(2.into()).pow(si_prefix.power as i32);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's raising to a power, not multiplying

It is multiplying something with the SI prefix. That the SI prefix is a power of 2/10 is internal to the SI prefix.

experimental/unitsconversion/src/converter.rs Outdated Show resolved Hide resolved
@robertbastian robertbastian dismissed stale reviews from sffc and themself via ed60d75 February 5, 2024 10:21
@robertbastian robertbastian changed the title Implement the converter (end-to-end) Implement LinearConverter Feb 5, 2024
@robertbastian robertbastian merged commit 6b6f6df into unicode-org:main Feb 5, 2024
30 checks passed
@younies younies deleted the convertibilty_implementation branch June 27, 2024 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants