Giter Club home page Giter Club logo

interval's Introduction

Interval, part of the collection of Boost C++ Libraries, is intended to help manipulating mathematical intervals.

License

Distributed under the Boost Software License, Version 1.0.

Properties

  • C++03
  • Header-only

Build Status

Branch GHA CI Appveyor Coverity Scan codecov.io Deps Docs Tests
master Build Status Build status Coverity Scan Build Status codecov Deps Documentation Enter the Matrix
develop Build Status Build status Coverity Scan Build Status codecov Deps Documentation Enter the Matrix

Directories

Name Purpose
doc documentation
examples use case examples
include headers
test unit tests

More inintervalion

  • Ask questions: Be sure to read the documentation first as Boost.Interval has specific requirements.
  • Report bugs: Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well.
  • Submit Pull Requests against the develop branch. Note that by submitting patches you agree to license your modifications under the Boost Software License, Version 1.0. Be sure to include tests proving your changes work properly.
  • Discussions about the library are held on the Boost developers mailing list. Be sure to read the discussion policy before posting and add the [interval] tag at the beginning of the subject line.

interval's People

Contributors

akumta avatar belcourt avatar beman avatar danieljames avatar douggregor avatar eldiener avatar fkonvick avatar glenfe avatar gongminmin avatar grafikrobot avatar hervebronnimann avatar imikejackson avatar jeking3 avatar jensmaurer avatar jhunold avatar jzmaddock avatar kojoley avatar mclow avatar pdimov avatar romain-geissler-1a avatar silene avatar steveire avatar straszheim avatar svigerske avatar swatanabe avatar sylvainpion avatar teemperor avatar thwitt avatar viboes avatar vprus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

interval's Issues

interval::hull occludes non-member hull() functions

There are functions hull(a, b) and also a static member function interval::hull(T, T). I am using the interval class as a base class. Within my type that is derived from interval<T>, I find that it is complicated to invoke the non-member versions of the hull() function, because the compiler becomes obsessively glued to the static member function interval::hull(T, T). It effectively occludes the others. Conversely, the static member function serves no purpose, because it performs exactly the same operation as its non-static counterpart. It would be convenient to have this static member function removed.

Modular Boost C++ Libraries Request

We are in the process of making B2 build changes to all of the B2 build files
to support "modular" consumption of the Boost Libraries by users. See this list
post for some details: https://lists.boost.org/Archives/boost/2024/01/255704.php

The process requires making a variety of changes to make each Boost library
independent of the super-project structure. But the changes do not remove the
super-project structure or the comprehensive Boost release. The changes make
solely make it possible, optionally, for users, like package manages, to easily
consume libraries individually.

Generally the changes include:

  • Adding a libroot/build.jam.
  • Porting any functionality from libroot/jamfile to libroot/build.jam.
  • Moving boost-install declaration from libroot/build/jamfile is applicable.
  • Adjusting other B2 build files in the library, like test/jamfile, as needed.
  • Possible changes to C++ source files to remove includes relative to the
    super-project boostroot location.

Some examples of such changes:

We are asking how you would like us to handle the changes. We would prefer if
you allow the owners of the Boost.org GitHub project to make changes to B2
build files, as needed, to accomplish the changes. But understand
that you may want to manage the proposed changes yourself.

We previously sent emails to all known maintainers to fill out a form with their
preference. We are contacting you in this issue as we have not gotten a response
to that email. You can see the ongoing responses for that form and the responses
to these issues here https://github.com/users/grafikrobot/projects/1/views/6

We are now asking if you can reply directly to this issue to indicate your
preference of handling the changes. Please supply a response to this question
and close the issue (so that we can verify you are a maintainer).

How would you like the build changes to be processed?

  1. Pull request, reviewed and merged by a BOOSTORG OWNER.
  2. Pull request, reviewed and merged by YOU.
  3. Other. (please specify details in the reply)

Also please indicate any special instructions you want us to consider. Or other
information you want us to be aware of.

Thanks you, René

Ill-formed narrowing conversions for ppc

