| 1516 | |
| 1517 | template <unsigned Digits10, class ExponentType, class Allocator> |
| 1518 | void cpp_dec_float<Digits10, ExponentType, Allocator>::extract_parts(double& mantissa, ExponentType& exponent) const |
| 1519 | { |
| 1520 | // Extract the approximate parts mantissa and base-10 exponent from the input cpp_dec_float<Digits10, ExponentType, Allocator> value x. |
| 1521 | |
| 1522 | // Extracts the mantissa and exponent. |
| 1523 | exponent = exp; |
| 1524 | |
| 1525 | std::uint32_t p10 = static_cast<std::uint32_t>(1u); |
| 1526 | std::uint32_t test = data[0u]; |
| 1527 | |
| 1528 | for (;;) |
| 1529 | { |
| 1530 | test /= static_cast<std::uint32_t>(10u); |
| 1531 | |
| 1532 | if (test == static_cast<std::uint32_t>(0u)) |
| 1533 | { |
| 1534 | break; |
| 1535 | } |
| 1536 | |
| 1537 | p10 *= static_cast<std::uint32_t>(10u); |
| 1538 | ++exponent; |
| 1539 | } |
| 1540 | |
| 1541 | // Establish the upper bound of limbs for extracting the double. |
| 1542 | const int max_elem_in_double_count = static_cast<int>(static_cast<std::int32_t>(std::numeric_limits<double>::digits10) / cpp_dec_float_elem_digits10) + (static_cast<int>(static_cast<std::int32_t>(std::numeric_limits<double>::digits10) % cpp_dec_float_elem_digits10) != 0 ? 1 : 0) + 1; |
| 1543 | |
| 1544 | // And make sure this upper bound stays within bounds of the elems. |
| 1545 | const std::size_t max_elem_extract_count = static_cast<std::size_t>((std::min)(static_cast<std::int32_t>(max_elem_in_double_count), cpp_dec_float_elem_number)); |
| 1546 | |
| 1547 | // Extract into the mantissa the first limb, extracted as a double. |
| 1548 | mantissa = static_cast<double>(data[0]); |
| 1549 | double scale = 1.0; |
| 1550 | |
| 1551 | // Extract the rest of the mantissa piecewise from the limbs. |
| 1552 | for (std::size_t i = 1u; i < max_elem_extract_count; i++) |
| 1553 | { |
| 1554 | scale /= static_cast<double>(cpp_dec_float_elem_mask); |
| 1555 | mantissa += (static_cast<double>(data[i]) * scale); |
| 1556 | } |
| 1557 | |
| 1558 | mantissa /= static_cast<double>(p10); |
| 1559 | |
| 1560 | if (neg) |
| 1561 | { |
| 1562 | mantissa = -mantissa; |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | template <unsigned Digits10, class ExponentType, class Allocator> |
| 1567 | double cpp_dec_float<Digits10, ExponentType, Allocator>::extract_double() const |