Ref T215, PQ integer support

This commit is contained in:
Klaus Basan
2018-01-03 20:04:38 +01:00
parent 35af956c95
commit b2c0d726bc
2 changed files with 22 additions and 1 deletions

View File

@@ -318,10 +318,25 @@ namespace BlackMisc
int CPhysicalQuantity<MU, PQ>::valueInteger(MU unit) const int CPhysicalQuantity<MU, PQ>::valueInteger(MU unit) const
{ {
Q_ASSERT_X(!unit.isNull(), Q_FUNC_INFO, "Cannot convert to null"); Q_ASSERT_X(!unit.isNull(), Q_FUNC_INFO, "Cannot convert to null");
double v = unit.roundValue(this->value(unit), 0); const double v = unit.roundValue(this->value(unit), 0);
return static_cast<int>(v); return static_cast<int>(v);
} }
template<class MU, class PQ>
int CPhysicalQuantity<MU, PQ>::valueInteger() const
{
return this->valueInteger(m_unit);
}
template<class MU, class PQ>
bool CPhysicalQuantity<MU, PQ>::isInteger() const
{
if (this->isNull()) { return false; }
const double diff = std::abs(this->value() - this->valueInteger());
return diff <= m_unit.getEpsilon();
}
template <class MU, class PQ> template <class MU, class PQ>
double CPhysicalQuantity<MU, PQ>::valueRounded(int digits) const double CPhysicalQuantity<MU, PQ>::valueRounded(int digits) const
{ {

View File

@@ -107,6 +107,12 @@ namespace BlackMisc
//! As integer value //! As integer value
int valueInteger(MU unit) const; int valueInteger(MU unit) const;
//! As integer value in current unit
int valueInteger() const;
//! Is value an integer
bool isInteger() const;
//! Rounded value in current unit //! Rounded value in current unit
//! \note default digits is CMeasurementUnit::getDisplayDigits //! \note default digits is CMeasurementUnit::getDisplayDigits
double valueRounded(int digits = -1) const; double valueRounded(int digits = -1) const;