rational: assert the denominator is nonzero on reduce
this placates clang-analyzer
This commit is contained in:
parent
3a4f6ffce8
commit
e0fb8e4e6b
@ -17,6 +17,7 @@
|
|||||||
#include "rational.hpp"
|
#include "rational.hpp"
|
||||||
|
|
||||||
#include "maths.hpp"
|
#include "maths.hpp"
|
||||||
|
#include "debug.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@ -109,6 +110,7 @@ template <typename T>
|
|||||||
rational<T>
|
rational<T>
|
||||||
rational<T>::reduced (void) const
|
rational<T>::reduced (void) const
|
||||||
{
|
{
|
||||||
|
CHECK_NEZ (d);
|
||||||
auto x = std::gcd (abs (n), abs (d));
|
auto x = std::gcd (abs (n), abs (d));
|
||||||
|
|
||||||
return { n / x, d / x };
|
return { n / x, d / x };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user