[Boost-bugs] [Boost C++ Libraries] #12157: Dividing zero by zero produces one in boost::multiprecision::cpp_dec_float

Subject: [Boost-bugs] [Boost C++ Libraries] #12157: Dividing zero by zero produces one in boost::multiprecision::cpp_dec_float
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-04-26 17:05:41


#12157: Dividing zero by zero produces one in boost::multiprecision::cpp_dec_float
------------------------------+----------------------------
 Reporter: vfaion@… | Owner: johnmaddock
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: multiprecision
  Version: Boost 1.60.0 | Severity: Problem
 Keywords: divide |
------------------------------+----------------------------
 When using Boost multiprecision, dividing 0/0 produces 1. I would expected
 the result to be inf. When dividing other numbers by zero it does produce
 inf.

 {{{
 #include<iostream>
 #include<boost/multiprecision/cpp_dec_float.hpp>

 typedef
 boost::multiprecision::number<boost::multiprecision::cpp_dec_float<0>>
 BigFloat;

 int main() {
    BigFloat zero(0);
    BigFloat one(1);
    std::cout << zero / zero << std::endl;
    std::cout << one / zero << std::endl;
 }

 }}}

 I looked at operator/ from here:
 http://www.boost.org/doc/libs/1_60_0/boost/multiprecision/cpp_dec_float.hpp
 I think adding the case "if(iszero() && v.iszero())" as below could solve
 this issue.


 {{{
 template <unsigned Digits10, class ExponentType, class Allocator>
 cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10,
 ExponentType, Allocator>::operator/=(const cpp_dec_float<Digits10,
 ExponentType, Allocator>& v)
 {
    if(iszero() && v.iszero())
    {
       *this = inf();
       return *this;
    }

    const bool u_and_v_are_finite_and_identical = ( (isfinite)()
       && (fpclass == v.fpclass)
       && (exp == v.exp)
       && (cmp_data(v.data) == static_cast<boost::int32_t>(0)));

    if(u_and_v_are_finite_and_identical)
    {
       if(neg != v.neg)
       {
          *this = one();
          negate();
       }
       else
          *this = one();
       return *this;
    }
    else
    {
       if(iszero())
       {
          if((v.isnan)() || v.iszero())
          {
             return *this = v;
          }
          return *this;
       }
       cpp_dec_float t(v);
       t.calculate_inv();
       return operator*=(t);
    }
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12157>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC