Math with temperature values is not as expected.

For addition and subtraction,  we created a new routine that
only scales second units to the first.  We apply it to all
conversions when adding and subtracting, but it only changes
the temperature results, because that is the only units that
has a bias factor. The comparision conversion routines were not
changed.

refs #202
This commit is contained in:
Alex Lin 2016-03-16 16:54:25 -05:00
parent 4ff8591b12
commit 552f73d3a5
4 changed files with 62 additions and 16 deletions

View File

@ -34,3 +34,47 @@ int convert_united_value( std::string & to_units , std::string & from_units , do
return 0 ;
}
int scale_united_value( std::string & to_units , std::string & from_units , long long * val ) {
if ( from_units.compare("--") ) {
try {
Units_t * from = new_units(from_units.c_str()) ;
Units_t * to = new_units(to_units.c_str()) ;
UnitsConvFn_t conv_fn;
if (conv_fn_u(from, to, &conv_fn) != CONV_OK) {
throw Unit::CONVERSION_ERROR();
}
*val = (long long)(conv_fn.C[1] * (*val)) ;
free(from) ;
free(to) ;
}
catch (Unit::CONVERSION_ERROR & ce_err ) {
PyErr_SetString(PyExc_AttributeError,"Units conversion Error");
return -1 ;
}
}
return 0 ;
}
int scale_united_value( std::string & to_units , std::string & from_units , double * val ) {
if ( from_units.compare("--") ) {
try {
Units_t * from = new_units(from_units.c_str()) ;
Units_t * to = new_units(to_units.c_str()) ;
UnitsConvFn_t conv_fn;
if (conv_fn_u(from, to, &conv_fn) != CONV_OK) {
throw Unit::CONVERSION_ERROR();
}
*val = conv_fn.C[1] * (*val) ;
free(from) ;
free(to) ;
}
catch (Unit::CONVERSION_ERROR & ce_err ) {
PyErr_SetString(PyExc_AttributeError,"Units conversion Error");
return -1 ;
}
}
return 0 ;
}

View File

@ -6,4 +6,6 @@
int convert_united_value( std::string & to_units , std::string & from_units , long long * val ) ;
int convert_united_value( std::string & to_units , std::string & from_units , double * val ) ;
int scale_united_value( std::string & to_units , std::string & from_units , long long * val ) ;
int scale_united_value( std::string & to_units , std::string & from_units , double * val ) ;
#endif

View File

@ -46,7 +46,7 @@ PyObject * swig_double::__add__( PyObject * obj1 ) {
swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ;
new_value = (double)temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_value ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_value ) ;
if ( conv_ret == 0 ) {
result->value = value + new_value ;
} else {
@ -55,7 +55,7 @@ PyObject * swig_double::__add__( PyObject * obj1 ) {
} else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_double *"), 0 ))) {
swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ;
new_value = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_value ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_value ) ;
if ( conv_ret == 0 ) {
result->value = value + new_value ;
} else {
@ -86,7 +86,7 @@ PyObject * swig_double::__sub__( PyObject * obj1 ) {
swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ;
new_value = (double)temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_value ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_value ) ;
if ( conv_ret == 0 ) {
result->value = value - new_value ;
} else {
@ -95,7 +95,7 @@ PyObject * swig_double::__sub__( PyObject * obj1 ) {
} else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_double *"), 0 ))) {
swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ;
new_value = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_value ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_value ) ;
if ( conv_ret == 0 ) {
result->value = value - new_value ;
} else {
@ -450,7 +450,7 @@ PyObject * swig_double::__iadd__( PyObject * obj1 ) {
} else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_int *"), 0 ))) {
swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ;
new_val = (double)temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
value += new_val ;
} else {
@ -459,7 +459,7 @@ PyObject * swig_double::__iadd__( PyObject * obj1 ) {
} else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_double *"), 0 ))) {
swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ;
new_val = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
value += new_val ;
} else {
@ -485,7 +485,7 @@ PyObject * swig_double::__isub__( PyObject * obj1 ) {
} else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_int *"), 0 ))) {
swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ;
new_val = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
value -= new_val ;
} else {
@ -494,7 +494,7 @@ PyObject * swig_double::__isub__( PyObject * obj1 ) {
} else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_double *"), 0 ))) {
swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ;
new_val = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
value -= new_val ;
} else {

View File

@ -43,7 +43,7 @@ PyObject * swig_int::__add__( PyObject * obj1 ) {
long long new_val ;
swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ;
new_val = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
result->value = value + new_val ;
} else {
@ -53,7 +53,7 @@ PyObject * swig_int::__add__( PyObject * obj1 ) {
double new_val ;
swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ;
new_val = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
result->value = (long long)(round(value + new_val)) ;
} else {
@ -83,7 +83,7 @@ PyObject * swig_int::__sub__( PyObject * obj1 ) {
long long new_val ;
swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ;
new_val = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
result->value = value - new_val ;
} else {
@ -93,7 +93,7 @@ PyObject * swig_int::__sub__( PyObject * obj1 ) {
double new_val ;
swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ;
new_val = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
result->value = (long long)(round(value - new_val)) ;
} else {
@ -626,7 +626,7 @@ PyObject * swig_int::__iadd__( PyObject * obj1 ) {
long long new_val ;
swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ;
new_val = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
value += new_val ;
} else {
@ -636,7 +636,7 @@ PyObject * swig_int::__iadd__( PyObject * obj1 ) {
double new_val ;
swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ;
new_val = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
value = (long long)round(value + new_val) ;
} else {
@ -663,7 +663,7 @@ PyObject * swig_int::__isub__( PyObject * obj1 ) {
long long new_val ;
swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ;
new_val = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
value -= new_val ;
} else {
@ -673,7 +673,7 @@ PyObject * swig_int::__isub__( PyObject * obj1 ) {
double new_val ;
swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ;
new_val = temp_m->value ;
conv_ret = convert_united_value( units , temp_m->units , &new_val ) ;
conv_ret = scale_united_value( units , temp_m->units , &new_val ) ;
if ( conv_ret == 0 ) {
value = (long long)round(value - new_val) ;
} else {