Skip to content

Commit ebb4ebb

Browse files
committed
Merge branch 'cpp_double_fp_backend' into develop
2 parents 77bb3da + a3d7e63 commit ebb4ebb

File tree

80 files changed

+613
-311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+613
-311
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
- BOOST_LIBRARY=multiprecision
77
- CXX_STANDARD=gnu++11
88
docker:
9-
- image: gcc:7
9+
- image: cimg/base:current
1010
steps:
1111
- checkout
1212
- run:
@@ -24,8 +24,8 @@ jobs:
2424
- run:
2525
name: install pre dependencies
2626
command: |
27-
apt-get update -yqq
28-
apt-get install git xsltproc docbook-xsl docbook-xml -y
27+
sudo apt-get update -yqq
28+
sudo apt-get install git xsltproc docbook-xsl docbook-xml -y
2929
- run:
3030
name: Initializing git repo for boost
3131
command: |
@@ -46,11 +46,11 @@ jobs:
4646
- run:
4747
name: Building inspect
4848
command: |
49-
cd $BOOST/boost/tools/inspect/build && ../../../b2 -j2 address-model=64 architecture=x86 toolset=gcc cxxflags="-std=gnu++14" release dist-bin
49+
cd $BOOST/boost/tools/inspect && ../../b2 toolset=gcc variant=release dist-bin
5050
- run:
5151
name: Building docs
5252
command: |
53-
cd $BOOST_REMOVE/doc && rm -rf html/boost_multiprecision && ../../../b2 -j2 address-model=64 architecture=x86 toolset=gcc cxxflags="-std=gnu++14" release
53+
cd $BOOST_REMOVE/doc && rm -rf html/boost_multiprecision && ../../../b2
5454
- run:
5555
name: Running Inspect
5656
command: |

build.jam

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright René Ferdinand Rivera Morell 2023-2024
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# (See accompanying file LICENSE_1_0.txt or copy at
4+
# http://www.boost.org/LICENSE_1_0.txt)
5+
6+
require-b2 5.2 ;
7+
8+
constant boost_dependencies :
9+
/boost/assert//boost_assert
10+
/boost/config//boost_config
11+
/boost/core//boost_core
12+
/boost/integer//boost_integer
13+
/boost/lexical_cast//boost_lexical_cast
14+
/boost/math//boost_math
15+
/boost/predef//boost_predef
16+
/boost/random//boost_random
17+
/boost/throw_exception//boost_throw_exception ;
18+
19+
project /boost/multiprecision
20+
: common-requirements
21+
<include>include
22+
;
23+
24+
explicit
25+
[ alias boost_multiprecision : : : : <library>$(boost_dependencies) ]
26+
[ alias all : boost_multiprecision test example performance ]
27+
;
28+
29+
call-if : boost-library multiprecision
30+
;
31+
32+
use-project /boost/multiprecision/config : config ;
33+

config/Jamfile.v2

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
# copyright John Maddock 2008
2-
# Distributed under the Boost Software License, Version 1.0.
3-
# (See accompanying file LICENSE_1_0.txt or copy at
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# (See accompanying file LICENSE_1_0.txt or copy at
44
# http://www.boost.org/LICENSE_1_0.txt.
55

6+
import-search /boost/config/checks ;
7+
68
import modules ;
79
import path ;
8-
import ../../config/checks/config : requires ;
10+
import config : requires ;
911

1012
local gmp_path = [ modules.peek : GMP_PATH ] ;
1113
local mpfr_path = [ modules.peek : MPFR_PATH ] ;
1214
local mpfi_path = [ modules.peek : MPFI_PATH ] ;
1315
local tommath_path = [ modules.peek : TOMMATH_PATH ] ;
1416

15-
project : requirements
16-
<include>$(gmp_path)
17-
<include>$(gmp_path)/mpfr
18-
<include>$(gmp_path)/gmpfrxx
17+
project : requirements
18+
<include>$(gmp_path)
19+
<include>$(gmp_path)/mpfr
20+
<include>$(gmp_path)/gmpfrxx
1921
<include>$(mpfr_path)
2022
<include>$(mpfi_path)
2123
<include>$(mpfi_path)/src
2224
<include>$(tommath_path)
23-
<include>../../..
24-
<search>$(gmp_path)
25-
<search>$(mpfr_path)
25+
<search>$(gmp_path)
26+
<search>$(mpfr_path)
2627
<search>$(mpfr_path)/build.vc10/lib/Win32/Debug
27-
<search>$(tommath_path)
28-
<search>$(mpfi_path)
29-
<search>$(mpfi_path)/src
28+
<search>$(tommath_path)
29+
<search>$(mpfi_path)
30+
<search>$(mpfi_path)/src
3031
# We set these to make it easier to set up and test GMP and MPFR under Win32:
3132
<toolset>msvc:<runtime-link>static
3233
<toolset>msvc:<link>static

