src/third_party/icu/source/i18n/units_converter.cpp
/**
 *  Extract conversion rate from `source` to `target`
 */
Extract conversion rate from `source` to `target`
Extract conversion rate from ` source ` to ` target `
void loadConversionRate(ConversionRate &conversionRate, const MeasureUnitImpl &source,
                        const MeasureUnitImpl &target, Convertibility unitsState,
                        const ConversionRates &ratesInfo, UErrorCode &status) {
    Factor finalFactor;
    Factor sourceToBase = loadCompoundFactor(source, ratesInfo, status);
    Factor targetToBase = loadCompoundFactor(target, ratesInfo, status);
    finalFactor.multiplyBy(sourceToBase);
    if (unitsState == Convertibility::CONVERTIBLE) {
        finalFactor.divideBy(targetToBase);
    } else if (unitsState == Convertibility::RECIPROCAL) {
        finalFactor.multiplyBy(targetToBase);
    } else {
        status = UErrorCode::U_ARGUMENT_TYPE_MISMATCH;
        return;
    }
    finalFactor.substituteConstants();
    conversionRate.factorNum = finalFactor.factorNum;
    conversionRate.factorDen = finalFactor.factorDen;
    if (checkSimpleUnit(source, status) && checkSimpleUnit(target, status)) {
        conversionRate.sourceOffset =
            sourceToBase.offset * sourceToBase.factorDen / sourceToBase.factorNum;
        conversionRate.targetOffset =
            targetToBase.offset * targetToBase.factorDen / targetToBase.factorNum;
    }
    conversionRate.reciprocal = unitsState == Convertibility::RECIPROCAL;
}
void loadConversionRate ( ConversionRate & conversionRate , const MeasureUnitImpl & source , const MeasureUnitImpl & target , Convertibility unitsState , const ConversionRates & ratesInfo , UErrorCode & status ) { Factor finalFactor ; Factor sourceToBase = loadCompoundFactor ( source , ratesInfo , status ) ; Factor targetToBase = loadCompoundFactor ( target , ratesInfo , status ) ; finalFactor . multiplyBy ( sourceToBase ) ; if ( unitsState == Convertibility :: CONVERTIBLE ) { finalFactor . divideBy ( targetToBase ) ; } else if ( unitsState == Convertibility :: RECIPROCAL ) { finalFactor . multiplyBy ( targetToBase ) ; } else { status = UErrorCode :: U_ARGUMENT_TYPE_MISMATCH ; return ; } finalFactor . substituteConstants ( ) ; conversionRate . factorNum = finalFactor . factorNum ; conversionRate . factorDen = finalFactor . factorDen ; if ( checkSimpleUnit ( source , status ) && checkSimpleUnit ( target , status ) ) { conversionRate . sourceOffset = sourceToBase . offset * sourceToBase . factorDen / sourceToBase . factorNum ; conversionRate . targetOffset = targetToBase . offset * targetToBase . factorDen / targetToBase . factorNum ; } conversionRate . reciprocal = unitsState == Convertibility :: RECIPROCAL ; }
Extract conversion rate from `source` to `target`
Extract conversion rate from ` source ` to ` target `
// Represents the conversion factor from the source to the target. // Represents the conversion factor from the source to the base unit that specified in the conversion // data which is considered as the root of the source and the target. // Merger Factors // In case of simple units (such as: celsius or fahrenheit), offsets are considered.