diff options
author | David Wagner <david.wagner@intel.com> | 2014-05-09 17:25:13 +0200 |
---|---|---|
committer | Mattijs Korpershoek <mattijsx.korpershoek@intel.com> | 2014-06-25 10:52:29 +0200 |
commit | d299108157ee4d0eadb7683b2fa6a6635bc63d95 (patch) | |
tree | 5a5e876ce87153e74c8fd7687ac12ab0a90c0d1b /parameter | |
parent | e874c2575c1203648e71426cd34f747cbd34b2b4 (diff) | |
download | external_parameter-framework-d299108157ee4d0eadb7683b2fa6a6635bc63d95.zip external_parameter-framework-d299108157ee4d0eadb7683b2fa6a6635bc63d95.tar.gz external_parameter-framework-d299108157ee4d0eadb7683b2fa6a6635bc63d95.tar.bz2 |
FixedPointParameter: Removed precision notion
BZ: 197723
Significant digits were computed in order to prevent odd behaviour when printing
a converted fixed point parameter. After converting a number from fixed
point towards a double, we had to round up/down in order to print the
double to the user (or towards a file).
The printing showed only the significant digits, in other words, the
digits which can vary from 0 to 9. This caused unpredictable behaviour
when rounding using the setPrecision() function.
This patch removes the 'precision' notion related to fixed points in
order to have a predictable behaviour by displaying all fractional
digits.
Change-Id: Id5a9b5b8a80d5a96bcbbb6af9213770a05a70083
Signed-off-by: Mattijs Korpershoek <mattijsx.korpershoek@intel.com>
Diffstat (limited to 'parameter')
-rw-r--r-- | parameter/FixedPointParameterType.cpp | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp index 067f311..33d79e1 100644 --- a/parameter/FixedPointParameterType.cpp +++ b/parameter/FixedPointParameterType.cpp @@ -147,7 +147,8 @@ void CFixedPointParameterType::setOutOfRangeError(const string& strValue, CParam double dMax = 0; getRange(dMin, dMax); - strStream << "real range [" << dMin << ", " << dMax << "]"; + strStream << fixed << setprecision(_uiFractional) + << "real range [" << dMin << ", " << dMax << "]"; } else { // Min/Max computation @@ -209,28 +210,7 @@ bool CFixedPointParameterType::fromBlackboard(string& strValue, const uint32_t& // Conversion double dData = asDouble(iData); - // Set up the precision of the display and notation type - // For a Qn.m number, the step between each storable number is 2^(-m). - // Hence, on a decimal representation, the Dth digit after the decimal - // point can take all possible values (1..9) - meaning that it is - // significant - only if - // - // 2^(-m) <= 10^(-D) - // -m <= log2(10^(-D)) - // -m <= log10(10^(-D)) / log10(2) - // -m <= -D / log10(2) - // m * log10(2) >= D - // - // Conversly, the Dth digit can be represented if - // - // D <= m * log10(2) - // - // Since floor(x) <= x, we can write (replacing D with iPrecision and m - // with _uiFractional) this next line. - // (we add 1 to avoid losing precision even though this last digit is - // not 100% significant) - int iPrecision = (_uiFractional * log10(2.0)) + 1; - strStream << fixed << setprecision(iPrecision) << dData; + strStream << fixed << setprecision(_uiFractional) << dData; } strValue = strStream.str(); |