From cf014375b8b408d58bd35deb4e58e4369fb3bf62 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 22 Aug 2013 14:21:16 -0700 Subject: SH-4433 FIX: Interesting: Statistics > Ping Sim is always 0 ms removed bad assert fixed precision issues during int->unsigned int conversions and vice versa --- indra/llcommon/lltraceaccumulators.cpp | 1 - indra/llcommon/llunit.h | 23 +++++++++++++++++------ indra/llcommon/tests/llunits_test.cpp | 16 ++++++++++++++++ indra/llui/llstatbar.cpp | 2 +- 4 files changed, 34 insertions(+), 8 deletions(-) (limited to 'indra') diff --git a/indra/llcommon/lltraceaccumulators.cpp b/indra/llcommon/lltraceaccumulators.cpp index c79c102afd..5e25ad6b26 100644 --- a/indra/llcommon/lltraceaccumulators.cpp +++ b/indra/llcommon/lltraceaccumulators.cpp @@ -147,7 +147,6 @@ void SampleAccumulator::addSamples( const SampleAccumulator& other, EBufferAppen if (other.mTotalSamplingTime > epsilon) { - llassert(mTotalSamplingTime > 0); // combine variance (and hence standard deviation) of 2 different sized sample groups using // the following formula: http://www.mrc-bsu.cam.ac.uk/cochrane/handbook/chapter_7/7_7_3_8_combining_groups.htm F64 n_1 = mTotalSamplingTime, diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index f42456fe72..bfc011bb55 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -69,6 +69,12 @@ struct LLResultTypeDivide typedef LL_TYPEOF(S() / T(1)) type_t; }; +template +struct LLResultTypePromote +{ + typedef LL_TYPEOF((true) ? S() : T()) type_t; +}; + template struct LLUnit { @@ -155,10 +161,11 @@ struct LLUnit template static self_t convert(LLUnit v) { - self_t result; - STORAGE_TYPE divisor = ll_convert_units(v, result); - result.mValue /= divisor; - return result; + typedef typename LLResultTypePromote::type_t result_storage_t; + LLUnit result; + result_storage_t divisor = ll_convert_units(v, result); + result.value(result.value() / divisor); + return self_t(result.value()); } protected: @@ -695,7 +702,9 @@ struct unit_name template \ S2 ll_convert_units(LLUnit in, LLUnit& out) \ { \ - LLUnitLinearOps op = LLUnitLinearOps(in.value()) conversion_operation; \ + typedef typename LLResultTypePromote::type_t result_storage_t; \ + LLUnitLinearOps op = \ + LLUnitLinearOps(in.value()) conversion_operation; \ out = LLUnit((S2)op.mValue); \ return op.mDivisor; \ } \ @@ -703,7 +712,9 @@ S2 ll_convert_units(LLUnit in, LLUnit& out) template \ S2 ll_convert_units(LLUnit in, LLUnit& out) \ { \ - LLUnitInverseLinearOps op = LLUnitInverseLinearOps(in.value()) conversion_operation; \ + typedef typename LLResultTypePromote::type_t result_storage_t; \ + LLUnitInverseLinearOps op = \ + LLUnitInverseLinearOps(in.value()) conversion_operation; \ out = LLUnit((S2)op.mValue); \ return op.mDivisor; \ } diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index b8aef9d15e..292c6122af 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -257,4 +257,20 @@ namespace tut LLUnitImplicit latinum_implicit(2); ensure("implicit units of different types are comparable", latinum_implicit * 2 == quatloos_implicit); } + + // precision tests + template<> template<> + void units_object_t::test<8>() + { + U32Bytes max_bytes(U32_MAX); + S32Megabytes mega_bytes = max_bytes; + ensure("max available precision is used when converting units", mega_bytes == (S32Megabytes)4095); + + mega_bytes = (S32Megabytes)-5 + (U32Megabytes)1; + ensure("can mix signed and unsigned in units addition", mega_bytes == (S32Megabytes)-4); + + mega_bytes = (U32Megabytes)5 + (S32Megabytes)-1; + ensure("can mix unsigned and signed in units addition", mega_bytes == (S32Megabytes)4); + + } } diff --git a/indra/llui/llstatbar.cpp b/indra/llui/llstatbar.cpp index 8658a2f968..3cd2e53001 100755 --- a/indra/llui/llstatbar.cpp +++ b/indra/llui/llstatbar.cpp @@ -401,7 +401,7 @@ void LLStatBar::draw() { mLastDisplayValueTimer.reset(); } - drawLabelAndValue(display_value, unit_label, bar_rect, mDecimalDigits); + drawLabelAndValue(display_value, unit_label, bar_rect, decimal_digits); mLastDisplayValue = display_value; -- cgit v1.2.3