Skip to content

Conversation

@younies
Copy link
Member

@younies younies commented Jun 19, 2025

Desctiption

  • Implemented generate_short_representation method in MeasureUnit to provide a concise string representation of measure units, including handling of constant denominators and scientific notation.
  • Added ToString implementation for SiPrefix and SingleUnit to facilitate their string representations, following a defined format for SI prefixes and unit IDs.
  • Updated documentation with examples for clarity on usage and expected outputs.

# Desctiption

- Implemented `generate_short_representation` method in `MeasureUnit` to provide a concise string representation of measure units, including handling of constant denominators and scientific notation.
- Added `ToString` implementation for `SiPrefix` and `SingleUnit` to facilitate their string representations, following a defined format for SI prefixes and unit IDs.
- Updated documentation with examples for clarity on usage and expected outputs.
@younies younies requested a review from a team as a code owner June 19, 2025 14:56
@gemini-code-assist
Copy link

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

@younies younies requested a review from robertbastian June 19, 2025 14:57
// add constant part to the negative part
if self.constant_denominator > 0 {
if !negative_part.is_empty() {
negative_part.insert(0, '#');
Copy link
Member

Choose a reason for hiding this comment

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

do you need the #? C and R should be unambiguous without them

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I was thinking about that. We only need C. In fact, we could even eliminate C if we declare the constant at the beginning, but let’s keep it for readability for now.

younies added 3 commits June 20, 2025 16:12
…SingleUnit

- Updated `generate_short_representation` in `MeasureUnit` to utilize helper methods for appending short representations.
- Introduced `append_short_representation` methods in `SiPrefix` and `SingleUnit` to streamline the process of generating their string representations.
- Enhanced documentation with examples for better clarity on usage.
@younies younies requested a review from robertbastian June 20, 2025 15:38
@younies younies closed this Jun 20, 2025
@younies younies reopened this Jun 20, 2025
///
/// assert_eq!(short_representation, "C100I82P-1D3I85", "{}", "liter-per-100-kilometer");
/// ```
pub fn generate_short_representation(&self) -> String {
Copy link
Member

Choose a reason for hiding this comment

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

is this actually intended to be a public API?

Copy link
Member Author

@younies younies Jun 23, 2025

Choose a reason for hiding this comment

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

For now, yes. Once we start using it internally, it will be private.

Copy link
Member

Choose a reason for hiding this comment

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

what requires this to be public now? I'm worried that this will be forgotten and accidentally made public

Copy link
Member Author

Choose a reason for hiding this comment

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

We will needed in the data gen

Copy link
Member

Choose a reason for hiding this comment

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

how will you make it private if it's used in datagen? should it be in provider?

Copy link
Member Author

@younies younies Jul 8, 2025

Choose a reason for hiding this comment

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

we should have a field for the short unit id, but it is okay, the fn can be public for now

///
/// assert_eq!(short_representation, "C100I82P-1D3I85", "{}", "liter-per-100-kilometer");
/// ```
pub fn generate_short_representation(&self) -> String {
Copy link
Member

Choose a reason for hiding this comment

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

what requires this to be public now? I'm worried that this will be forgotten and accidentally made public

@younies younies requested a review from robertbastian June 23, 2025 21:02
Comment on lines 83 to 99
// Divide by 10^8
while n % 100_000_000 == 0 {
n /= 100_000_000;
zeros_count += 8;
}

// Divide by 10^4
while n % 10_000 == 0 {
n /= 10_000;
zeros_count += 4;
}

// Divide by 10^2
while n % 100 == 0 {
n /= 100;
zeros_count += 2;
}
Copy link
Member

Choose a reason for hiding this comment

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

what's the point of these? repeatedly dividing by 10 is sufficient

Copy link
Member Author

Choose a reason for hiding this comment

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

for reducing the time complexity

Copy link
Member

Choose a reason for hiding this comment

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

the time complexity is constant because the input is fixed-length. I don't think this is worth the additional code complexity

@younies younies requested a review from robertbastian July 3, 2025 11:42
///
/// assert_eq!(short_representation, "C100I82P-1D3I85", "{}", "liter-per-100-kilometer");
/// ```
pub fn generate_short_representation(&self) -> String {
Copy link
Member

Choose a reason for hiding this comment

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

how will you make it private if it's used in datagen? should it be in provider?

@younies younies requested a review from robertbastian July 8, 2025 14:08
Base::Decimal => 'D',
Base::Binary => 'B',
});
write!(buff, "{}", self.power).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

don't unwrap, it adds panicking code

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch

Copy link
Member

Choose a reason for hiding this comment

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

also in other places

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@younies younies requested a review from robertbastian July 8, 2025 15:09
Copy link
Member

@robertbastian robertbastian left a comment

Choose a reason for hiding this comment

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

.

@younies younies requested a review from robertbastian July 8, 2025 15:27
@younies younies merged commit 6404bfd into unicode-org:main Jul 8, 2025
30 checks passed
@younies younies deleted the generate_id branch July 8, 2025 15:43
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.

2 participants