/usr/include/boost/numeric/interval/detail/ppc_rounding_control.hpp:31:56: error: narrowing conversion of '18444492273895866370' from 'long long unsigned int' to 'boost::long_long_type' {aka 'long long int'} [-Wnarrowing]
   31 | static const rounding_mode_struct mode_upward      = { 0xFFF8000000000002LL };
      |                                                        ^~~~~~~~~~~~~~~~~~~~
/usr/include/boost/numeric/interval/detail/ppc_rounding_control.hpp:32:56: error: narrowing conversion of '18444492273895866371' from 'long long unsigned int' to 'boost::long_long_type' {aka 'long long int'} [-Wnarrowing]
   32 | static const rounding_mode_struct mode_downward    = { 0xFFF8000000000003LL };
      |                                                        ^~~~~~~~~~~~~~~~~~~~
/usr/include/boost/numeric/interval/detail/ppc_rounding_control.hpp:33:56: error: narrowing conversion of '18444492273895866368' from 'long long unsigned int' to 'boost::long_long_type' {aka 'long long int'} [-Wnarrowing]
   33 | static const rounding_mode_struct mode_to_nearest  = { 0xFFF8000000000000LL };
      |                                                        ^~~~~~~~~~~~~~~~~~~~
/usr/include/boost/numeric/interval/detail/ppc_rounding_control.hpp:34:56: error: narrowing conversion of '18444492273895866369' from 'long long unsigned int' to 'boost::long_long_type' {aka 'long long int'} [-Wnarrowing]
   34 | static const rounding_mode_struct mode_toward_zero = { 0xFFF8000000000001LL };
      |                                                        ^~~~~~~~~~~~~~~~~~~~

These constants are too large for long long so they have type unsigned long long (despite the LL suffix). Converting them to long long inside a braced-init-list is a narrowing conversion.

Interval cosine function broken

Code to reproduce:

#include <boost/numeric/interval.hpp>

using boost::numeric::interval;
using namespace boost::numeric::interval_lib;

int main()
{
    auto x = cos(interval<double>(2.3));
    return 0;
}

Error message:

g++-7 -Wall -Wextra -Wfatal-errors -fext-numeric-literals main.cpp -o main.x -pthread
main.cpp: In function 'int main()':
main.cpp:8:10: warning: variable 'x' set but not used [-Wunused-but-set-variable]
     auto x = cos(interval<double>(2.3));
          ^
In file included from ../numeric/interval/include/boost/numeric/interval.hpp:30:0,
                 from main.cpp:1:
../numeric/interval/include/boost/numeric/interval/transc.hpp: In instantiation of 'boost::numeric::interval<T, Policies> boost::numeric::cos(const boost::numeric::interval<T, Policies>&) [with T = double; Policies = boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>, boost::numeric::interval_lib::checking_strict<double> >]':
main.cpp:8:39:   required from here
../numeric/interval/include/boost/numeric/interval/transc.hpp:73:18: error: 'boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>, boost::numeric::interval_lib::checking_strict<double> >::rounding {aka struct boost::numeric::interval_lib::rounded_math<double>}' has no member named 'cos_down'; did you mean 'conv_down'?
     return I(rnd.cos_down(u), rnd.cos_up(l), true);
              ~~~~^~~~~~~~
              conv_down
compilation terminated due to -Wfatal-errors.
make: *** [main.x] Error 1

Compiled against a fresh clone.

Cosine rounding failure on macOS

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?

MSVC 10.0 fails test_float

It looks like msvc-10.0 does not support /fp:strict which is needed to pass tests.
From upcoming CI submission, seeing the following:

testing.capture-output bin.v2\libs\numeric\interval\test\test_float.test\msvc-10.0\release\threading-multi\test_float.run
====== BEGIN OUTPUT ======
Running 1 test case...
C:/projects/boost-root/libs/numeric/interval/test/test_float.cpp(29): fatal error: in "test_main_caller( argc, argv )": critical check in(rT2, rI) has failed
*** 1 failure is detected in the test module "Test Program"
 
