| 1565 | |
| 1566 | template <unsigned Digits10, class ExponentType, class Allocator> |
| 1567 | double cpp_dec_float<Digits10, ExponentType, Allocator>::extract_double() const |
| 1568 | { |
| 1569 | // Returns the double conversion of a cpp_dec_float<Digits10, ExponentType, Allocator>. |
| 1570 | |
| 1571 | // Check for non-normal cpp_dec_float<Digits10, ExponentType, Allocator>. |
| 1572 | if (!(isfinite)()) |
| 1573 | { |
| 1574 | if ((isnan)()) |
| 1575 | { |
| 1576 | return std::numeric_limits<double>::quiet_NaN(); |
| 1577 | } |
| 1578 | else |
| 1579 | { |
| 1580 | return ((!neg) ? std::numeric_limits<double>::infinity() |
| 1581 | : -std::numeric_limits<double>::infinity()); |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | cpp_dec_float<Digits10, ExponentType, Allocator> xx(*this); |
| 1586 | if (xx.isneg()) |
| 1587 | xx.negate(); |
| 1588 | |
| 1589 | // Check if *this cpp_dec_float<Digits10, ExponentType, Allocator> is zero. |
| 1590 | if (iszero() || (xx.compare(double_min()) < 0)) |
| 1591 | { |
| 1592 | return 0.0; |
| 1593 | } |
| 1594 | |
| 1595 | // Check if *this cpp_dec_float<Digits10, ExponentType, Allocator> exceeds the maximum of double. |
| 1596 | if (xx.compare(double_max()) > 0) |
| 1597 | { |
| 1598 | return ((!neg) ? std::numeric_limits<double>::infinity() |
| 1599 | : -std::numeric_limits<double>::infinity()); |
| 1600 | } |
| 1601 | |
| 1602 | return std::strtod(str(std::numeric_limits<double>::digits10 + (2 + 1), std::ios_base::scientific).c_str(), nullptr); |
| 1603 | } |
| 1604 | |
| 1605 | template <unsigned Digits10, class ExponentType, class Allocator> |
| 1606 | long double cpp_dec_float<Digits10, ExponentType, Allocator>::extract_long_double() const |