From 0f63a2b6dec4ff3dc4c251e655e1e886a092af98 Mon Sep 17 00:00:00 2001 From: G Yuvan Shankar Date: Sat, 25 Dec 2021 19:32:08 +0530 Subject: [PATCH 1/3] Changed initial guess of Newtons Square Root Method --- include/real/real_math.hpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/real/real_math.hpp b/include/real/real_math.hpp index 15012a7..0811fc1 100755 --- a/include/real/real_math.hpp +++ b/include/real/real_math.hpp @@ -201,8 +201,17 @@ namespace boost{ return literals::zero_exact; } - // initial guess - exact_number result(x.digits, (x.exponent + 1)/2, true); + // initial guess using scalar estimate + exact_number result; + if(x.exponent%2==0) + { + if(x.digits[0]>=1) + result=exact_number (std::vector {6}, (x.exponent)/2, true); + else + result=exact_number (std::vector {2}, (x.exponent)/2, true); + } + else + result=exact_number(std::vector {2}, (x.exponent-1)/2, true); exact_number error; exact_number max_error(std::vector {1}, -max_error_exponent, true); From 2e0d4b4a13a5c970dbc3876ec575ff07c0a50920 Mon Sep 17 00:00:00 2001 From: G Yuvan Shankar Date: Fri, 7 Jan 2022 13:42:12 +0530 Subject: [PATCH 2/3] Removed loop and replaced with simple multiplication --- include/real/real_math.hpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/include/real/real_math.hpp b/include/real/real_math.hpp index 0811fc1..314a6c2 100755 --- a/include/real/real_math.hpp +++ b/include/real/real_math.hpp @@ -201,17 +201,8 @@ namespace boost{ return literals::zero_exact; } - // initial guess using scalar estimate - exact_number result; - if(x.exponent%2==0) - { - if(x.digits[0]>=1) - result=exact_number (std::vector {6}, (x.exponent)/2, true); - else - result=exact_number (std::vector {2}, (x.exponent)/2, true); - } - else - result=exact_number(std::vector {2}, (x.exponent-1)/2, true); + // initial guess + exact_number result(x.digits, (x.exponent + 1)/2, true); exact_number error; exact_number max_error(std::vector {1}, -max_error_exponent, true); @@ -369,9 +360,7 @@ namespace boost{ else result -= cur_term; - for(exact_number i = (two * term_number) + literals::one_exact ; i <= two * (term_number + literals::one_exact); i = i + literals::one_exact){ - factorial *= i; - } + factorial *=((two * term_number) + literals::one_exact)*(two * (term_number + literals::one_exact)); cur_power *= square_x; cur_term = cur_power; ++ term_number_int; From 749a9c2299b775777a5caf6143d6b3070b277b38 Mon Sep 17 00:00:00 2001 From: G Yuvan Shankar Date: Tue, 11 Jan 2022 13:42:27 +0530 Subject: [PATCH 3/3] Minor changes to CML --- CMakeLists.txt | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e22a2fd..643d2d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,29 +1,25 @@ cmake_minimum_required(VERSION 3.8) -project(Boost.Real) -set (Boost.Real_VERSION_MAJOR 1) -set (Boost.Real_VERSION_MINOR 0) +set(_version 1.0) +project(Boost.Real VERSION ${_version} LANGUAGES CXX) #Add coverage support to CMAKE in debug mode -IF(CMAKE_BUILD_TYPE MATCHES Debug) +if(CMAKE_BUILD_TYPE MATCHES Debug) message("debug mode adding coverage report tools and flags") list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules") include(CodeCoverage) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG} -Wall -g -O0 -fsanitize=address -fno-omit-frame-pointer -fprofile-arcs -ftest-coverage") -ENDIF(CMAKE_BUILD_TYPE MATCHES Debug) +endif(CMAKE_BUILD_TYPE MATCHES Debug) +# add Boost.Real as a 'linkable' target +add_library(Boost.Real PUBLIC) # Check for standard to use include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-std=c++17 HAVE_FLAG_STD_CXX17) -if(HAVE_FLAG_STD_CXX17) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic --std=c++17") -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic --std=c++1z") -endif() +target_compile_features(Boost.Real PUBLIC cxx_std_17) + +include_directories(include external/include) -include_directories(include external/include ${Boost_INCLUDE_DIRS}) -# add Boost.Real as a 'linkable' target -add_library(Boost.Real INTERFACE) #Library Headers add_executable(Boost.Real_headers include)