EXIT STATUS: 201 
====== END OUTPUT ======
    
    set status=0
    if %status% NEQ 0 (
        echo Skipping test execution due to testing.execute=off
        exit 0
    )
     "bin.v2\libs\numeric\interval\test\test_float.test\msvc-10.0\release\threading-multi\test_float.exe"   > "bin.v2\libs\numeric\interval\test\test_float.test\msvc-10.0\release\threading-multi\test_float.output" 2>&1 
    set status=%ERRORLEVEL%
    echo. >> "bin.v2\libs\numeric\interval\test\test_float.test\msvc-10.0\release\threading-multi\test_float.output"
    echo EXIT STATUS: %status% >> "bin.v2\libs\numeric\interval\test\test_float.test\msvc-10.0\release\threading-multi\test_float.output"
    if %status% EQU 0 (
        copy "bin.v2\libs\numeric\interval\test\test_float.test\msvc-10.0\release\threading-multi\test_float.output" "bin.v2\libs\numeric\interval\test\test_float.test\msvc-10.0\release\threading-multi\test_float.run"
    )
    set verbose=0
    if %status% NEQ 0 (
        set verbose=1
    )
    if %verbose% EQU 1 (
        echo ====== BEGIN OUTPUT ======
        type "bin.v2\libs\numeric\interval\test\test_float.test\msvc-10.0\release\threading-multi\test_float.output"
        echo ====== END OUTPUT ======
    )
    exit %status%
...failed testing.capture-output bin.v2\libs\numeric\interval\test\test_float.test\msvc-10.0\release\threading-multi\test_float.run...

As such I am going to document it and disable that test on MSVC 10.0 only.

Changes in Boost.Logic (tribool) have broken compare/tribool

gcc.compile.c++ ../../../../bin.v2/libs/numeric/interval/test/cmp_tribool.test/gcc-7.3/debug/cxxstd-11-iso/visibility-hidden/libs/numeric/interval/test/cmp_tribool.o
In file included from ../../../../boost/test/tools/old/impl.hpp:20:0,
                 from ../../../../boost/test/test_tools.hpp:46,
                 from /boost/libs/numeric/interval/test/cmp_header.hpp:14,
                 from /boost/libs/numeric/interval/test/cmp_tribool.cpp:11:
../../../../boost/test/tools/assertion_result.hpp: In instantiation of 'boost::test_tools::assertion_result::assertion_result(const BoolConvertable&) [with BoolConvertable = boost::logic::tribool]':
/boost/libs/numeric/interval/test/cmp_tribool.cpp:21:3:   required from here
../../../../boost/test/tools/assertion_result.hpp:57:79: error: no matching function for call to 'boost::test_tools::assertion_result::readonly_property65::readonly_property65(boost::logic::tribool)'
     assertion_result( BoolConvertable const& pv_ ) : p_predicate_value( !!pv_ ) {}
                                                                               ^
In file included from ../../../../boost/config/detail/suffix.hpp:543:0,
                 from ../../../../boost/config.hpp:61,
                 from ../../../../boost/limits.hpp:14,
                 from ../../../../boost/numeric/interval/checking.hpp:16,
                 from /boost/libs/numeric/interval/test/cmp_header.hpp:11,
                 from /boost/libs/numeric/interval/test/cmp_tribool.cpp:11:
../../../../boost/test/utils/class_properties.hpp:155:29: note: candidate: boost::test_tools::assertion_result::readonly_property65::readonly_property65(write_param_t)
     explicit    BOOST_JOIN( readonly_property, __LINE__ )( write_param_t init_v  )  \
                             ^
../../../../boost/test/tools/assertion_result.hpp:65:5: note: in expansion of macro 'BOOST_READONLY_PROPERTY'
     BOOST_READONLY_PROPERTY( bool, (assertion_result) ) p_predicate_value;
     ^~~~~~~~~~~~~~~~~~~~~~~
../../../../boost/test/utils/class_properties.hpp:155:29: note:   no known conversion for argument 1 from 'boost::logic::tribool' to 'write_param_t {aka bool}'
     explicit    BOOST_JOIN( readonly_property, __LINE__ )( write_param_t init_v  )  \
                             ^
../../../../boost/test/tools/assertion_result.hpp:65:5: note: in expansion of macro 'BOOST_READONLY_PROPERTY'
     BOOST_READONLY_PROPERTY( bool, (assertion_result) ) p_predicate_value;
     ^~~~~~~~~~~~~~~~~~~~~~~
