Skip to content

Add Japanese Hydrometer Scale support with conversions and localization - #1746

Open
Nishiwaki-Takao wants to merge 1 commit into
angularsen:masterfrom
Nishiwaki-Takao:JapaneseHydrometer
Open

Nishiwaki-Takao wants to merge 1 commit into
angularsen:masterfrom
Nishiwaki-Takao:JapaneseHydrometer

Conversation

@Nishiwaki-Takao

Copy link
Copy Markdown

Summary

This PR adds JapaneseHydrometerScale, a dimensionless quantity for Japanese hydrometer readings derived from reciprocal specific gravity.

The quantity includes:

  • Reciprocal specific gravity
  • Heavy Baumé
  • Light Baumé
  • Sake Meter Value

It also provides conversions from the scale to Ratio as specific gravity and to an equivalent Density using the density of water at 4 °C as the reference.

Definition

Let specific gravity be $SG$, and define reciprocal specific gravity as:

$$ R = \frac{1}{SG} $$

ReciprocalSpecificGravity is used as the base unit of JapaneseHydrometerScale.

Heavy Baumé

$$ ^\circ\mathrm{Bé}_{\mathrm{heavy}} = 144.3(1-R) $$

Equivalently:

$$ R = 1-\frac{^\circ\mathrm{Bé}_{\mathrm{heavy}}}{144.3} $$

Examples:

  • $SG = 1.000$, or $R = 1.000$, gives $0,^\circ\mathrm{Bé}_{\mathrm{heavy}}$
  • $SG = 1.200$, or $R \approx 0.8333333$, gives approximately $24.05,^\circ\mathrm{Bé}_{\mathrm{heavy}}$

Light Baumé

$$ ^\circ\mathrm{Bé}_{\mathrm{light}} = 144.3R-134.3 $$

Equivalently:

$$ R = \frac{^\circ\mathrm{Bé}_{\mathrm{light}}+134.3}{144.3} $$

At $R = 1$, the light Baumé value is $10,^\circ\mathrm{Bé}_{\mathrm{light}}$.

Sake Meter Value

$$ \mathrm{SMV} = 1443(R-1) $$

Equivalently:

$$ R = 1+\frac{\mathrm{SMV}}{1443} $$

At $R = 1$, the Sake Meter Value is zero.

Motivation

These scales are conventional hydrometer readings used in Japanese industrial and brewing contexts. They are not plain ratios: each scale has its own name, formula, abbreviation, parsing behavior, and localization requirements.

Representing them as a dedicated quantity provides typed conversions between the related scales while keeping their convention separate from a generic Ratio.

Design

The new quantity is named JapaneseHydrometerScale, with the following units:

  • ReciprocalSpecificGravity
  • DegreeBaumeHeavy
  • DegreeBaumeLight
  • SakeMeterValue

Reciprocal specific gravity is used as the base unit because all three scale conversions are affine functions of it.

The implementation also provides:

  • ToSpecificGravity(), returning a Ratio
  • ToDensity(), returning an equivalent Density

ToDensity() uses a water density of 999.974950 kg/m³ at 4 °C:

$$
\rho_{\mathrm{sample}}

\frac{\rho_{\mathrm{water},,4,^\circ\mathrm{C}}}{R}
$$

The resulting density therefore depends on that explicit reference condition. Reciprocal specific gravity is not treated as density itself.

Implementation

  • Add the JapaneseHydrometerScale quantity definition.
  • Use ReciprocalSpecificGravity as its base unit.
  • Add heavy Baumé, light Baumé, and Sake Meter Value conversions.
  • Add English and Japanese abbreviations:
    • 1/SG
    • °Bé heavy / °Bh
    • °Bé light / °Bl
    • SMV / 日本酒度
  • Add ToSpecificGravity() and ToDensity() conversion methods.
  • Generate the quantity type, unit enum, parsing and formatting support, number extensions, localization resources, and generated tests.

Tests

The generated tests cover:

  • Conversion of one reciprocal-specific-gravity base unit to every supported scale
  • Conversion through As() and ToUnit()
  • Round trips between the base unit and each scale
  • Parsing and formatting of English and Japanese abbreviations
  • Number extension methods
  • Standard quantity operations and metadata

The custom conversion expectations verify that $R = 1$ gives:

  • Heavy Baumé: 0
  • Light Baumé: 10
  • Sake Meter Value: 0

Scope

This PR implements the Japanese hydrometer convention represented by the formulas above.

It does not attempt to provide a generic or internationally interchangeable DegreeBaume unit. Other Baumé conventions, API gravity, and Twaddell scales may use different constants or reference conditions and remain outside the scope of this change.

References

[- JIS Z 8804 : 2012 液体の密度及び比重の測定方法] (https://kikakurui.com/z8/Z8804-2012-01.html)
- Authoritative reference for the Sake Meter Value formula.

- Introduced a new quantity `JapaneseHydrometerScale` with methods for converting to density.
- Generated code for `JapaneseHydrometerScale` including unit definitions and conversion functions.
- Added localization resources for Japanese and English, including unit abbreviations.
- Defined units for `JapaneseHydrometerScale`: Degree Baumé Heavy, Degree Baumé Light, Reciprocal Specific Gravity, and Sake Meter Value.

This branch has not been deployed

No deployments
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.

1 participant