doc/Jamfile.v2

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ boostbook standalone
1717
:
1818
# Path for links to Boost:
1919
<xsl:param>boost.root=../../../..
20-
20+
2121
# Some general style settings:
2222
<xsl:param>table.footnote.number.format=1
2323
<xsl:param>footnote.number.format=1
@@ -42,8 +42,8 @@ boostbook standalone
4242
# extending 'standard' BOOST_ROOT/doc/src/boostbook.css with
4343
# @import url('../../../../doc/src/boostbook.css');
4444
# in location multiprecision/doc/html/multiprecision.css
45-
46-
45+
46+
4747
# PDF Options:
4848
# TOC Generation: this is needed for FOP-0.9 and later:
4949
<xsl:param>fop1.extensions=0
@@ -65,7 +65,7 @@ boostbook standalone
6565
# default PNG graphics are awful in PDF form,
6666
# better use SVGs instead:
6767
<format>pdf:<xsl:param>admon.graphics.extension=".svg"
68-
<format>pdf:<xsl:param>use.role.for.mediaobject=1
68+
<format>pdf:<xsl:param>use.role.for.mediaobject=1
6969
<format>pdf:<xsl:param>preferred.mediaobject.role=print
7070
<format>pdf:<xsl:param>img.src.path=$(images_location)/
7171
<format>pdf:<xsl:param>draft.mode="no"
@@ -76,19 +76,19 @@ boostbook standalone
7676
# .SVG files are roughly twice the .png size and so a bit gross.
7777
# This also changes the admonitions icons.
7878
# <format>html:<xsl:param>admon.graphics.extension=".svg"
79-
<format>html:<xsl:param>use.role.for.mediaobject=1
79+
<format>html:<xsl:param>use.role.for.mediaobject=1
8080
<format>html:<xsl:param>preferred.mediaobject.role=print
8181
# <format>html:<xsl:param>img.src.path=$(images_location)/ isn't right for html.
8282
<format>html:<xsl:param>draft.mode="no"
8383
<format>html:<xsl:param>boost.url.prefix=http\://www.boost.org/doc/libs/release/libs/multiprecision/doc/html
84-
84+
8585
# Index generation:
8686
<auto-index>on
8787
<auto-index-script>$(here)/index.idx
88-
<auto-index-prefix>$(here)/../../..
88+
<auto-index-prefix>$(here)/../include
8989
<auto-index-verbose>on
9090
<format>html:<auto-index-internal>on
91-
<quickbook-define>enable_index
91+
<quickbook-define>enable_index
9292
<format>pdf:<xsl:param>index.on.type=1
9393
;
9494

