|
ACF $AcfVersion:0$
|
Implementation of double value manipulator with fixed-point arithmetic and rounding. More...
#include <CFixedPointManip.h>
Public Types | |
| enum | RoundingType { RT_NORMAL , RT_FLOOR , RT_CEIL , RT_LAST = RT_CEIL + 1 } |
| typedef CDoubleManip | BaseClass |
Public Member Functions | |
| CFixedPointManip (int precision=1, RoundingType roundingType=RT_NORMAL) | |
| void | SetPrecision (int precision) |
| Set fixed point precision. | |
| RoundingType | GetRoundingType () const |
| Get type of rounding. | |
| void | SetRoundingType (RoundingType roundingType) |
| Set type of rounding. | |
| virtual int | GetPrecision () const override |
| Get number of digits after point. | |
| virtual double | GetRounded (const double &value) const override |
| Get the nearest value rounded used this arithmetik. | |
| virtual bool | AreValuesEqual (const double &value1, const double &value2) const override |
| Compare two values and check, if there are equal. | |
| virtual bool | IsSmaller (const double &value1, const double &value2) const override |
| Compare two values and check, if first one is smaller as the second. | |
| virtual bool | IsSmallerEqual (const double &value1, const double &value2) const override |
| Compare two values and check, if first one is smaller or equal as the second. | |
| virtual double | GetSmallerValue (const double &value) const override |
| Return biggest value smaller that specified one. | |
| virtual double | GetBiggerValue (const double &value) const override |
| Return smallest value bigger that specified one. | |
| virtual QString | GetString (const double &value) const override |
| Get this value as string. | |
| virtual bool | GetParsed (const QString &text, double &result) const override |
| Get value converted from string. | |
Public Member Functions inherited from imath::CDoubleManip | |
| CDoubleManip () | |
| char | GetPointChar () const |
| Get point character. | |
| void | SetPointChar (char pointChar) |
| Set point character. | |
Public Member Functions inherited from istd::IPolymorphic | |
| virtual | ~IPolymorphic () |
Protected Types | |
| typedef int(* | RoundingFuntionPtr) (qreal value) |
Protected Types inherited from imath::CDoubleManip | |
| enum | { PRECISION = 6 } |
Protected Member Functions | |
| virtual qint32 | GetInternalValue (double value) const |
| virtual double | GetNormalValue (qint32 intValue) const |
| QString | GetString (const double &value, int precision) const |
Implementation of double value manipulator with fixed-point arithmetic and rounding.
CFixedPointManip provides manipulation of double precision values with fixed decimal precision, simulating fixed-point arithmetic. It rounds values to a specified number of decimal places and ensures consistent behavior for financial calculations, user interfaces, and scenarios where exact decimal representation is required. Extends CDoubleManip with configurable precision and rounding modes.
RT_NORMAL** - Mathematical rounding (nearest value, 0.5 rounds up):
1.235 -> 1.24 (precision=2)
RT_FLOOR** - Always round toward negative infinity:
-1.231 -> -1.24 (precision=2)
RT_CEIL** - Always round toward positive infinity:
Financial/Currency Applications**:
Ensures consistent display ($1.50, not $1.5)
User Interface Controls**:
Display fields with consistent formatting
Fixed-Resolution Measurements**:
Quantized values from hardware
Scientific Data with Fixed Precision**:
The precision parameter represents the number of decimal places:
Definition at line 126 of file CFixedPointManip.h.
Definition at line 129 of file CFixedPointManip.h.
|
protected |
Definition at line 177 of file CFixedPointManip.h.
| Enumerator | |
|---|---|
| RT_NORMAL | Normal mathematical rounding to the nearest value. |
| RT_FLOOR | Rounding down. |
| RT_CEIL | Rounding up. |
| RT_LAST | |
Definition at line 131 of file CFixedPointManip.h.
| imath::CFixedPointManip::CFixedPointManip | ( | int | precision = 1, |
| RoundingType | roundingType = RT_NORMAL |
||
| ) |
|
inlineoverridevirtual |
Compare two values and check, if there are equal.
| value1 | first value. |
| value2 | second value. |
Reimplemented from imath::CDoubleManip.
Definition at line 210 of file CFixedPointManip.h.
References GetInternalValue().
|
inlineoverridevirtual |
Return smallest value bigger that specified one.
Reimplemented from imath::CDoubleManip.
Definition at line 234 of file CFixedPointManip.h.
References GetInternalValue(), and GetNormalValue().
|
inlineprotectedvirtual |
Reimplemented in imath::CComplexDoubleManip.
Definition at line 242 of file CFixedPointManip.h.
Referenced by AreValuesEqual(), GetBiggerValue(), GetRounded(), GetSmallerValue(), IsSmaller(), and IsSmallerEqual().
|
inlineprotectedvirtual |
Definition at line 250 of file CFixedPointManip.h.
Referenced by GetBiggerValue(), GetRounded(), and GetSmallerValue().
|
overridevirtual |
Get value converted from string.
| text | input string. |
| result | result value. |
Reimplemented from imath::CDoubleManip.
Reimplemented in imath::CComplexDoubleManip.
|
overridevirtual |
Get number of digits after point.
Reimplemented from imath::CDoubleManip.
Referenced by imath::CComplexDoubleManip::SetPrecision(), and imath::CComplexDoubleManip::SetScaleFactor().
|
inlineoverridevirtual |
Get the nearest value rounded used this arithmetik.
Reimplemented from imath::CDoubleManip.
Definition at line 204 of file CFixedPointManip.h.
References GetInternalValue(), and GetNormalValue().
|
inline |
Get type of rounding.
Definition at line 196 of file CFixedPointManip.h.
|
inlineoverridevirtual |
Return biggest value smaller that specified one.
Reimplemented from imath::CDoubleManip.
Definition at line 228 of file CFixedPointManip.h.
References GetInternalValue(), and GetNormalValue().
|
overridevirtual |
Get this value as string.
| value | value will be converted. |
Reimplemented from imath::CDoubleManip.
Reimplemented in imath::CComplexDoubleManip.
|
protected |
|
inlineoverridevirtual |
Compare two values and check, if first one is smaller as the second.
| value1 | first value. |
| value2 | second value. |
Reimplemented from imath::CDoubleManip.
Definition at line 216 of file CFixedPointManip.h.
References GetInternalValue().
|
inlineoverridevirtual |
Compare two values and check, if first one is smaller or equal as the second.
| value1 | first value. |
| value2 | second value. |
Reimplemented from imath::CDoubleManip.
Definition at line 222 of file CFixedPointManip.h.
References GetInternalValue().
| void imath::CFixedPointManip::SetPrecision | ( | int | precision | ) |
Set fixed point precision.
Referenced by imath::CComplexDoubleManip::SetPrecision().
| void imath::CFixedPointManip::SetRoundingType | ( | RoundingType | roundingType | ) |
Set type of rounding.