interval icon indicating copy to clipboard operation
interval copied to clipboard

Cosine rounding failure on macOS

Open zfergus opened this issue 4 years ago • 2 comments

I am running into issues with the interval library when compiling with Clang. This is the simple failure case:

#include <iomanip>
#include <iostream>

#include <boost/numeric/interval.hpp>

typedef boost::numeric::interval<
    double,
    boost::numeric::interval_lib::policies<
        boost::numeric::interval_lib::save_state<
            boost::numeric::interval_lib::rounded_transc_std<double> >,
        boost::numeric::interval_lib::checking_base<double> > >
    Interval;

int main(int argc, char* argv[])
{
    Interval theta = Interval(0.79358805865013693);
    Interval output = cos(theta);
    std::cout << std::setprecision(std::numeric_limits<double>::digits10 + 1)
              << "[" << output.lower() << ", " << output.upper() << "]"
              << std::endl;
    std::cout << "is empty: "
              << (output.lower() > output.upper() ? "true" : "false")
              << std::endl;
}

The output when compiled with clang is:

[0.7012920012119436, 0.7012920012119435]
is empty: true

You can see that the last digit was rounded improperly resulting in an empty interval. If I try the same case but use rounded_transc_exact for the rounding policy It works as expected:

[0.7012920012119437, 0.7012920012119437]
is empty: false

My compiler info is

Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.3.0
Thread model: posix

and the example is compiled in debug mode. The examples works fine on GCC (specifically I tested on gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008)

Is this an expected failure for Clang?

zfergus avatar Feb 28 '20 19:02 zfergus