Browse Source

Added some safeguards against default "1" value in C++

master
Archivist 5 years ago
parent
commit
01b4f6f1cb
1 changed files with 5 additions and 5 deletions
  1. +5
    -5
      include/9float.hpp

+ 5
- 5
include/9float.hpp View File

@ -27,7 +27,7 @@ public:
template<class srcT>
constexpr Q (const srcT value)
: backend{(integer_type)(value*(1<<degen))}
: backend{(integer_type)(value*(p">((integer_type)1)<<degen))}
{}
constexpr Q ()
@ -43,7 +43,7 @@ public:
constexpr bool is_negative()
{
return backend&(1<<(sizeof(backend)-1));
return backend&(p">((integer_type)1)<<(sizeof(backend)-1));
}
@ -71,7 +71,7 @@ public:
constexpr Q<integer_type, fractionals>& operator/=(const Q& oth)
{
backend*=1<<Q<integer_type, fractionals>::degen;
backend*=p">((integer_type)1)<<Q<integer_type, fractionals>::degen;
backend/=oth.backend;
return *this;
}
@ -145,14 +145,14 @@ public:
constexpr operator float()
{
float n=backend;
n/=(1<<Q<integer_type, fractionals>::degen);
n/=(p">((integer_type)1)<<Q<integer_type, fractionals>::degen);
return n;
}
constexpr operator double()
{
double n=backend;
n/=(1<<Q<integer_type, fractionals>::degen);
n/=(p">((integer_type)1)<<Q<integer_type, fractionals>::degen);
return n;
}
};

Loading…
Cancel
Save