doc/multiprecision.qbk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
[template mpf_class[] [@http://gmplib.org/manual/C_002b_002b-Interface-Floats.html#C_002b_002b-Interface-Floats mpf_class]]
6161
[template mpfr_class[] [@http://math.berkeley.edu/~wilken/code/gmpfrxx/ mpfr_class]]
6262
[template mpreal[] [@http://www.holoborodko.com/pavel/mpfr/ mpreal]]
63-
[template mpir[] [@http://mpir.org/ MPIR]]
63+
[template mpir[] [@https://github.com/wbhart/mpir/ MPIR]]
6464
[template tommath[] [@http://libtom.net libtommath]]
6565
[template quadmath[] [@http://gcc.gnu.org/onlinedocs/libquadmath/ libquadmath]]
6666

example/Jamfile.v2

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import testing ;
1212
import modules ;
1313
import path ;
14-
import ../../config/checks/config : requires ;
14+
import-search /boost/config/checks ;
15+
import config : requires ;
1516

1617
local ntl-path = [ modules.peek : NTL_PATH ] ;
1718
local gmp_path = [ modules.peek : GMP_PATH ] ;
@@ -21,16 +22,16 @@ local tommath_path = [ modules.peek : TOMMATH_PATH ] ;
2122

2223
project
2324
: requirements
25+
<library>/boost/multiprecision//boost_multiprecision
26+
2427
<include>$(gmp_path)
2528
<include>$(gmp_path)/mpfr
2629
<include>$(gmp_path)/gmpfrxx
2730
<include>$(mpfr_path)
2831
<include>$(mpfi_path)
2932
<include>$(mpfi_path)/src
3033
<include>$(tommath_path)
31-
<include>../include
32-
<include>../../..
33-
34+
3435
<toolset>gcc:<cxxflags>-Wno-missing-braces
3536
<toolset>darwin:<cxxflags>-Wno-missing-braces
3637
<toolset>acc:<cxxflags>+W2068,2461,2236,4070
@@ -51,7 +52,7 @@ project
5152
<toolset>msvc:<cxxflags>/wd4701
5253
<toolset>msvc:<cxxflags>/wd4305
5354
<toolset>clang:<link>static
54-
[ requires
55+
[ requires
5556
cxx11_rvalue_references cxx11_template_aliases cxx11_hdr_array cxx11_allocator cxx11_constexpr cxx11_explicit_conversion_operators cxx11_ref_qualifiers
5657
cxx11_hdr_functional cxx11_variadic_templates cxx11_user_defined_literals cxx11_decltype cxx11_static_assert cxx11_defaulted_functions
5758
cxx11_noexcept cxx11_ref_qualifiers cxx11_user_defined_literals cxx11_hdr_type_traits
@@ -95,7 +96,7 @@ test-suite examples :
9596
[ run integer_examples.cpp no_eh_eg_support ]
9697
[ run logged_adaptor.cpp no_eh_eg_support mpfi mpfr gmp : : : [ check-target-builds ../config//has_mpfi : : <build>no ] ]
9798
[ run mixed_integer_arithmetic.cpp no_eh_eg_support ]
98-
[ run numeric_limits_snips.cpp no_eh_eg_support /boost//test_exec_monitor : : : [ requires cxx11_numeric_limits ] [ check-target-builds ../config//has_float128 : <source>quadmath ] ]
99+
[ run numeric_limits_snips.cpp no_eh_eg_support /boost/test//boost_test_exec_monitor : : : [ requires cxx11_numeric_limits ] [ check-target-builds ../config//has_float128 : <source>quadmath ] ]
99100
[ run random_snips.cpp gmp no_eh_eg_support : : : [ requires cxx11_explicit_conversion_operators ] [ check-target-builds ../config//has_gmp : : <build>no ] ]
100101
[ run safe_prime.cpp no_eh_eg_support ]
101102

@@ -104,7 +105,7 @@ test-suite examples :
104105
[ run mpfr_snips.cpp mpfr gmp no_eh_eg_support : : : [ check-target-builds ../config//has_mpfr : : <build>no ] ]
105106
[ run tommath_snips.cpp $(TOMMATH) no_eh_eg_support : : : [ check-target-builds ../config//has_tommath : : <build>no ] ]
106107
[ compile constexpr_float_arithmetic_examples.cpp : [ requires cxx14_constexpr cxx17_if_constexpr ] ]
107-
108+
108109
[ run big_seventh.cpp no_eh_eg_support ]
109110

110111
[ run exercise_threading_log_agm.cpp : : : <define>BOOST_MULTIPRECISION_EXERCISE_THREADING_BACKEND_TYPE=101 release [ requires cxx11_hdr_atomic cxx11_hdr_thread ] : exercise_threading_log_agm_cpp_dec_float ]

include/boost/multiprecision/cpp_bin_float.hpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
////////////////////////////////////////////////////////////////
2-
// Copyright 2013 - 2022 John Maddock.
3-
// Copyright 2022 Christopher Kormanyos.
2+
// Copyright 2013 - 2025 John Maddock.
3+
// Copyright 2022 - 2025 Christopher Kormanyos.
44
// Distributed under the Boost Software License,
55
// Version 1.0. (See accompanying file LICENSE_1_0.txt
66
// or copy at https://www.boost.org/LICENSE_1_0.txt)
@@ -1626,15 +1626,34 @@ inline void convert_to_unsigned_int(I* res, const cpp_bin_float<Digits, DigitBas
16261626
}
16271627
typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::rep_type man(arg.bits());
16281628
using shift_type = typename std::conditional<sizeof(typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type) < sizeof(int), int, typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type>::type;
1629-
shift_type shift = (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1 - arg.exponent();
1630-
if (shift > (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1)
1629+
1630+
const shift_type shift = (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1 - arg.exponent();
1631+
1632+
if (arg.sign())
1633+
{
1634+
using si_type = typename boost::multiprecision::detail::make_signed<I>::type;
1635+
1636+
si_type val;
1637+
1638+
convert_to_signed_int(&val, arg);
1639+
1640+
*res = static_cast<I>(val);
1641+
1642+
return;
1643+
}
1644+
else if (shift > (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1)
16311645
{
16321646
*res = 0;
16331647
return;
16341648
}
1649+
else if (arg.compare(max_val) >= 0)
1650+
{
1651+
*res = max_val;
1652+
return;
1653+
}
16351654
else if (shift < 0)
16361655
{
1637-
if (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - shift <= digits)
1656+
if ((shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - shift <= (shift_type)digits)
16381657
{
16391658
// We have more bits in ulong_long_type than the float, so it's OK to left shift:
16401659
eval_convert_to(res, man);
@@ -1644,7 +1663,7 @@ inline void convert_to_unsigned_int(I* res, const cpp_bin_float<Digits, DigitBas
16441663
*res = max_val;
16451664
return;
16461665
}
1647-
eval_right_shift(man, shift);
1666+
eval_right_shift(man, static_cast<unsigned>(shift));
16481667
eval_convert_to(res, man);
16491668
}
16501669

@@ -2035,18 +2054,18 @@ inline void eval_ceil(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE
20352054
}
20362055
bool fractional = (shift_type)eval_lsb(arg.bits()) < shift;
20372056
res = arg;
2038-
eval_right_shift(res.bits(), shift);
2057+
eval_right_shift(res.bits(), static_cast<unsigned>(shift));
20392058
if (fractional && !res.sign())
20402059
{
20412060
eval_increment(res.bits());
2042-
if ((std::ptrdiff_t)eval_msb(res.bits()) != cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1 - shift)
2061+
if ((std::ptrdiff_t)eval_msb(res.bits()) != (std::ptrdiff_t)(static_cast<shift_type>(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count) - 1 - shift))
20432062
{
20442063
// Must have extended result by one bit in the increment:
20452064
--shift;
20462065
++res.exponent();
20472066
}
20482067
}
2049-
eval_left_shift(res.bits(), shift);
2068+
eval_left_shift(res.bits(), static_cast<unsigned>(shift));
20502069
}
20512070

20522071
template <unsigned D1, backends::digit_base_type B1, class A1, class E1, E1 M1, E1 M2>

include/boost/multiprecision/cpp_dec_float.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ long long cpp_dec_float<Digits10, ExponentType, Allocator>::extract_signed_long_
17131713
// See https://svn.boost.org/trac/boost/ticket/9740.
17141714
//
17151715
long long sval = static_cast<long long>(val - 1);
1716-
sval = -sval;
1716+
sval = -sval;
17171717
--sval;
17181718
return sval;
17191719
}
@@ -1749,14 +1749,14 @@ unsigned long long cpp_dec_float<Digits10, ExponentType, Allocator>::extract_uns
17491749
else
17501750
{
17511751
// Extract the data into an unsigned long long value.
1752-
val = static_cast<unsigned long long>(xn.data[0]);
1752+
val = static_cast<unsigned long long>(xn.data[std::size_t { 0U }]);
17531753

17541754
const std::int32_t imax = (std::min)(static_cast<std::int32_t>(static_cast<std::int32_t>(xn.exp) / cpp_dec_float_elem_digits10), static_cast<std::int32_t>(cpp_dec_float_elem_number - static_cast<std::int32_t>(1)));
17551755

17561756
for (std::int32_t i = static_cast<std::int32_t>(1); i <= imax; i++)
17571757
{
17581758
val *= static_cast<unsigned long long>(cpp_dec_float_elem_mask);
1759-
val += static_cast<unsigned long long>(xn.data[i]);
1759+
val += static_cast<unsigned long long>(xn.data[static_cast<std::size_t>(i)]);
17601760
}
17611761
}
17621762

include/boost/multiprecision/cpp_int/bitwise.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_trivial
700700
eval_left_shift(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, T s) noexcept((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
701701
{
702702
is_valid_bitwise_op(result, typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
703-
*result.limbs() = detail::checked_left_shift(*result.limbs(), s, typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
703+
*result.limbs() = detail::checked_left_shift(*result.limbs(), static_cast<unsigned long long>(s), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
704704
result.normalize();
705705
}
706706

@@ -710,7 +710,7 @@ eval_right_shift(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Alloca
710710
{
711711
// Nothing to check here... just make sure we don't invoke undefined behavior:
712712
is_valid_bitwise_op(result, typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
713-
*result.limbs() = (static_cast<unsigned>(s) >= sizeof(*result.limbs()) * CHAR_BIT) ? 0 : (result.sign() ? ((--*result.limbs()) >> s) + 1 : *result.limbs() >> s);
713+
*result.limbs() = (static_cast<std::size_t>(s) >= static_cast<std::size_t>(sizeof(*result.limbs()) * CHAR_BIT)) ? 0 : (result.sign() ? ((--*result.limbs()) >> s) + 1 : *result.limbs() >> s);
714714
if (result.sign() && (*result.limbs() == 0))
715715
result = static_cast<signed_limb_type>(-1);
716716
}

0 commit comments

Comments
 (0)