mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 11:25:33 +08:00
Ref T215, PQ integer support
This commit is contained in:
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user