../../../../boost/test/utils/class_properties.hpp:154:29: note: candidate: boost::test_tools::assertion_result::readonly_property65::readonly_property65()
                 BOOST_JOIN( readonly_property, __LINE__ )() {}                      \
                             ^
../../../../boost/test/tools/assertion_result.hpp:65:5: note: in expansion of macro 'BOOST_READONLY_PROPERTY'
     BOOST_READONLY_PROPERTY( bool, (assertion_result) ) p_predicate_value;
     ^~~~~~~~~~~~~~~~~~~~~~~
../../../../boost/test/utils/class_properties.hpp:154:29: note:   candidate expects 0 arguments, 1 provided
                 BOOST_JOIN( readonly_property, __LINE__ )() {}                      \
                             ^
../../../../boost/test/tools/assertion_result.hpp:65:5: note: in expansion of macro 'BOOST_READONLY_PROPERTY'
     BOOST_READONLY_PROPERTY( bool, (assertion_result) ) p_predicate_value;
     ^~~~~~~~~~~~~~~~~~~~~~~
../../../../boost/test/utils/class_properties.hpp:148:19: note: candidate: constexpr boost::test_tools::assertion_result::readonly_property65::readonly_property65(const boost::test_tools::assertion_result::readonly_property65&)
 class BOOST_JOIN( readonly_property, __LINE__ )                                     \
                   ^
../../../../boost/test/tools/assertion_result.hpp:65:5: note: in expansion of macro 'BOOST_READONLY_PROPERTY'
     BOOST_READONLY_PROPERTY( bool, (assertion_result) ) p_predicate_value;
     ^~~~~~~~~~~~~~~~~~~~~~~
../../../../boost/test/utils/class_properties.hpp:148:19: note:   no known conversion for argument 1 from 'boost::logic::tribool' to 'const boost::test_tools::assertion_result::readonly_property65&'
 class BOOST_JOIN( readonly_property, __LINE__ )                                     \
                   ^
../../../../boost/test/tools/assertion_result.hpp:65:5: note: in expansion of macro 'BOOST_READONLY_PROPERTY'
     BOOST_READONLY_PROPERTY( bool, (assertion_result) ) p_predicate_value;
     ^~~~~~~~~~~~~~~~~~~~~~~
../../../../boost/test/utils/class_properties.hpp:148:19: note: candidate: constexpr boost::test_tools::assertion_result::readonly_property65::readonly_property65(boost::test_tools::assertion_result::readonly_property65&&)
 class BOOST_JOIN( readonly_property, __LINE__ )                                     \
                   ^
../../../../boost/test/tools/assertion_result.hpp:65:5: note: in expansion of macro 'BOOST_READONLY_PROPERTY'
     BOOST_READONLY_PROPERTY( bool, (assertion_result) ) p_predicate_value;
     ^~~~~~~~~~~~~~~~~~~~~~~
../../../../boost/test/utils/class_properties.hpp:148:19: note:   no known conversion for argument 1 from 'boost::logic::tribool' to 'boost::test_tools::assertion_result::readonly_property65&&'
 class BOOST_JOIN( readonly_property, __LINE__ )                                     \
                   ^
../../../../boost/test/tools/assertion_result.hpp:65:5: note: in expansion of macro 'BOOST_READONLY_PROPERTY'
     BOOST_READONLY_PROPERTY( bool, (assertion_result) ) p_predicate_value;
     ^~~~~~~~~~~~~~~~~~~~~~~

    "/usr/bin/g++-7"   -std=c++11 -fvisibility-inlines-hidden -fPIC -m64 -O0 -fno-inline -Wall -g -fvisibility=hidden -frounding-math -DBOOST_ALL_NO_LIB=1 -DBOOST_CHRONO_STATIC_LINK=1 -DBOOST_CHRONO_THREAD_DISABLED -DBOOST_SYSTEM_STATIC_LINK=1 -DBOOST_TEST_NO_AUTO_LINK=1 -DBOOST_TIMER_STATIC_LINK=1  -I"../../../.." -c -o "../../../../bin.v2/libs/numeric/interval/test/cmp_tribool.test/gcc-7.3/debug/cxxstd-11-iso/visibility-hidden/libs/numeric/interval/test/cmp_tribool.o" "/boost/libs/numeric/interval/test/cmp_tribool.cpp"

