]> granicus.if.org Git - icu/commitdiff
fix substituteConstans function
authorYounies Mahmoud <younies@younies-macbookpro4.roam.corp.google.com>
Wed, 6 May 2020 02:28:35 +0000 (04:28 +0200)
committerYounies Mahmoud <younies@younies-macbookpro4.roam.corp.google.com>
Wed, 6 May 2020 02:43:48 +0000 (04:43 +0200)
icu4c/source/i18n/unitconverter.cpp

index 07b0b8ad3121fcd3fde34c13ca8aac9db0a6846c..2899cd5909af93a7debad8c59ddde8756956f352 100644 (file)
@@ -125,22 +125,16 @@ struct Factor {
         constantsValues[CONSTANT_GAL_IMP2M3] = 0.00454609;
 
         for (int i = 0; i < CONSTANTS_COUNT; i++) {
-            if (this->constants[i] == 0) continue;
+            if (this->constants[i] == 0) { continue;}
 
-            substituteSingleConstant(this->constants[i], constantsValues[i]);
-            this->constants[i] = 0;
-        }
-    }
+            auto absPower = std::abs(this->constants[i]);
+            SigNum powerSig = this->constants[i] < 0 ? SigNum::NEGATIVE : SigNum::POSITIVE;
+            double absConstantValue = std::pow(constantsValues[i], absPower);
 
-    void substituteSingleConstant(int32_t constantPower,
-                                  double constantValue /* the constant actual value,
-                                                                     e.g. G= 9.88888 */) {
-        constantValue = std::pow(constantValue, std::abs(constantPower));
+            if (powerSig ==  SigNum::NEGATIVE) { this->factorDen *= absConstantValue;} 
+            else { this->factorNum *= absConstantValue;}
 
-        if (constantPower < 0) {
-            this->factorDen *= constantValue;
-        } else {
-            this->factorNum *= constantValue;
+            this->constants[i] = 0;
         }
     }
 };
@@ -222,6 +216,7 @@ MeasureUnit extractCompoundBaseUnit(const MeasureUnit &source, const ConversionR
     return result;
 }
 
+// TODO: Load those constant from units data.
 /*
  * Adds a single factor element to the `Factor`. e.g "ft3m", "2.333" or "cup2m3". But not "cup2m3^3".
  */