Changeset 80 for trunk


Ignore:
Timestamp:
Sep 30, 2005 5:30:24 PM (19 years ago)
Author:
dkearney
Message:

one good test deserves another... fixed Rappture.Units.convert("5J","meV")

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/RpUnits.cc

    r79 r80  
    777777    double value = val;
    778778    RpUnits* basis = this->getBasis();
     779    RpUnits* toBasis = toUnit->getBasis();
    779780    RpUnits* fromUnit = this;
    780781    RpUnits* dictToUnit = NULL;
     
    809810
    810811    // find the toUnit in our dictionary.
    811 
    812     dictToUnit = find(toUnit->getUnits());
     812    // if the toUnits has a basis, we need to search for the basis
     813    // and convert between basis' and then convert again back to the
     814    // original unit.
     815    if ( (toBasis) && (toBasis->getUnits() != fromUnit->getUnits()) ) {
     816        dictToUnit = find(toBasis->getUnits());
     817    }
     818    else {
     819        dictToUnit = find(toUnit->getUnits());
     820    }
    813821
    814822    // did we find the unit in the dictionary?
     
    841849
    842850            value = p->conv->convForwFxnPtr(value);
     851           
     852            // check to see if we converted to the actual requested unit
     853            // or to the requested unit's basis.
     854            // if we converted to the requested unit's basis. we need to
     855            // do one last conversion from the requested unit's basis back
     856            // to the requested unit.
     857            if ( (toBasis) && (toBasis->getUnits() != fromUnit->getUnits()) ) {
     858                my_result = 0;
     859                value = toBasis->convert(toUnit,value,&my_result);
     860                if (my_result != 0) {
     861                    if (result) {
     862                        *result += 1;
     863                    }
     864                }
     865            }
     866           
     867            // we can probably remove this
    843868            if (result) {
    844                 *result = 0;
     869                *result += 0;
    845870            }
    846871            break;
     
    852877
    853878            value = p->conv->convBackFxnPtr(value);
     879           
     880            // check to see if we converted to the actual requested unit
     881            // or to the requested unit's basis.
     882            // if we converted to the requested unit's basis. we need to
     883            // do one last conversion from the requested unit's basis back
     884            // to the requested unit.
     885            if ( (toBasis) && (toBasis->getUnits() != fromUnit->getUnits()) ) {
     886                my_result = 0;
     887                value = toBasis->convert(toUnit,value,&my_result);
     888                if (my_result != 0) {
     889                    if (result) {
     890                        *result += 1;
     891                    }
     892                }
     893            }
     894           
     895            // we can probably remove this
    854896            if (result) {
    855                 *result = 0;
     897                *result += 0;
    856898            }
    857899            break;
     
    865907    if ( p == NULL) {
    866908        // we did not find the conversion
     909        if (result) {
     910            *result += 1;
     911        }
    867912        return val;
    868913    }
     
    883928    void* value = val;
    884929    RpUnits* basis = this->getBasis();
     930    RpUnits* toBasis = toUnit->getBasis();
    885931    RpUnits* fromUnit = this;
    886932    RpUnits* dictToUnit = NULL;
     
    915961
    916962    // find the toUnit in our dictionary.
    917 
    918     dictToUnit = find(toUnit->getUnits());
     963    // if the toUnits has a basis, we need to search for the basis
     964    // and convert between basis' and then convert again back to the
     965    // original unit.
     966    if ( (toBasis) && (toBasis->getUnits() != fromUnit->getUnits()) ) {
     967        dictToUnit = find(toBasis->getUnits());
     968    }
     969    else {
     970        dictToUnit = find(toUnit->getUnits());
     971    }
    919972
    920973    // did we find the unit in the dictionary?
     
    9481001            value = p->conv->convForwFxnPtrVoid(p->conv->convForwData,value);
    9491002
     1003            // check to see if we converted to the actual requested unit
     1004            // or to the requested unit's basis.
     1005            // if we converted to the requested unit's basis. we need to
     1006            // do one last conversion from the requested unit's basis back
     1007            // to the requested unit.
     1008            if ( (toBasis) && (toBasis->getUnits() != fromUnit->getUnits()) ) {
     1009                my_result = 0;
     1010                value = toBasis->convert(toUnit,value,&my_result);
     1011                if (my_result != 0) {
     1012                    if (result) {
     1013                        *result += 1;
     1014                    }
     1015                }
     1016            }
     1017           
     1018            // we can probably remove this
    9501019            if (result) {
    9511020                *result = 0;
     
    9591028
    9601029            value = p->conv->convBackFxnPtrVoid(p->conv->convBackData,value);
     1030
     1031            // check to see if we converted to the actual requested unit
     1032            // or to the requested unit's basis.
     1033            // if we converted to the requested unit's basis. we need to
     1034            // do one last conversion from the requested unit's basis back
     1035            // to the requested unit.
     1036            if ( (toBasis) && (toBasis->getUnits() != fromUnit->getUnits()) ) {
     1037                my_result = 0;
     1038                value = toBasis->convert(toUnit,value,&my_result);
     1039                if (my_result != 0) {
     1040                    if (result) {
     1041                        *result += 1;
     1042                    }
     1043                }
     1044            }
     1045           
     1046            // we can probably remove this
    9611047            if (result) {
    9621048                *result = 0;
     
    9721058    if ( p == NULL) {
    9731059        // we did not find the conversion
     1060        if (result) {
     1061            *result += 1;
     1062        }
    9741063        return val;
    9751064    }
Note: See TracChangeset for help on using the changeset viewer.