瀏覽代碼

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

master
Archivist 6 年之前
父節點
當前提交
01b4f6f1cb
共有 1 個文件被更改,包括 5 次插入5 次删除
  1. +5
    -5
      include/9float.hpp

+ 5
- 5
include/9float.hpp 查看文件

@ -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…
取消
儲存