Fixed a divide by 0 error

This commit is contained in:
Yousef Khadadeh 2025-08-04 11:32:27 +03:00
parent d261293d6b
commit c5b9187216

View file

@ -399,14 +399,14 @@ namespace FixedPoint {
}
explicit operator float() const {
if(isReciprocal)
if(isReciprocal && val != UnderlyingNumber(0))
return 1.0f / static_cast<float>(val);
else
return static_cast<float>(val);
}
explicit operator double() const {
if(isReciprocal)
if(isReciprocal && val != UnderlyingNumber(0))
return 1.0 / static_cast<double>(val);
else
return static_cast<double>(val);
@ -427,7 +427,7 @@ namespace FixedPoint {
}
explicit operator UnderlyingNumber() const {
if(isReciprocal)
if(isReciprocal && val != UnderlyingNumber(0))
return UnderlyingNumber(1) / val;
else
return val;