Skip to content

Commit

Permalink
ICU-22463 Fix gasoline-equivalent conversion
Browse files Browse the repository at this point in the history
See #2616
  • Loading branch information
younies authored and Squash Bot committed Sep 21, 2023
1 parent 4fcf8d2 commit 8f203e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
15 changes: 12 additions & 3 deletions icu4c/source/i18n/units_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,20 @@ void U_I18N_API addSingleFactorConstant(StringPiece baseStr, int32_t power, Sign
factor.constantExponents[CONSTANT_FT2M] += 3 * power * signum;
} else if (baseStr == "in3_to_m3") {
factor.constantExponents[CONSTANT_FT2M] += 3 * power * signum;
factor.factorDen *= 12 * 12 * 12;
if (signum == Signum::NEGATIVE) {
factor.factorNum *= 12 * 12 * 12;
} else {
factor.factorDen *= 12 * 12 * 12;
}
} else if (baseStr == "gal_to_m3") {
factor.factorNum *= 231;
factor.constantExponents[CONSTANT_FT2M] += 3 * power * signum;
factor.factorDen *= 12 * 12 * 12;
if (signum == Signum::NEGATIVE) {
factor.factorDen *= 231;
factor.factorNum *= 12 * 12 * 12;
} else {
factor.factorNum *= 231;
factor.factorDen *= 12 * 12 * 12;
}
} else if (baseStr == "gal_imp_to_m3") {
factor.constantExponents[CONSTANT_GAL_IMP2M3] += power * signum;
} else if (baseStr == "G") {
Expand Down
6 changes: 1 addition & 5 deletions icu4c/source/test/intltest/units_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,7 @@ void unitsTestDataLineFn(void *context, char *fields[][2], int32_t fieldCount, U
StringPiece y = trimField(fields[2]);
StringPiece commentConversionFormula = trimField(fields[3]);
StringPiece utf8Expected = trimField(fields[4]);
StringPiece gasolineEnergyDensity("gasoline-energy-density");

if ( x.compare(gasolineEnergyDensity) == 0 && unitsTest->logKnownIssue("CLDR-17015", "Problem with gasoline-energy-density unit calculation")) {
return;
}


UNumberFormat *nf = unum_open(UNUM_DEFAULT, nullptr, -1, "en_US", nullptr, status);
if (status.errIfFailureAndReset("unum_open failed")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,20 @@ private void addEntity(String entity, int power) {
this.exponentFtToM += 3 * power;
} else if ("in3_to_m3".equals(entity)) {
this.exponentFtToM += 3 * power;
this.factorDen = this.factorDen.multiply(BigDecimal.valueOf(Math.pow(12, 3)));
if (power < 0) {
this.factorNum = this.factorDen.multiply(BigDecimal.valueOf(12 * 12 * 12));
} else {
this.factorDen = this.factorNum.multiply(BigDecimal.valueOf(12 * 12 * 12));
}
} else if ("gal_to_m3".equals(entity)) {
this.factorNum = this.factorNum.multiply(BigDecimal.valueOf(231));
this.exponentFtToM += 3 * power;
this.factorDen = this.factorDen.multiply(BigDecimal.valueOf(12 * 12 * 12));
if (power < 0) {
this.factorDen = this.factorDen.multiply(BigDecimal.valueOf(231));
this.factorNum = this.factorNum.multiply(BigDecimal.valueOf(12 * 12 * 12));
} else {
this.factorNum = this.factorNum.multiply(BigDecimal.valueOf(231));
this.factorDen = this.factorDen.multiply(BigDecimal.valueOf(12 * 12 * 12));
}
} else if ("gal_imp_to_m3".equals(entity)) {
this.exponentGalImpToM3 += power;
} else if ("G".equals(entity)) {
Expand Down

0 comments on commit 8f203e8

Please sign in to comment.