Boost logo

Boost :

From: Kostas Savvidis (kotika98_at_[hidden])
Date: 2020-09-09 11:03:57


Hi Damian, Laouen,

I have been able to compile the test programs with your library
after making some simple changes. The patch is below the message.

However the example program from your documentation still does not compile,
unless I comment out some lines - you can see the listing below.

I ran a tricky calculation which is from the Aberth book,
your program is able to give the answer and moreover the true value
is indeed between the upper and lower bounds that your program gives. This is good!

The conclusion is that your library can do useful work, but it is very limited in capability.
No special functions, trig is there but not working well, and no simple way to interface with linear algebra.
I may want to use it at some point, but I would need at least
the ability to cast int and double to your boost::real::real type,
because as it is now, the only way to import numbers into your software seems to be through std::string.

Finally what seem to be some bugs:

1) unsigned int real::maximum_precision = 10;
// error: specializing member 'boost::real::real<int>::maximum_precision' requires 'template<>' syntax

2) auto it = e.cbegin();
// error: 'using real = class boost::real::real<int>' {aka 'class boost::real::real<int>'} has no member named 'cbegin'

3) real::sin(f) // enters infinite loop

4) real c = (std::string)"0.999999";
 prints:
c: [0.99999899999999999999999999999999999999999999999999999999999999999999999999999999999999999933600778729, 0.99999899999999999999999999999999999999999999999999999999999999999999999999999999999999999982691714296]

as far as i can see the interval is incorrect !

Best Regards,
Kostas

=============================================================================================

diff -r -u real.orig/integer_number.hpp real/integer_number.hpp
--- real.orig/integer_number.hpp 2020-09-07 16:22:04.000000000 +0300
+++ real/integer_number.hpp 2020-09-08 14:11:22.000000000 +0300
@@ -103,7 +103,8 @@
                                 }
                                 // this function always expects (*this) to bigger than other, so if borrow is not zero at the end
                                 // there should be error
- if(borrow != 0);
+ if(borrow != 0)
+ ;
                                         //throw subtraction_number_required_lower_exception();
 
diff -r -u real.orig/real_rational.hpp real/real_rational.hpp
--- real.orig/real_rational.hpp 2020-09-07 16:22:04.000000000 +0300
+++ real/real_rational.hpp 2020-09-08 11:59:51.000000000 +0300
@@ -262,7 +262,7 @@
                         // constructor to generate get number from string
                         constexpr explicit real_rational(std::string_view num){
                                 // searching for "/" in string
- size_t pos;
+ size_t pos=0;
                                 bool found = false;
                                 std::string_view num1, num2;
                                 pos = num.size();
=============================================================================================

#include <iostream>
#include <string>
#include <real/real.hpp>

using real = boost::real::real<int>;

//unsigned int real::maximum_precision = 10;
//unsigned int real_algorithm::maximum_precision = 10;

int main() {
    real c = (std::string)"0.999999";
    real d = (std::string)"0.999999";
    real e = c + d;
    std::cout << "c: " << c << std::endl;
    std::cout << "d: " << d << std::endl;
    std::cout << "e=c+d: " << e << std::endl; // ANSWER IS WRONG ??!!!
    
    // for(auto it = e.cbegin(); it != e.cend(); ++it) {
    // std::cout << "e iteration " << it.approximation_interval << std::endl;
    // }
    
    real g = (std::string)"0.999998";
    std::cout << "g: " << g << std::endl;
    if (g < d) {
        std::cout << "g < d --> true" << std::endl;
    } else {
        std::cout << "g < d --> false" << std::endl;
    }
    real h = d - g;
    std::cout << "h=d-g: " << h << std::endl;
    std::cout << "h++ is: " << h+real("1.0") << std::endl;
    
{ // Example from Aberth 1992, Precise Computation Using Range Arithmetic
    real a("77617.0");
    real b("33096.0");
    std::cout << "\n\n" << "a: " << a << std::endl;
    std::cout << "b: " << b << std::endl;
    real f = real("333.75")*b*b*b*b*b*b + a*a*(real("11.0")*a*a*b*b-b*b*b*b*b*b - real("121.0")*b*b*b*b-real("2.0")) + real("5.5")*b*b*b*b*b*b*b*b + a/(real("2.0")*b);
    // should be -0.827396
    std::cout << "f: " << f << std::endl;
    //std::cout << "sin(f): " << real::sin(f) << std::endl; // doesn't come out of the loop
}
    return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk