Skip to content

Commit bd61cea

Browse files
authored
Merge pull request #159 from BoostGSoC21/syntax_and_first_todos
Start improving syntax and TODOs
2 parents 2f5c93a + ed66654 commit bd61cea

File tree

1 file changed

+7
-68
lines changed

1 file changed

+7
-68
lines changed

include/boost/multiprecision/cpp_double_fp.hpp

+7-68
Original file line numberDiff line numberDiff line change
@@ -1402,18 +1402,13 @@ constexpr void eval_fabs(cpp_double_fp_backend<FloatingPointType>& result, const
14021402
template <typename FloatingPointType>
14031403
constexpr void eval_frexp(cpp_double_fp_backend<FloatingPointType>& result, const cpp_double_fp_backend<FloatingPointType>& a, int* v)
14041404
{
1405-
#if 0
1406-
result.rep().first = cpp_df_qf_detail::ccmath::frexp(a.rep().first, v);
1407-
result.rep().second = cpp_df_qf_detail::ccmath::ldexp(a.rep().second, -*v);
1408-
#else
14091405
using local_backend_type = cpp_double_fp_backend<FloatingPointType>;
14101406
using local_float_type = typename local_backend_type::float_type;
14111407

14121408
const local_float_type fhi { cpp_df_qf_detail::ccmath::frexp(a.rep().first, v) };
14131409
const local_float_type flo { cpp_df_qf_detail::ccmath::ldexp(a.rep().second, -*v) };
14141410

14151411
local_backend_type::arithmetic::normalize(result.rep(), fhi, flo);
1416-
#endif
14171412
}
14181413

14191414
template <typename FloatingPointType>
@@ -1431,41 +1426,6 @@ constexpr void eval_ldexp(cpp_double_fp_backend<FloatingPointType>& result, cons
14311426
template <typename FloatingPointType>
14321427
constexpr void eval_floor(cpp_double_fp_backend<FloatingPointType>& result, const cpp_double_fp_backend<FloatingPointType>& x)
14331428
{
1434-
#if 0
1435-
using double_float_type = cpp_double_fp_backend<FloatingPointType>;
1436-
1437-
const typename double_float_type::float_type fhi = cpp_df_qf_detail::floor_of_constituent(x.my_first());
1438-
1439-
if (fhi != x.my_first())
1440-
{
1441-
result.rep().first = fhi;
1442-
result.rep().second = static_cast<typename double_float_type::float_type>(0.0F);
1443-
}
1444-
else
1445-
{
1446-
const bool is_fractional_lo { cpp_df_qf_detail::ccmath::fabs(x.my_second()) < 1 };
1447-
const bool is_negative_lo { x.my_second() < 0 };
1448-
1449-
if (is_fractional_lo)
1450-
{
1451-
if (is_negative_lo)
1452-
{
1453-
result.rep().first = fhi - typename double_float_type::float_type { 1 };
1454-
result.rep().second = typename double_float_type::float_type { 0 };
1455-
}
1456-
else
1457-
{
1458-
result.rep().first = fhi;
1459-
result.rep().second = typename double_float_type::float_type { 0 };
1460-
}
1461-
}
1462-
else
1463-
{
1464-
result.rep().second = cpp_df_qf_detail::floor_of_constituent(x.my_second());
1465-
result.rep().second = fhi;
1466-
}
1467-
}
1468-
#else
14691429
using local_backend_type = cpp_double_fp_backend<FloatingPointType>;
14701430
using local_float_type = typename local_backend_type::float_type;
14711431

@@ -1482,7 +1442,6 @@ constexpr void eval_floor(cpp_double_fp_backend<FloatingPointType>& result, cons
14821442

14831443
local_backend_type::arithmetic::normalize(result.rep(), fhi, flo);
14841444
}
1485-
#endif
14861445
}
14871446

14881447
template <typename FloatingPointType>
@@ -1497,27 +1456,6 @@ constexpr void eval_ceil(cpp_double_fp_backend<FloatingPointType>& result, const
14971456
template <typename FloatingPointType>
14981457
constexpr int eval_fpclassify(const cpp_double_fp_backend<FloatingPointType>& o)
14991458
{
1500-
#if 0
1501-
const int fpc_a { cpp_df_qf_detail::ccmath::fpclassify(o.crep().first) };
1502-
const int fpc_b { cpp_df_qf_detail::ccmath::fpclassify(o.crep().second) };
1503-
1504-
if ((fpc_a == FP_ZERO) && ((fpc_b == FP_ZERO) || (fpc_b == FP_SUBNORMAL)))
1505-
{
1506-
return FP_ZERO;
1507-
}
1508-
else
1509-
{
1510-
if ((fpc_a == FP_NORMAL) && (fpc_b == FP_SUBNORMAL))
1511-
{
1512-
return FP_SUBNORMAL;
1513-
}
1514-
else
1515-
{
1516-
return fpc_a;
1517-
}
1518-
}
1519-
1520-
#else
15211459
using local_backend_type = cpp_double_fp_backend<FloatingPointType>;
15221460
using local_float_type = typename local_backend_type::float_type;
15231461

@@ -1528,7 +1466,6 @@ constexpr int eval_fpclassify(const cpp_double_fp_backend<FloatingPointType>& o)
15281466
: eval_is_zero(o) ? FP_ZERO
15291467
: ((fabs_x > 0) && (fabs_x < (cpp_df_qf_detail::ccmath::numeric_limits<FloatingPointType>::min)())) ? FP_SUBNORMAL
15301468
: FP_NORMAL;
1531-
#endif
15321469
}
15331470

15341471
template <typename FloatingPointType>
@@ -1560,13 +1497,15 @@ constexpr void eval_sqrt(cpp_double_fp_backend<FloatingPointType>& result, const
15601497
}
15611498
}
15621499

1563-
const local_float_type c = cpp_df_qf_detail::ccmath::sqrt(o.crep().first);
1500+
// TBD: Optimize this in a similar was as has been done for mul/div.
15641501

1565-
constexpr auto MantissaBits = cpp_df_qf_detail::ccmath::numeric_limits<local_float_type>::digits;
1566-
constexpr auto SplitBits = static_cast<int>((MantissaBits / 2) + 1);
1567-
constexpr auto Splitter = static_cast<local_float_type>((1ULL << SplitBits) + 1);
1502+
// TBD: Taking the square root of a large number (like the (max)() value)
1503+
// will overflow when multiplying by the split. Can this be handled
1504+
// more graciously?
1505+
1506+
const local_float_type c = cpp_df_qf_detail::ccmath::sqrt(o.crep().first);
15681507

1569-
local_float_type p = Splitter * c;
1508+
local_float_type p = cpp_df_qf_detail::split(local_float_type()) * c;
15701509
local_float_type hx = (c - p);
15711510
hx = hx + p;
15721511
local_float_type tx = c - hx;

0 commit comments

Comments
 (0)