Mercurial > hgweb.cgi > pecunia
changeset 202:294201d07167
Replaced in Money the old floating-point verification function with verified type.
author | John Schneiderman <JohnMS@member.fsf.org> |
---|---|
date | Mon, 08 Mar 2021 19:12:10 +0100 |
parents | 46d7580c8bb5 |
children | 9b7b082734ca |
files | src/external/pecunia/Money.cpp src/internal/Verification.cpp src/internal/Verification.h |
diffstat | 3 files changed, 16 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/external/pecunia/Money.cpp Mon Mar 08 19:03:12 2021 +0100 +++ b/src/external/pecunia/Money.cpp Mon Mar 08 19:12:10 2021 +0100 @@ -73,7 +73,7 @@ using pecunia::currency::internal::normaliseAmount; #include "internal/Verification.h" using pecunia::internal::isEqual; -using pecunia::internal::verifiedFloatingPoint; +using pecunia::internal::VerifiedFloatingPoint; using pecunia::internal::VerifiedValue; using pecunia::internal::verifyAdditionFits; using pecunia::internal::verifyDivisionFits; @@ -714,8 +714,8 @@ minorUnitPrecisionFactor(this->iso4217Code_) * static_cast<int32_t>(pow(10, extraFloatingPointPrecision)) }; - const auto adjustedValue{verifiedFloatingPoint(value * unitRatio)}; - *this *= static_cast<int64_t>(adjustedValue); + const auto adjustedValue{VerifiedFloatingPoint{value} * VerifiedFloatingPoint{unitRatio}}; + *this *= static_cast<int64_t>(adjustedValue.value()); this->amount_ /= unitRatio; return *this; } @@ -841,7 +841,7 @@ }; const auto adjustedValue{ static_cast<UnitStorage>( - verifiedFloatingPoint(value * static_cast<FloatingPoint>(unitRatio)) + (VerifiedFloatingPoint{value} * VerifiedFloatingPoint{unitRatio}).value() ) }; const auto adjustedAmount{this->amount_ * unitRatio};
--- a/src/internal/Verification.cpp Mon Mar 08 19:03:12 2021 +0100 +++ b/src/internal/Verification.cpp Mon Mar 08 19:12:10 2021 +0100 @@ -19,6 +19,7 @@ *******************************************************************************/ #include "Verification.h" using std::int32_t; +using std::int64_t; using std::uint8_t; using pecunia::precision; using pecunia::MinorUnit; @@ -73,13 +74,21 @@ } VerifiedFloatingPoint::VerifiedFloatingPoint() : - VerifiedFloatingPoint{0} + VerifiedFloatingPoint{static_cast<FloatingPoint>(0)} {} VerifiedFloatingPoint::VerifiedFloatingPoint(const FloatingPoint& value) : value_{value} {} +VerifiedFloatingPoint::VerifiedFloatingPoint(const int32_t& value) : + VerifiedFloatingPoint{static_cast<FloatingPoint>(value)} +{} + +VerifiedFloatingPoint::VerifiedFloatingPoint(const int64_t& value) : + VerifiedFloatingPoint{static_cast<FloatingPoint>(value)} +{} + VerifiedFloatingPoint::VerifiedFloatingPoint(const VerifiedFloatingPoint& vfp) : value_{vfp.value_} {}
--- a/src/internal/Verification.h Mon Mar 08 19:03:12 2021 +0100 +++ b/src/internal/Verification.h Mon Mar 08 19:12:10 2021 +0100 @@ -44,6 +44,8 @@ public: VerifiedFloatingPoint(); explicit VerifiedFloatingPoint(const FloatingPoint& value); + explicit VerifiedFloatingPoint(const std::int32_t& value); + explicit VerifiedFloatingPoint(const std::int64_t& value); VerifiedFloatingPoint(const VerifiedFloatingPoint& vfp); VerifiedFloatingPoint(VerifiedFloatingPoint&& vfp) noexcept; VerifiedFloatingPoint& operator=(const VerifiedFloatingPoint& vfp);