Skip to content

Commit

Permalink
handle infinities and NaNs correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sinandredemption committed Aug 7, 2021
1 parent b14b339 commit 51c2ba5
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions include/boost/multiprecision/cpp_quad_float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,15 @@ class cpp_quad_float
using std::array;
using std::fabs;
using std::get;
using std::isfinite;
using std::tie;

if (!isfinite(get<0>(this->data)) || !isfinite(get<0>(other.data)))
{
data = (rep_type)std::make_tuple(get<0>(this->data) + get<0>(other.data), 0.0F, 0.0F, 0.0F);
return *this;
}

float_pair u, v;
int i, j, k;

Expand Down Expand Up @@ -417,15 +424,23 @@ class cpp_quad_float

cpp_quad_float& operator*=(const cpp_quad_float& other)
{
using std::get;
using std::tie;
using std::get;
using std::isfinite;
using std::tie;

if (!isfinite(get<0>(this->data)) || !isfinite(get<0>(other.data)))
{
data = (rep_type)std::make_tuple(get<0>(this->data) * get<0>(other.data), 0.0F, 0.0F, 0.0F);
return *this;
}

std::array<float_pair, 10> p;
float_pair r, t, s;
float_type s_;

p[0] = arithmetic::product(get<0>(this->data), get<0>(other.data));


p[1] = arithmetic::product(get<0>(this->data), get<1>(other.data));
p[2] = arithmetic::product(get<1>(this->data), get<0>(other.data));

Expand Down Expand Up @@ -488,11 +503,19 @@ class cpp_quad_float
cpp_quad_float& operator/=(const cpp_quad_float& other)
{
using std::get;
using std::isfinite;

rep_type q;
cpp_quad_float r;

get<0>(q) = get<0>(this->data) / get<0>(other.data);

if (!isfinite(get<0>(q)))
{
data = q;
return *this;
}

r = *this - (other * get<0>(q));

get<1>(q) = get<0>(r.data) / get<0>(other.data);
Expand Down

2 comments on commit 51c2ba5

@sinandredemption
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooray! cpp_quad_float now passes the basic arithmetic test suite of Boost library. I think we can set up a CI accordingly

CC @ckormanyos @cosurgi

@ckormanyos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooray! cpp_quad_float now passes the basic arithmetic test suite of Boost library.

Awesome. I just verified that as well.

Did you know that your PR is set as a draft Pull Request? I think you should remove the draft attribute and we should merge your PR?
I can handle CI and also have some sqrt tests in my own branch that I will happily combine with your progress.
There still does, however, seem to be problems when we hammer cpp_quad_float<float> with millions of random cases of mul/div.

Please sign in to comment.