...failed gcc.compile.c++ ../../../../bin.v2/libs/numeric/interval/test/cmp_tribool.test/gcc-7.3/debug/cxxstd-11-iso/visibility-hidden/libs/numeric/interval/test/cmp_tribool.o...

test_sqrt function in mul.cpp got failed. Need to change rounding mode for MXCSR.

Code to reproduce:

#include <boost/numeric/interval.hpp>
#include <boost/test/minimal.hpp>
#include "bugs.hpp"
typedef boost::numeric::interval I;
static bool test_sqrt(double al, double au) {
I a(al, au);
I b = square(sqrt(a));
return subset(abs(a), b);
}
int test_main(int, char*[]) {
BOOST_CHECK(test_sqrt(2, 3));
BOOST_CHECK(test_sqrt(5, 7));
return 0;
}

When linking with -limf(Intel's LIBM Math library), this test would got failed when running. Below is the error message.

test.cpp(15): test test_sqrt(2, 3) failed in function: 'int test_main(int, char **)'
test.cpp(16): test test_sqrt(5, 7) failed in function: 'int test_main(int, char **)'
**** 2 errors detected

This test changed rounding mode only on x87 FPU control register (bits 10 and 11) but not on MXCSR register (bits 13 and 14). There are functions in LIBM that could use x87 or simd instructions. In this case, SSE version of sqrt is called and it uses "sqrtsd %xmm0,%xmm0" instruction. This sqrtsd instruction uses the rounding mode that is in the MXCSR. Therefore, the rounding bits in MXCSR should be updated as well.

Boost.Numeric.Interval: Please specify rounding control mechanism

Hi, I am building an app for IOS (ARM) and I had this issue while compiling:
Boost.Numeric.Interval: Please specify rounding control mechanism.

C99 version should be used in my case but __USE_ISOC99 is not defined.

Modifying the condition with this code (using __cplusplus) fixed the issue:
boost/numeric/interval/hw_rounding.hpp(36)

#if defined(BOOST_NUMERIC_INTERVAL_NO_HARDWARE) && (defined(__USE_ISOC99) || defined(__MSL__) || (defined __cplusplus && __cplusplus >= 201103L))
 #include <boost/numeric/interval/detail/c99_rounding_control.hpp>
#endif

Let me know if I missed something or if you plan to integrate this modification in a next version.

Cheers,
Bastien Commelongue

Code behaves differently if compiled with MSVC vs GCC

VS 19 vs GCC 12
If you build and run the following sample with both compilers:

#include <fenv.h>
#include <iostream>
#pragma warning(push)
#pragma warning(disable : 4702)
#include <boost/numeric/interval.hpp>
#pragma warning(pop)

/// An interval of doubles [lower,upper)
using Interval = boost::numeric::interval<double,boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>,boost::numeric::interval_lib::checking_strict<double>>>;

/// An interval from -DBL_MAX to +DBL_MAX
const inline Interval InfiniteInterval =
	Interval(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max());

int main(void)
{
#ifdef _WIN32
	unsigned int current_word = 0;
	_controlfp_s(&current_word, 0, _MCW_EM);
#else
	feenableexcept(FE_ALL_EXCEPT);
#endif
	auto i = InfiniteInterval;
	boost::numeric::width(i);
	std::cerr << "The end" << std::endl;
}

You will see how it fails with FP exception on linux, but never fails on windows.
The reason is simple:
On linux we adjust only rounding mode

static void set_rounding_mode(rounding_mode mode) { fesetround(mode); }

But on windows in addition to rounding we also mask all the FP exceptions (turn off corresponding flags) because we use _MCW_EM | _MCW_RC instead of _MCW_RC only.

Shouldn't both systems set the same FP settings? If yes - what should they adjust? Both systems should adjust rounding only, or both should adjust rounding and exception masking?
If we only want to change rounding control bits - it is enough to remove _MCW_EM | part of that line and both systems will throw FP exception.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.