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

Editorial: Simplify NumberFormat #978

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

gibson042
Copy link
Contributor

  • Fix id values to align with operation names.
  • Refactor spec aliases and parameter types for readability.
  • Collapse rounding mode negation data into one table.
  • Fold GetUnsignedRoundingMode into ApplyUnsignedRoundingMode

@gibson042 gibson042 requested review from sffc and ryzokuken March 5, 2025 22:17
@ptomato
Copy link
Contributor

ptomato commented Mar 5, 2025

Would you have time to update the usages of GetUnsignedRoundingMode and ApplyUnsignedRoundingMode in Temporal while this is still fresh?

Copy link
Contributor

@sffc sffc left a comment

Choose a reason for hiding this comment

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

Hmm. I quite like having a clean separation between RoundingMode (what users specify) and UnsignedRoundingMode (what implementations need). I'm not convinced that essentially replacing the internal enum UnsignedRoundingMode with an internal tuple that pairs RoundingMode with ~positive~ or ~negative~ is an improvement.

@gibson042
Copy link
Contributor Author

Hmm. I quite like having a clean separation between RoundingMode (what users specify) and UnsignedRoundingMode (what implementations need).

I might agree with you if we didn't make comparisons against the former all over the place, including in many steps in or downstream of NumberFormat PartitionNumberPattern (numberFormat.[[Style]] vs. "percent"/"unit"/"currency", intlObject.[[TrailingZeroDisplay]] vs. "stripIfInteger", numberFormat.[[SignDisplay]] vs. "never"/"auto"/"always"/"exceptZero"/"negative", numberFormat.[[Notation]] vs. "scientific"/"engineering"/"compact", etc.).

I'm not convinced that essentially replacing the internal enum UnsignedRoundingMode with an internal tuple that pairs RoundingMode with ~positive~ or ~negative~ is an improvement.

Well, that's exactly what GetUnsignedRoundingMode does right now. The benefits of instead directly propagating that pair into ToRaw{Precision,Fixed} and ApplyUnsignedRoundingMode are

  • Make clear in the definition of rounding modes that only the ceil/floor family need this adjustment when working with absolute values, defining details about the rounding modes in one place.
  • Avoid essentially duplicating that table a huge distance away.
  • Avoid needless introduction of new entities that basically duplicate the rounding modes anyway.

@sffc
Copy link
Contributor

sffc commented Mar 6, 2025

Just as an anecdote, we found the UnsignedRoundingMode enum useful when implementing ICU4X, and we include it along with the conformance table in the docs.

https://unicode-org.github.io/icu4x/rustdoc/fixed_decimal/enum.UnsignedRoundingMode.html

@gibson042
Copy link
Contributor Author

https://unicode-org.github.io/icu4x/rustdoc/fixed_decimal/enum.UnsignedRoundingMode.html

I don't have the context to evaluate how (or if) that might be different if the spec had already looked like I'm proposing in this PR, but the "Comparative table of all the rounding modes" at that link includes all 9 user-specifiable ECMA-402 rounding modes and not the current spec enum values produced by GetUnsignedRoundingMode (which makes sense, because the latter are redundant with the former—INFINITY/HALF-INFINITY is just "{ceil,expand}"/"half{Ceil,Expand}", ZERO/HALF-ZERO is just "{floor,trunc}"/"half{Floor,Trunc}", and HALF-EVEN is exactly "halfEven"—due to the respective equivalence of "ceil" vs. "expand" and "floor" vs. "trunc" when limited to non-negative input).

@ryzokuken ryzokuken added editorial Involves an editorial fix needs consensus labels Mar 6, 2025
@gibson042 gibson042 requested a review from sffc March 17, 2025 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial Involves an editorial fix needs consensus
Projects
Status: Priority Issues
Development

Successfully merging this pull request may close these issues.

None yet

4 participants