├── b2.log
├── html
├── doc
├── images
│ ├── up.png
│ ├── blank.png
│ ├── draft.png
│ ├── home.png
│ ├── next.png
│ ├── note.png
│ ├── prev.png
│ ├── tip.png
│ ├── caution.png
│ ├── warning.png
│ ├── annot-open.png
│ ├── callouts
│ │ ├── 1.png
│ │ ├── 2.png
│ │ ├── 3.png
│ │ ├── 4.png
│ │ ├── 5.png
│ │ ├── 6.png
│ │ ├── 7.png
│ │ ├── 8.png
│ │ ├── 9.png
│ │ ├── 10.png
│ │ ├── 11.png
│ │ ├── 12.png
│ │ ├── 13.png
│ │ ├── 14.png
│ │ └── 15.png
│ ├── important.png
│ ├── toc-blank.png
│ ├── toc-minus.png
│ ├── toc-plus.png
│ └── annot-close.png
├── html
│ ├── images
│ │ ├── up.png
│ │ ├── blank.png
│ │ ├── draft.png
│ │ ├── home.png
│ │ ├── next.png
│ │ ├── note.png
│ │ ├── prev.png
│ │ ├── tip.png
│ │ ├── caution.png
│ │ ├── warning.png
│ │ ├── important.png
│ │ ├── toc-blank.png
│ │ ├── toc-minus.png
│ │ ├── toc-plus.png
│ │ ├── up_disabled.png
│ │ ├── next_disabled.png
│ │ └── prev_disabled.png
│ ├── pre-boost.jpg
│ ├── StepperMotor.gif
│ ├── stepper_profile.png
│ ├── tutorial
│ │ └── pre-boost.jpg
│ ├── promotion_policies
│ │ └── pre-boost.jpg
│ └── eliminate_runtime_penalty
│ │ └── pre-boost.jpg
├── safe_numerics.pdf
└── boostbook
│ ├── accu
│ ├── accu.pdf
│ ├── accu_logo.png
│ ├── makepdf.sh
│ ├── makehtml.sh
│ └── bb2db.xsl
│ ├── images
│ ├── up.png
│ ├── blank.png
│ ├── draft.png
│ ├── home.png
│ ├── next.png
│ ├── note.png
│ ├── prev.png
│ ├── tip.png
│ ├── caution.png
│ ├── warning.png
│ ├── annot-open.png
│ ├── callouts
│ │ ├── 1.png
│ │ ├── 2.png
│ │ ├── 3.png
│ │ ├── 4.png
│ │ ├── 5.png
│ │ ├── 6.png
│ │ ├── 7.png
│ │ ├── 8.png
│ │ ├── 9.png
│ │ ├── 10.png
│ │ ├── 11.png
│ │ ├── 12.png
│ │ ├── 13.png
│ │ ├── 14.png
│ │ └── 15.png
│ ├── important.png
│ ├── toc-blank.png
│ ├── toc-minus.png
│ ├── toc-plus.png
│ └── annot-close.png
│ ├── pre-boost.jpg
│ ├── StepperMotor.gif
│ ├── stepper_profile.png
│ ├── bb2db.xsl
│ ├── makehtml.bat
│ ├── makeproposal.sh
│ ├── makeepub.sh
│ ├── makepdf.sh
│ ├── makehtml.sh
│ ├── ignore_exception.xml
│ ├── HTML.manifest
│ ├── trap_exception.xml
│ └── overflow.xml
├── example
├── stepper-motor.pdf
├── example16.cpp
├── example17.cpp
├── example18.cpp
├── example81.cpp
├── picsfr.h
├── example20.cpp
├── Jamfile.v2
├── example82.cpp
├── motor_test1.c
├── example2.cpp
├── motor_test2.c
├── CMakeLists.txt
├── example1.cpp
├── example11.cpp
├── example13.cpp
├── example10.cpp
├── example14.cpp
├── example8.cpp
├── example6.cpp
├── example3.cpp
├── example5.cpp
├── example83.cpp
├── safe_format.hpp
├── motor_test3.c
├── example15.cpp
├── example4.cpp
└── example19.cpp
├── include
└── boost
│ └── safe_numerics
│ ├── CMakeLists.txt
│ ├── concept
│ ├── CMakeLists.txt
│ ├── integer.hpp
│ ├── numeric.hpp
│ ├── exception_policy.hpp
│ └── promotion_policy.hpp
│ ├── safe_common.hpp
│ ├── safe_integer.hpp
│ ├── range_value.hpp
│ └── safe_integer_range.hpp
├── meta
└── libraries.json
├── test
├── check_symmetry.hpp
├── test_notepad.hpp
├── test_stream_overload.cpp
├── test_add_constexpr.hpp
├── test_or_constexpr.hpp
├── test_xor_constexpr.hpp
├── test_modulus_constexpr.hpp
├── test_divide_constexpr.hpp
├── test_multiply_constexpr.hpp
├── test_subtract_constexpr.hpp
├── test_left_shift_constexpr.hpp
├── test_right_shift_constexpr.hpp
├── test_float.cpp
├── test_cpp.cpp
├── test_checked_and.hpp
├── test_checked_or.hpp
├── test_checked_add.hpp
├── test_checked_xor.hpp
├── test_checked_comparison.hpp
├── test_checked_divide.hpp
├── test_checked_subtract.hpp
├── test_checked_modulus.hpp
├── test_checked_multiply.hpp
├── test_equal_constexpr.hpp
├── test_checked_cast.hpp
├── test_less_than_constexpr.hpp
├── test_concept_integer.cpp
├── test_trap.cpp
├── test_checked_left_shift.hpp
├── test_checked_right_shift.hpp
├── test_concept_numeric.cpp
├── test_xor_native_constexpr.cpp
├── test_or_native_constexpr.cpp
├── test_xor_automatic_constexpr.cpp
├── test_or_automatic_constexpr.cpp
├── test_equal_native_constexpr.cpp
├── test_less_than_native_constexpr.cpp
├── test_divide_native_constexpr.cpp
├── test_divide_automatic_constexpr.cpp
├── test_modulus_native_constexpr.cpp
├── test_equal_automatic_constexpr.cpp
├── test_less_than_automatic_constexpr.cpp
├── test_subtract_native_constexpr.cpp
├── test_modulus_automatic_constexpr.cpp
├── test_right_shift_native_constexpr.cpp
├── test_subtract_automatic_constexpr.cpp
├── test_left_shift_native_constexpr.cpp
├── test_left_shift_automatic_constexpr.cpp
├── test_right_shift_automatic_constexpr.cpp
├── test_add_native_constexpr.cpp
├── test_add_automatic_constexpr.cpp
├── test_multiply_native_constexpr.cpp
├── test_and_native_constexpr.cpp
├── test_and_automatic_constexpr.cpp
├── test_multiply_automatic_constexpr.cpp
├── test_compare_native.hpp
├── test_subtract_native_results.hpp
├── test_multiply_native_results.hpp
├── test_xor_native.cpp
├── test_equal_native.cpp
├── test_less_than_native.cpp
├── test_or_native.cpp
├── test_xor_automatic.cpp
├── test_and_native.cpp
├── test_or_automatic.cpp
├── test_and_automatic.cpp
├── test_modulus_native.cpp
├── test_equal_automatic.cpp
├── test_less_than_automatic.cpp
├── test_right_shift_native.cpp
├── test_left_shift_native.cpp
├── test_modulus_automatic.cpp
├── test_left_shift_automatic.cpp
├── test_divide_automatic.cpp
├── test_divide_native.cpp
├── test_constexpr.cpp
├── test_subtract_automatic.cpp
└── test_right_shift_automatic.cpp
├── index.html
├── appveyor.yml
├── LICENSE_1_0.txt
├── .drone
└── drone.sh
├── README.md
└── .github
└── workflows
├── windows.yml
└── posix.yml
/b2.log:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/html
--------------------------------------------------------------------------------
/doc/images/up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/up.png
--------------------------------------------------------------------------------
/doc/images/blank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/blank.png
--------------------------------------------------------------------------------
/doc/images/draft.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/draft.png
--------------------------------------------------------------------------------
/doc/images/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/home.png
--------------------------------------------------------------------------------
/doc/images/next.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/next.png
--------------------------------------------------------------------------------
/doc/images/note.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/note.png
--------------------------------------------------------------------------------
/doc/images/prev.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/prev.png
--------------------------------------------------------------------------------
/doc/images/tip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/tip.png
--------------------------------------------------------------------------------
/doc/html/images/up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/up.png
--------------------------------------------------------------------------------
/doc/html/pre-boost.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/pre-boost.jpg
--------------------------------------------------------------------------------
/doc/images/caution.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/caution.png
--------------------------------------------------------------------------------
/doc/images/warning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/warning.png
--------------------------------------------------------------------------------
/doc/safe_numerics.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/safe_numerics.pdf
--------------------------------------------------------------------------------
/doc/html/StepperMotor.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/StepperMotor.gif
--------------------------------------------------------------------------------
/doc/html/images/blank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/blank.png
--------------------------------------------------------------------------------
/doc/html/images/draft.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/draft.png
--------------------------------------------------------------------------------
/doc/html/images/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/home.png
--------------------------------------------------------------------------------
/doc/html/images/next.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/next.png
--------------------------------------------------------------------------------
/doc/html/images/note.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/note.png
--------------------------------------------------------------------------------
/doc/html/images/prev.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/prev.png
--------------------------------------------------------------------------------
/doc/html/images/tip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/tip.png
--------------------------------------------------------------------------------
/doc/images/annot-open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/annot-open.png
--------------------------------------------------------------------------------
/doc/images/callouts/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/1.png
--------------------------------------------------------------------------------
/doc/images/callouts/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/2.png
--------------------------------------------------------------------------------
/doc/images/callouts/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/3.png
--------------------------------------------------------------------------------
/doc/images/callouts/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/4.png
--------------------------------------------------------------------------------
/doc/images/callouts/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/5.png
--------------------------------------------------------------------------------
/doc/images/callouts/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/6.png
--------------------------------------------------------------------------------
/doc/images/callouts/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/7.png
--------------------------------------------------------------------------------
/doc/images/callouts/8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/8.png
--------------------------------------------------------------------------------
/doc/images/callouts/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/9.png
--------------------------------------------------------------------------------
/doc/images/important.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/important.png
--------------------------------------------------------------------------------
/doc/images/toc-blank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/toc-blank.png
--------------------------------------------------------------------------------
/doc/images/toc-minus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/toc-minus.png
--------------------------------------------------------------------------------
/doc/images/toc-plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/toc-plus.png
--------------------------------------------------------------------------------
/example/stepper-motor.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/example/stepper-motor.pdf
--------------------------------------------------------------------------------
/doc/boostbook/accu/accu.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/accu/accu.pdf
--------------------------------------------------------------------------------
/doc/boostbook/images/up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/up.png
--------------------------------------------------------------------------------
/doc/boostbook/pre-boost.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/pre-boost.jpg
--------------------------------------------------------------------------------
/doc/html/images/caution.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/caution.png
--------------------------------------------------------------------------------
/doc/html/images/warning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/warning.png
--------------------------------------------------------------------------------
/doc/images/annot-close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/annot-close.png
--------------------------------------------------------------------------------
/doc/images/callouts/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/10.png
--------------------------------------------------------------------------------
/doc/images/callouts/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/11.png
--------------------------------------------------------------------------------
/doc/images/callouts/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/12.png
--------------------------------------------------------------------------------
/doc/images/callouts/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/13.png
--------------------------------------------------------------------------------
/doc/images/callouts/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/14.png
--------------------------------------------------------------------------------
/doc/images/callouts/15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/images/callouts/15.png
--------------------------------------------------------------------------------
/doc/boostbook/StepperMotor.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/StepperMotor.gif
--------------------------------------------------------------------------------
/doc/boostbook/images/blank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/blank.png
--------------------------------------------------------------------------------
/doc/boostbook/images/draft.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/draft.png
--------------------------------------------------------------------------------
/doc/boostbook/images/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/home.png
--------------------------------------------------------------------------------
/doc/boostbook/images/next.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/next.png
--------------------------------------------------------------------------------
/doc/boostbook/images/note.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/note.png
--------------------------------------------------------------------------------
/doc/boostbook/images/prev.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/prev.png
--------------------------------------------------------------------------------
/doc/boostbook/images/tip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/tip.png
--------------------------------------------------------------------------------
/doc/html/images/important.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/important.png
--------------------------------------------------------------------------------
/doc/html/images/toc-blank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/toc-blank.png
--------------------------------------------------------------------------------
/doc/html/images/toc-minus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/toc-minus.png
--------------------------------------------------------------------------------
/doc/html/images/toc-plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/toc-plus.png
--------------------------------------------------------------------------------
/doc/html/stepper_profile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/stepper_profile.png
--------------------------------------------------------------------------------
/doc/boostbook/accu/accu_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/accu/accu_logo.png
--------------------------------------------------------------------------------
/doc/boostbook/images/caution.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/caution.png
--------------------------------------------------------------------------------
/doc/boostbook/images/warning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/warning.png
--------------------------------------------------------------------------------
/doc/html/images/up_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/up_disabled.png
--------------------------------------------------------------------------------
/doc/html/tutorial/pre-boost.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/tutorial/pre-boost.jpg
--------------------------------------------------------------------------------
/doc/boostbook/images/annot-open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/annot-open.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/1.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/2.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/3.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/4.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/5.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/6.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/7.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/8.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/9.png
--------------------------------------------------------------------------------
/doc/boostbook/images/important.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/important.png
--------------------------------------------------------------------------------
/doc/boostbook/images/toc-blank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/toc-blank.png
--------------------------------------------------------------------------------
/doc/boostbook/images/toc-minus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/toc-minus.png
--------------------------------------------------------------------------------
/doc/boostbook/images/toc-plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/toc-plus.png
--------------------------------------------------------------------------------
/doc/boostbook/stepper_profile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/stepper_profile.png
--------------------------------------------------------------------------------
/doc/html/images/next_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/next_disabled.png
--------------------------------------------------------------------------------
/doc/html/images/prev_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/images/prev_disabled.png
--------------------------------------------------------------------------------
/doc/boostbook/images/annot-close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/annot-close.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/10.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/11.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/12.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/13.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/14.png
--------------------------------------------------------------------------------
/doc/boostbook/images/callouts/15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/boostbook/images/callouts/15.png
--------------------------------------------------------------------------------
/doc/html/promotion_policies/pre-boost.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/promotion_policies/pre-boost.jpg
--------------------------------------------------------------------------------
/doc/html/eliminate_runtime_penalty/pre-boost.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/boostorg/safe_numerics/HEAD/doc/html/eliminate_runtime_penalty/pre-boost.jpg
--------------------------------------------------------------------------------
/doc/boostbook/accu/makepdf.sh:
--------------------------------------------------------------------------------
1 | #use -r switch on fop for relaxed validation
2 | xsltproc --xinclude --nonet bb2db.xsl accu.xml > accudocbook4.xml
3 | fop -r -dpi 300 -xsl db2fo.xsl -xml accudocbook4.xml -pdf accu.pdf
4 |
--------------------------------------------------------------------------------
/include/boost/safe_numerics/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | ####################
2 | # add include headers to IDE
3 |
4 | file(GLOB include_files
5 | RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
6 | "*.hpp"
7 | )
8 | add_custom_target(safe_numerics SOURCES ${include_files})
9 |
10 | add_subdirectory("concept")
11 |
12 | # end headers in IDE
13 | ####################
14 |
--------------------------------------------------------------------------------
/doc/boostbook/accu/makehtml.sh:
--------------------------------------------------------------------------------
1 | if test x = x$BOOST_ROOT
2 | then
3 | echo BOOST_ROOT not set
4 | fi
5 | mkdir html
6 | xsltproc --xinclude --nonet bb2db.xsl accu.xml > accudocbook4.xml
7 | xsltproc --nonet db2html.xsl accudocbook4.xml
8 | cp accu_logo.png html
9 | cp $BOOST_ROOT/doc/src/boostbook.css html
10 | cp -R $BOOST_ROOT/doc/html/images html
11 |
--------------------------------------------------------------------------------
/doc/boostbook/bb2db.xsl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/meta/libraries.json:
--------------------------------------------------------------------------------
1 | {
2 | "key": "safe_numerics",
3 | "name": "Safe Numerics",
4 | "authors": [
5 | "Robert Ramey"
6 | ],
7 | "description": "Guaranteed Correct Integer Arithmetic",
8 | "category": [
9 | "Math",
10 | "Correctness"
11 | ],
12 | "maintainers": [
13 | "Robert Ramey "
14 | ],
15 | "cxxstd": "14"
16 | }
17 |
--------------------------------------------------------------------------------
/doc/boostbook/accu/bb2db.xsl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/test/check_symmetry.hpp:
--------------------------------------------------------------------------------
1 | // given an array of values of a particular type
2 | template
3 | constexpr bool check_symmetry(const T (&value)[N]) {
4 | using namespace boost::safe_numerics;
5 | // for each pair of values p1, p2 (100)
6 | for(unsigned int i = 0; i < N; i++)
7 | for(unsigned int j = 0; j < N; j++)
8 | assert(value[i][j] == value[j][i]);
9 | return true;
10 | }
11 |
--------------------------------------------------------------------------------
/include/boost/safe_numerics/concept/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | ####################
2 | # add include headers to IDE
3 |
4 | set(USE_FOLDERS TRUE)
5 |
6 | file(GLOB include_files
7 | RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
8 | "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp"
9 | )
10 | add_custom_target(concept SOURCES ${include_files})
11 | set_target_properties(concept PROPERTIES FOLDER "safe_numerics")
12 |
13 | # end headers in IDE
14 | ####################
15 |
--------------------------------------------------------------------------------
/doc/boostbook/makehtml.bat:
--------------------------------------------------------------------------------
1 | if x == x%BOOST_ROOT% goto abort
2 |
3 | xsltproc --nonet --xinclude bb2db.xsl safe_numerics.xml | xsltproc --nonet db2html.xsl -
4 | xcopy /i /q /y *.jpg ..\html
5 | if not exist ..\html md ..\html
6 | xcopy /i /q /y %BOOST_ROOT%\doc\src\boostbook.css ..\html
7 | if not exist ..\html md ..\html\images
8 | xcopy /i /q /y /s %BOOST_ROOT%\doc\html\images ..\html\images
9 | exit
10 |
11 | :abort
12 | echo BOOST_ROOT not set
13 | exit
14 |
--------------------------------------------------------------------------------
/doc/boostbook/makeproposal.sh:
--------------------------------------------------------------------------------
1 | if test x = x$BOOST_ROOT
2 | then
3 | echo BOOST_ROOT not set
4 | exit 1
5 | fi
6 | #use -r switch on fop for relaxed validation
7 | xsltproc --xinclude --nonet bb2db.xsl proposal.xml \
8 | | fop -r -dpi 300 -xsl db2fo.xsl -xml - -pdf proposal.pdf
9 |
10 | # equivalent alternative?
11 | # xsltproc --xinclude --nonet bb2db.xsl safe_numerics.xml \
12 | # | xsltproc --xinclude --nonet db2fo.xsl - \
13 | # | fop -r -dpi 300 -fo - -pdf safe_numerics.pdf
14 |
15 |
--------------------------------------------------------------------------------
/doc/boostbook/makeepub.sh:
--------------------------------------------------------------------------------
1 | if test x = x$BOOST_ROOT
2 | then
3 | echo BOOST_ROOT not set
4 | exit 1
5 | fi
6 | xsltproc --nonet --xinclude bb2db.xsl safe_numerics.xml | xsltproc --xinclude --nonet --stringparam base.dir ebooktmp db2epub.xsl -
7 | cp *.png ebooktmp/OEBPS/
8 | xsltproc --xinclude --nonet opf.xsl ebooktmp/OEBPS/package.opf >ebooktmp/OEBPS/t.opf
9 | # mv ebooktmp/OEBPS/t.opf ebooktmp/OEBPS/package.opf
10 | cd ebooktmp
11 | zip -r -X ../book.epub mimetype META-INF OEBPS
12 | cd -
13 |
--------------------------------------------------------------------------------
/doc/boostbook/makepdf.sh:
--------------------------------------------------------------------------------
1 | if test x = x$BOOST_ROOT
2 | then
3 | echo BOOST_ROOT not set
4 | exit 1
5 | fi
6 | #use -r switch on fop for relaxed validation
7 | xsltproc --xinclude --nonet bb2db.xsl safe_numerics.xml \
8 | | fop -r -dpi 300 -xsl db2fo.xsl -xml - -pdf ../safe_numerics.pdf
9 |
10 | # equivalent alternative?
11 | # xsltproc --xinclude --nonet bb2db.xsl safe_numerics.xml \
12 | # | xsltproc --xinclude --nonet db2fo.xsl - \
13 | # | fop -r -dpi 300 -fo - -pdf safe_numerics.pdf
14 |
15 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 | Automatic redirection failed, please go to
13 | doc/html/index.html.
14 |
15 |
16 |
--------------------------------------------------------------------------------
/doc/boostbook/makehtml.sh:
--------------------------------------------------------------------------------
1 | if test x = x$BOOST_ROOT
2 | then
3 | echo BOOST_ROOT not set
4 | exit 1
5 | fi
6 | xsltproc --nonet --xinclude bb2db.xsl safe_numerics.xml | xsltproc --nonet db2html.xsl -
7 | cp pre-boost.jpg ../html
8 | cp pre-boost.jpg ../html/eliminate_runtime_penalty
9 | cp pre-boost.jpg ../html/promotion_policies
10 | cp pre-boost.jpg ../html/tutorial
11 | cp StepperMotor.gif ../html/
12 | cp stepper_profile.png ../html/
13 | cp $BOOST_ROOT/doc/src/boostbook.css ../html
14 | cp -R $BOOST_ROOT/doc/html/images ../html
15 |
--------------------------------------------------------------------------------
/test/test_notepad.hpp:
--------------------------------------------------------------------------------
1 | // this is a hack to workaround the limititation of template
2 | // expansion depth in the MSVC compiler.
3 | template
4 | BOOST_MP11_CONSTEXPR mp_if_c::value <= 1024, F> mp_for_each_1( F && f ){
5 | return detail::mp_for_each_impl( mp_rename(), std::forward(f) );
6 | }
7 | template
8 | BOOST_MP11_CONSTEXPR mp_if_c::value >= 1025, F> mp_for_each_1( F && f ){
9 | mp_for_each>( std::forward(f) );
10 | return mp_for_each_1>( std::forward(f) );
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/example/example16.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 | using namespace boost::safe_numerics;
9 |
10 | int f(int i){
11 | return i;
12 | }
13 |
14 | using safe_t = safe;
15 |
16 | int main(){
17 | const long x = 97;
18 | f(x); // OK - implicit conversion to int
19 | const safe_t y = 97;
20 | f(y); // Also OK - checked implicit conversion to int
21 | return 0;
22 | }
--------------------------------------------------------------------------------
/test/test_stream_overload.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | // test stream overload of >> and << for some non-numeric type
8 |
9 | // this is a compile only test - but since many build systems
10 | #include
11 |
12 | struct X {};
13 |
14 | using I = boost::safe_numerics::safe;
15 |
16 | void operator>>(X, I){};
17 | void operator<<(X, I){};
18 |
19 |
20 | void f(X x, I i) {
21 | x << i;
22 | x >> i;
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/include/boost/safe_numerics/concept/integer.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_NUMERIC_CONCEPT_INTEGER_HPP
2 | #define BOOST_NUMERIC_CONCEPT_INTEGER_HPP
3 |
4 | // Copyright (c) 2012 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include "numeric.hpp"
11 |
12 | namespace boost {
13 | namespace safe_numerics {
14 |
15 | template
16 | using Integer = std::integral_constant() && std::numeric_limits::is_integer>;
17 |
18 | } // safe_numerics
19 | } // boost
20 |
21 | #endif // BOOST_NUMERIC_CONCEPT_INTEGER_HPP
22 |
--------------------------------------------------------------------------------
/include/boost/safe_numerics/concept/numeric.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_NUMERIC_CONCEPT_NUMERIC_HPP
2 | #define BOOST_NUMERIC_CONCEPT_NUMERIC_HPP
3 |
4 | // Copyright (c) 2021 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | namespace boost {
15 | namespace safe_numerics {
16 |
17 | template
18 | using Numeric = std::integral_constant::is_specialized>;
19 |
20 | } // safe_numerics
21 | } // boost
22 |
23 | #endif // BOOST_NUMERIC_CONCEPT_NUMERIC_HPP
24 |
--------------------------------------------------------------------------------
/example/example17.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 | #include // uint8_t
9 | using namespace boost::safe_numerics;
10 |
11 | uint8_t f(uint8_t i){
12 | return i;
13 | }
14 |
15 | using safe_t = safe;
16 |
17 | int main(){
18 | const long x = 97;
19 | f(x); // OK - implicit conversion to int can never fail
20 | const safe_t y = 97;
21 | f(y); // could overflow so trap at compile time
22 | return 0;
23 | }
24 |
--------------------------------------------------------------------------------
/example/example18.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 | #include
9 |
10 | using namespace boost::safe_numerics;
11 |
12 | int f(int i){
13 | return i;
14 | }
15 |
16 | template
17 | using safe_literal = safe_signed_literal;
18 |
19 | int main(){
20 | const long x = 97;
21 | f(x); // OK - implicit conversion to int
22 | const safe_literal<97> y;
23 | f(y); // OK - y is a type with min/max = 97;
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/example/example81.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 |
9 | #include
10 | #include // include exception policies
11 |
12 | using safe_t = boost::safe_numerics::safe<
13 | int,
14 | boost::safe_numerics::native,
15 | boost::safe_numerics::loose_trap_policy // note use of "loose_trap_exception" policy!
16 | >;
17 |
18 | int main(){
19 | std::cout << "example 81:\n";
20 | safe_t x(INT_MAX);
21 | safe_t y(2);
22 | safe_t z = x + y; // will fail to compile !
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/example/picsfr.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////////////////
2 | // picsfr.h
3 | // Copyright (c) 2015 Robert Ramey
4 | //
5 | // Distributed under the Boost Software License, Version 1.0. (See
6 | // accompanying file LICENSE_1_0.txt or copy at
7 | // http://www.boost.org/LICENSE_1_0.txt)
8 | //
9 | // Put these in a separate file so they can conditionally included.
10 | // This is necessary since their mere inclusion will cause syntax
11 | // errors on some compilers.
12 |
13 | #ifndef PICSFR_H
14 | #define PICSFR_H
15 |
16 | #byte TRISC = 0xf94
17 | #byte T3CON = 0xfb1
18 | #byte CCP2CON = 0xfba
19 | #byte CCPR2L = 0xfbb
20 | #byte CCPR2H = 0xfbc
21 | #byte CCP1CON = 0xfbd
22 | #byte CCPR1L = 0xfbe
23 | #byte CCPR1H = 0xfbf
24 | #byte T1CON = 0xfcd
25 | #byte TMR1L = 0xfce
26 | #byte TMR1H = 0xfcf
27 | #bit TMR1ON = T1CON.0
28 |
29 | #endif // PICSFR_H
30 |
--------------------------------------------------------------------------------
/include/boost/safe_numerics/concept/exception_policy.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_NUMERIC_CONCEPT_EXCEPTION_POLICY_HPP
2 | #define BOOST_NUMERIC_CONCEPT_EXCEPTION_POLICY_HPP
3 |
4 | // Copyright (c) 2015 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | namespace boost {
11 | namespace safe_numerics {
12 |
13 | template
14 | struct ExceptionPolicy {
15 | const char * message;
16 | /*
17 | BOOST_CONCEPT_USAGE(ExceptionPolicy){
18 | EP::on_arithmetic_error(e, message);
19 | EP::on_undefined_behavior(e, message)
20 | EP::on_implementation_defined_behavior(e, message)
21 | EP::on_uninitialized_value(e, message)
22 | }
23 | */
24 | };
25 |
26 | } // safe_numerics
27 | } // boost
28 |
29 | #endif // BOOST_NUMERIC_CONCEPT_EXCEPTION_POLICY_HPP
30 |
--------------------------------------------------------------------------------
/example/example20.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 |
9 | #include
10 | #include
11 |
12 | int main(){
13 | using ext_uint = boost::safe_numerics::checked_result;
14 | const ext_uint x{4};
15 | const ext_uint y{3};
16 |
17 | // operation is a success!
18 | std::cout << "success! x - y = " << x - y;
19 |
20 | // subtraction would result in -1, and invalid result for an unsigned value
21 | std::cout << "problem: y - x = " << y - x;
22 |
23 | const ext_uint z = y - x;
24 | std::cout << "z = " << z;
25 | // sum of two negative overflows is a negative overflow.
26 | std::cout << "z + z" << z + z;
27 |
28 | return 0;
29 | }
30 |
--------------------------------------------------------------------------------
/test/test_add_constexpr.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_TEST_ADD_CONSTEXPR_HPP
2 | #define BOOST_TEST_ADD_CONSTEXPR_HPP
3 |
4 | // Copyright (c) 2015 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 |
12 | template
13 | constexpr bool test_add_constexpr(
14 | T1 v1,
15 | T2 v2,
16 | char expected_result
17 | ){
18 | using namespace boost::safe_numerics;
19 | // if we don't expect the operation to pass, we can't
20 | // check the constexpr version of the calculation so
21 | // just return success.
22 | if(expected_result == 'x')
23 | return true;
24 | safe_t(v1) + v2;
25 | v1 + safe_t(v2);
26 | safe_t(v1) + safe_t(v2);
27 | return true; // correct result
28 | }
29 |
30 | #endif // BOOST_TEST_ADD_CONSTEXPR_HPP
31 |
--------------------------------------------------------------------------------
/test/test_or_constexpr.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_TEST_ADD_CONSTEXPR_HPP
2 | #define BOOST_TEST_ADD_CONSTEXPR_HPP
3 |
4 | // Copyright (c) 2015 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 |
12 | template
13 | constexpr bool test_or_constexpr(
14 | T1 v1,
15 | T2 v2,
16 | char expected_result
17 | ){
18 | using namespace boost::safe_numerics;
19 | // if we don't expect the operation to pass, we can't
20 | // check the constexpr version of the calculation so
21 | // just return success.
22 | if(expected_result == 'x')
23 | return true;
24 | safe_t(v1) | v2;
25 | v1 | safe_t(v2);
26 | safe_t(v1) | safe_t(v2);
27 | return true; // correct result
28 | }
29 |
30 | #endif // BOOST_TEST_ADD_CONSTEXPR_HPP
31 |
--------------------------------------------------------------------------------
/test/test_xor_constexpr.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_TEST_XOR_CONSTEXPR_HPP
2 | #define BOOST_TEST_XOR_CONSTEXPR_HPP
3 |
4 | // Copyright (c) 2019 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 |
12 | template
13 | constexpr bool test_xor_constexpr(
14 | T1 v1,
15 | T2 v2,
16 | char expected_result
17 | ){
18 | using namespace boost::safe_numerics;
19 | // if we don't expect the operation to pass, we can't
20 | // check the constexpr version of the calculation so
21 | // just return success.
22 | if(expected_result == 'x')
23 | return true;
24 | safe_t(v1) ^ v2;
25 | v1 ^ safe_t(v2);
26 | safe_t(v1) ^ safe_t(v2);
27 | return true; // correct result
28 | }
29 |
30 | #endif // BOOST_TEST_XOR_CONSTEXPR_HPP
31 |
--------------------------------------------------------------------------------
/test/test_modulus_constexpr.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_TEST_ADD_CONSTEXPR_HPP
2 | #define BOOST_TEST_ADD_CONSTEXPR_HPP
3 |
4 | // Copyright (c) 2015 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 |
12 | template
13 | constexpr bool test_modulus_constexpr(
14 | T1 v1,
15 | T2 v2,
16 | char expected_result
17 | ){
18 | using namespace boost::safe_numerics;
19 | // if we don't expect the operation to pass, we can't
20 | // check the constexpr version of the calculation so
21 | // just return success.
22 | if(expected_result == 'x')
23 | return true;
24 | safe_t(v1) % v2;
25 | v1 % safe_t(v2);
26 | safe_t(v1) % safe_t(v2);
27 | return true; // correct result
28 | }
29 |
30 | #endif // BOOST_TEST_ADD_CONSTEXPR_HPP
31 |
--------------------------------------------------------------------------------
/test/test_divide_constexpr.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_TEST_DIVIDE_CONSTEXPR_HPP
2 | #define BOOST_TEST_DIVIDE_CONSTEXPR_HPP
3 |
4 | // Copyright (c) 2015 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 |
12 | template
13 | constexpr bool test_divide_constexpr(
14 | T1 v1,
15 | T2 v2,
16 | char expected_result
17 | ){
18 | using namespace boost::safe_numerics;
19 | // if we don't expect the operation to pass, we can't
20 | // check the constexpr version of the calculation so
21 | // just return success.
22 | if(expected_result == 'x')
23 | return true;
24 | safe_t(v1) / v2;
25 | v1 / safe_t(v2);
26 | safe_t(v1) / safe_t(v2);
27 | return true; // correct result
28 | }
29 |
30 | #endif // BOOST_TEST_DIVIDE_CONSTEXPR_HPP
31 |
--------------------------------------------------------------------------------
/test/test_multiply_constexpr.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_TEST_MULTIPLY_CONSTEXPR_HPP
2 | #define BOOST_TEST_MULTIPLY_CONSTEXPR_HPP
3 |
4 | // Copyright (c) 2019 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 |
12 | template
13 | constexpr bool test_multiply_constexpr(
14 | T1 v1,
15 | T2 v2,
16 | char expected_result
17 | ){
18 | using namespace boost::safe_numerics;
19 | // if we don't expect the operation to pass, we can't
20 | // check the constexpr version of the calculation so
21 | // just return success.
22 | if(expected_result == 'x')
23 | return true;
24 | safe_t(v1) * v2;
25 | v1 * safe_t(v2);
26 | safe_t(v1) * safe_t(v2);
27 | return true; // correct result
28 | }
29 |
30 | #endif // BOOST_TEST_MULTIPLY_CONSTEXPR_HPP
31 |
--------------------------------------------------------------------------------
/test/test_subtract_constexpr.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_TEST_SUBTRACT_CONSTEXPR_HPP
2 | #define BOOST_TEST_SUBTRACT_CONSTEXPR_HPP
3 |
4 | // Copyright (c) 2019 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 |
12 | template
13 | constexpr bool test_subtract_constexpr(
14 | T1 v1,
15 | T2 v2,
16 | char expected_result
17 | ){
18 | using namespace boost::safe_numerics;
19 | // if we don't expect the operation to pass, we can't
20 | // check the constexpr version of the calculation so
21 | // just return success.
22 | if(expected_result == 'x')
23 | return true;
24 | safe_t(v1) - v2;
25 | v1 - safe_t(v2);
26 | safe_t(v1) - safe_t(v2);
27 | return true; // correct result
28 | }
29 |
30 | #endif // BOOST_TEST_SUBTRACT_CONSTEXPR_HPP
31 |
--------------------------------------------------------------------------------
/test/test_left_shift_constexpr.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_TEST_LEFT_SHIFT_CONSTEXPR_HPP
2 | #define BOOST_TEST_LEFT_SHIFT_CONSTEXPR_HPP
3 |
4 | // Copyright (c) 2019 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 |
12 | template
13 | constexpr bool test_left_shift_constexpr(
14 | T1 v1,
15 | T2 v2,
16 | char expected_result
17 | ){
18 | using namespace boost::safe_numerics;
19 | // if we don't expect the operation to pass, we can't
20 | // check the constexpr version of the calculation so
21 | // just return success.
22 | if(expected_result == 'x')
23 | return true;
24 | safe_t(v1) << v2;
25 | v1 << safe_t(v2);
26 | safe_t(v1) << safe_t(v2);
27 | return true; // correct result
28 | }
29 |
30 | #endif // BOOST_TEST_LEFT_SHIFT_CONSTEXPR_HPP
31 |
--------------------------------------------------------------------------------
/test/test_right_shift_constexpr.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_TEST_RIGHT_SHIFT_CONSTEXPR_HPP
2 | #define BOOST_TEST_RIGHT_SHIFT_CONSTEXPR_HPP
3 |
4 | // Copyright (c) 2015 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 |
12 | template
13 | constexpr bool test_right_shift_constexpr(
14 | T1 v1,
15 | T2 v2,
16 | char expected_result
17 | ){
18 | using namespace boost::safe_numerics;
19 | // if we don't expect the operation to pass, we can't
20 | // check the constexpr version of the calculation so
21 | // just return success.
22 | if(expected_result == 'x')
23 | return true;
24 | safe_t(v1) >> v2;
25 | v1 >> safe_t(v2);
26 | safe_t(v1) >> safe_t(v2);
27 | return true; // correct result
28 | }
29 |
30 | #endif // BOOST_TEST_RIGHT_SHIFT_CONSTEXPR_HPP
31 |
--------------------------------------------------------------------------------
/test/test_float.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2012 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | // testing floating point
8 |
9 | // this is a compile only test - but since many build systems
10 | // can't handle a compile-only test - make sure it passes trivially.
11 | #include
12 | #include
13 |
14 | template
15 | void test(){
16 | T t;
17 | U u;
18 | float x = t;
19 | t = x;
20 | t + u;
21 | t - u;
22 | t * u;
23 | t / u;
24 | /**/
25 | // the operators below are restricted to integral types
26 | }
27 | int main(){
28 | using namespace boost::safe_numerics;
29 | /*
30 | test, float>();
31 | test,float>();
32 | test, float>();
33 | test, float>();
34 | */
35 | return 0;
36 | }
37 |
--------------------------------------------------------------------------------
/example/Jamfile.v2:
--------------------------------------------------------------------------------
1 | # Boost.SafeNumerics Library test Jamfile
2 | #
3 | # Copyright (c) 2017 Robert Ramey
4 | #
5 | # Distributed under the Boost Software License, Version 1.0.
6 | # See accompanying file LICENSE_1_0.txt or copy at
7 | # http://www.boost.org/LICENSE_1_0.txt
8 |
9 | import testing ;
10 |
11 | project : requirements /boost/safe_numerics//boost_safe_numerics ;
12 |
13 | run example1.cpp ;
14 | run example2.cpp ;
15 | run example3.cpp ;
16 | run example4.cpp ;
17 | run example5.cpp ;
18 | run example6.cpp ;
19 | run example7.cpp ;
20 | run example8.cpp ;
21 | compile-fail example81.cpp ;
22 | run example82.cpp ;
23 | run example83.cpp ;
24 | run example84.cpp ;
25 | run example10.cpp ;
26 | run example11.cpp ;
27 | run example13.cpp ;
28 | run example14.cpp ;
29 | run example15.cpp : : : /boost/rational//boost_rational ;
30 | run example16.cpp ;
31 | compile-fail example17.cpp ;
32 | run example18.cpp ;
33 | run example19.cpp ;
34 | run example20.cpp ;
35 | run example92.cpp ;
36 | run example93.cpp ;
37 |
38 |
--------------------------------------------------------------------------------
/example/example82.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include "safe_format.hpp" // prints out range and value of any type
13 |
14 | using safe_t = boost::safe_numerics::safe<
15 | int,
16 | boost::safe_numerics::automatic, // note use of "automatic" policy!!!
17 | boost::safe_numerics::loose_trap_policy
18 | >;
19 |
20 | int main(int, const char *[]){
21 | std::cout << "example 82:\n";
22 | safe_t x(INT_MAX);
23 | safe_t y = 2;
24 | std::cout << "x = " << safe_format(x) << std::endl;
25 | std::cout << "y = " << safe_format(y) << std::endl;
26 | std::cout << "x + y = " << safe_format(x + y) << std::endl;
27 | return 0;
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/test/test_cpp.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 | #include
9 |
10 | // include headers to support safe integers
11 | #include
12 |
13 | using promotion_policy = boost::safe_numerics::cpp<
14 | 8, // char 8 bits
15 | 16, // short 16 bits
16 | 16, // int 16 bits
17 | 16, // long 32 bits
18 | 32 // long long 32 bits
19 | >;
20 |
21 | template
22 | struct test {
23 | using ResultType = promotion_policy::result_type;
24 | //boost::safe_numerics::utility::print_type pt;
25 | static_assert(
26 | std::is_same::value,
27 | "is_same"
28 | );
29 | };
30 |
31 | test t1;
32 |
33 | int main(){
34 | return 0;
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/include/boost/safe_numerics/safe_common.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_NUMERIC_SAFE_COMMON_HPP
2 | #define BOOST_NUMERIC_SAFE_COMMON_HPP
3 |
4 | // Copyright (c) 2012 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 |
12 | namespace boost {
13 | namespace safe_numerics {
14 |
15 | // default implementations for required meta-functions
16 | template
17 | struct is_safe : public std::false_type
18 | {};
19 |
20 | template
21 | struct base_type {
22 | using type = T;
23 | };
24 |
25 | template
26 | constexpr const typename base_type::type & base_value(const T & t) {
27 | return static_cast::type & >(t);
28 | }
29 |
30 | template
31 | struct get_promotion_policy {
32 | using type = void;
33 | };
34 |
35 | template
36 | struct get_exception_policy {
37 | using type = void;
38 | };
39 |
40 |
41 | } // safe_numerics
42 | } // boost
43 |
44 | #endif // BOOST_NUMERIC_SAFE_COMMON_HPP
45 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | # Copyright 2018 Peter Dimov
2 | # Distributed under the Boost Software License, Version 1.0.
3 |
4 | version: 1.0.{build}-{branch}
5 |
6 | shallow_clone: true
7 |
8 | branches:
9 | only:
10 | - master
11 | - develop
12 |
13 | environment:
14 | matrix:
15 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
16 | TOOLSET: msvc-14.1
17 | CXXSTD: 14,17
18 |
19 | install:
20 | - cd ..
21 | - git clone -b %APPVEYOR_REPO_BRANCH% https://github.com/boostorg/boost.git boost
22 | - cd boost
23 | - git submodule update --init tools/build
24 | - git submodule update --init libs/config
25 | - git submodule update --init tools/boostdep
26 | - git submodule update --init tools/boost_install
27 | - git submodule update --init libs/headers
28 | - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\safe_numerics\
29 | - python tools/boostdep/depinst/depinst.py safe_numerics
30 | - cmd /c bootstrap
31 | - b2 headers
32 |
33 | build: off
34 |
35 | test_script:
36 | - PATH=%ADDPATH%%PATH%
37 | - if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
38 | - b2 -j 3 libs/safe_numerics/test toolset=%TOOLSET% %CXXSTD%
39 |
--------------------------------------------------------------------------------
/test/test_checked_and.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_SAFE_NUMERICS_TEST_CHECKED_AND_HPP
2 | #define BOOST_SAFE_NUMERICS_TEST_CHECKED_AND_HPP
3 |
4 | // Copyright (c) 2018 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include "test_checked_values.hpp"
11 |
12 | // test result matrices
13 |
14 | // key
15 | // . success
16 | // - negative_overflow_error
17 | // + positive_overflow_error
18 | // ? range_error
19 |
20 | constexpr const char * signed_and_results[] = {
21 | // 012345678
22 | /* 0*/ "!!!!!!!!!",
23 | /* 1*/ "!!!!!!!!!",
24 | /* 2*/ "!!!!!!!!!",
25 | /* 3*/ "!!!.....!",
26 | /* 4*/ "!!!.....!",
27 | /* 5*/ "!!!.....!",
28 | /* 6*/ "!!!.....!",
29 | /* 7*/ "!!!.....!",
30 | /* 8*/ "!!!!!!!!!",
31 | };
32 |
33 | constexpr const char * unsigned_and_results[] = {
34 | // 0123456
35 | /* 0*/ "!!!!!!!",
36 | /* 1*/ "!!!!!!!",
37 | /* 2*/ "!!!!!!!",
38 | /* 3*/ "!!!...!",
39 | /* 4*/ "!!!...!",
40 | /* 5*/ "!!!...!",
41 | /* 6*/ "!!!!!!!",
42 | };
43 |
44 | #endif // BOOST_SAFE_NUMERICS_TEST_CHECKED_AND_HPP
45 |
--------------------------------------------------------------------------------
/test/test_checked_or.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_SAFE_NUMERICS_TEST_CHECKED_OR_HPP
2 | #define BOOST_SAFE_NUMERICS_TEST_CHECKED_OR_HPP
3 |
4 | // Copyright (c) 2018 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include "test_checked_values.hpp"
11 |
12 | // test result matrices
13 |
14 | // key
15 | // . success
16 | // - negative_overflow_error
17 | // + positive_overflow_error
18 | // ? range_error
19 |
20 | constexpr const char * const signed_or_results[] = {
21 | // 012345678
22 | /* 0*/ "!!!!!!!!!",
23 | /* 1*/ "!!!!!!!!!",
24 | /* 2*/ "!!!!!!!!!",
25 | /* 3*/ "!!!.....!",
26 | /* 4*/ "!!!.....!",
27 | /* 5*/ "!!!.....!",
28 | /* 6*/ "!!!.....!",
29 | /* 7*/ "!!!.....!",
30 | /* 8*/ "!!!!!!!!!",
31 | };
32 |
33 | constexpr const char * const unsigned_or_results[] = {
34 | // 0123456
35 | /* 0*/ "!!!!!!!",
36 | /* 1*/ "!!!!!!!",
37 | /* 2*/ "!!!!!!!",
38 | /* 3*/ "!!!...!",
39 | /* 4*/ "!!!...!",
40 | /* 5*/ "!!!...!",
41 | /* 6*/ "!!!!!!!",
42 | };
43 |
44 | #endif // BOOST_SAFE_NUMERICS_TEST_CHECKED_OR_HPP
45 |
--------------------------------------------------------------------------------
/test/test_checked_add.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_SAFE_NUMERICS_TEST_CHECKED_ADD_HPP
2 | #define BOOST_SAFE_NUMERICS_TEST_CHECKED_ADD_HPP
3 |
4 | // Copyright (c) 2018 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include "test_checked_values.hpp"
11 |
12 | // test result matrices
13 |
14 | // key
15 | // . success
16 | // - negative_overflow_error
17 | // + positive_overflow_error
18 | // ! range_error
19 |
20 | constexpr const char * signed_addition_results[] = {
21 | // 012345678
22 | /* 0*/ "!!!!!!!!!",
23 | /* 1*/ "!!!!!!!!!",
24 | /* 2*/ "!!++++++!",
25 | /* 3*/ "!!+++...-",
26 | /* 4*/ "!!++....-",
27 | /* 5*/ "!!+.....-",
28 | /* 6*/ "!!+....--",
29 | /* 7*/ "!!+...---",
30 | /* 8*/ "!!!------",
31 | };
32 |
33 | constexpr const char * unsigned_addition_results[] = {
34 | // 0123456
35 | /* 0*/ "!!!!!!!",
36 | /* 1*/ "!!!!!!!",
37 | /* 2*/ "!!++++!",
38 | /* 3*/ "!!+++.-",
39 | /* 4*/ "!!++..-",
40 | /* 5*/ "!!+...-",
41 | /* 6*/ "!!!----",
42 | };
43 |
44 | #endif // BOOST_SAFE_NUMERICS_TEST_CHECKED_ADD_HPP
45 |
--------------------------------------------------------------------------------
/test/test_checked_xor.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_SAFE_NUMERICS_TEST_CHECKED_XOR_HPP
2 | #define BOOST_SAFE_NUMERICS_TEST_CHECKED_XOR_HPP
3 |
4 | // Copyright (c) 2018 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include "test_checked_values.hpp"
11 |
12 | // test result matrices
13 |
14 | // key
15 | // . success
16 | // - negative_overflow_error
17 | // + positive_overflow_error
18 | // ? range_error
19 |
20 | constexpr const char * const signed_xor_results[] = {
21 | // 012345678
22 | /* 0*/ "!!!!!!!!!",
23 | /* 1*/ "!!!!!!!!!",
24 | /* 2*/ "!!!!!!!!!",
25 | /* 3*/ "!!!.....!",
26 | /* 4*/ "!!!.....!",
27 | /* 5*/ "!!!.....!",
28 | /* 6*/ "!!!.....!",
29 | /* 7*/ "!!!.....!",
30 | /* 8*/ "!!!!!!!!!",
31 | };
32 |
33 | constexpr const char * const unsigned_xor_results[] = {
34 | // 0123456
35 | /* 0*/ "!!!!!!!",
36 | /* 1*/ "!!!!!!!",
37 | /* 2*/ "!!!!!!!",
38 | /* 3*/ "!!!...!",
39 | /* 4*/ "!!!...!",
40 | /* 5*/ "!!!...!",
41 | /* 6*/ "!!!!!!!",
42 | };
43 |
44 | #endif // BOOST_SAFE_NUMERICS_TEST_CHECKED_XOR_HPP
45 |
--------------------------------------------------------------------------------
/include/boost/safe_numerics/safe_integer.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_NUMERIC_SAFE_INTEGER_HPP
2 | #define BOOST_NUMERIC_SAFE_INTEGER_HPP
3 |
4 | // Copyright (c) 2012 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | // not actually used here - but needed for integer arithmetic
11 | // so this is a good place to include it
12 | #include "checked_integer.hpp"
13 | #include "checked_result_operations.hpp"
14 |
15 | #include "safe_base.hpp"
16 | #include "safe_base_operations.hpp"
17 |
18 | #include "native.hpp"
19 | #include "exception_policies.hpp"
20 |
21 | // specialization for meta functions with safe argument
22 | namespace boost {
23 | namespace safe_numerics {
24 |
25 | template <
26 | class T,
27 | class P = native,
28 | class E = default_exception_policy
29 | >
30 | using safe = safe_base<
31 | T,
32 | ::std::numeric_limits::min(),
33 | ::std::numeric_limits::max(),
34 | P,
35 | E
36 | >;
37 |
38 | } // safe_numerics
39 | } // boost
40 |
41 |
42 | #endif // BOOST_NUMERIC_SAFE_INTEGER_HPP
43 |
--------------------------------------------------------------------------------
/test/test_checked_comparison.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_SAFE_NUMERICS_TEST_CHECKED_COMPARISON_HPP
2 | #define BOOST_SAFE_NUMERICS_TEST_CHECKED_COMPARISON_HPP
3 |
4 | // Copyright (c) 2018 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include "test_checked_values.hpp"
11 |
12 | // test result matrices
13 |
14 | // key
15 | // < less than
16 | // > greater than
17 | // = equal to
18 | // ! indeterminant
19 |
20 | constexpr const char * signed_comparison_results[] = {
21 | // 012345678
22 | /* 0*/ "!!!!!!!!!",
23 | /* 1*/ "!!!!!!!!!",
24 | /* 2*/ "!!!>>>>>>",
25 | /* 3*/ "!!<=>>>>>",
26 | /* 4*/ "!!<<=>>>>",
27 | /* 5*/ "!!<<<=>>>",
28 | /* 6*/ "!!<<<<=>>",
29 | /* 7*/ "!!<<<<<=>",
30 | /* 8*/ "!!<<<<<>>>",
38 | /* 3*/ "!!<=>>>",
39 | /* 4*/ "!!<<=>>",
40 | /* 5*/ "!!<<<=>",
41 | /* 6*/ "!!<<< // BOOST_CLANG
11 | #include
12 |
13 | #if BOOST_CLANG == 1
14 | #pragma GCC diagnostic push
15 | #pragma GCC diagnostic ignored "-Wunused-comparison"
16 | #endif
17 |
18 | template
19 | constexpr bool test_equal_constexpr(
20 | T1 v1,
21 | T2 v2,
22 | char expected_result
23 | ){
24 | using namespace boost::safe_numerics;
25 | // if we don't expect the operation to pass, we can't
26 | // check the constexpr version of the calculation so
27 | // just return success.
28 | if(expected_result == 'x')
29 | return true;
30 | safe_t(v1) == v2;
31 | v1 == safe_t(v2);
32 | safe_t(v1) == safe_t(v2);
33 | return true; // correct result
34 | }
35 |
36 | #if BOOST_CLANG == 1
37 | #pragma GCC diagnostic pop
38 | #endif
39 |
40 | #endif // BOOST_TEST_EQUAL_CONSTEXPR_HPP
41 |
--------------------------------------------------------------------------------
/test/test_checked_cast.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_SAFE_NUMERICS_TEST_CHECKED_CAST_HPP
2 | #define BOOST_SAFE_NUMERICS_TEST_CHECKED_CAST_HPP
3 |
4 | // Copyright (c) 2018 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include
11 | #include "test_values.hpp"
12 |
13 | // note: the types indexed on the left side of the table are gathered
14 | // by filtering the test_values list. So the types are in the same
15 | // sequence
16 |
17 | constexpr const char *test_result_cast[boost::mp11::mp_size::value] = {
18 | // 0 0 0 0
19 | // 01234567012345670123456701234567
20 | // 01234567890123456789012345678901
21 | /* 0*/ ".....xx..xx..xx...xx.xxx.xxx.xxx",
22 | /* 1*/ ".........xx..xx.......xx.xxx.xxx",
23 | /* 2*/ ".............xx...........xx.xxx",
24 | /* 3*/ "..............................xx",
25 | /* 4*/ "..xx.xxx.xxx.xxx.....xxx.xxx.xxx",
26 | /* 5*/ "..xx..xx.xxx.xxx.........xxx.xxx",
27 | /* 6*/ "..xx..xx..xx.xxx.............xxx",
28 | /* 7*/ "..xx..xx..xx..xx................"
29 | };
30 |
31 | #endif // BOOST_SAFE_NUMERICS_TEST_CHECKED_CAST_HPP
32 |
--------------------------------------------------------------------------------
/test/test_less_than_constexpr.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_TEST_LESS_THAN_CONSTEXPR_HPP
2 | #define BOOST_TEST_LESS_THAN_CONSTEXPR_HPP
3 |
4 | // Copyright (c) 2019 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include // BOOST_CLANG
11 | #include
12 |
13 | #if BOOST_CLANG==1
14 | #pragma GCC diagnostic push
15 | #pragma GCC diagnostic ignored "-Wunused-comparison"
16 | #endif
17 |
18 | template
19 | constexpr bool test_less_than_constexpr(
20 | T1 v1,
21 | T2 v2,
22 | char expected_result
23 | ){
24 | using namespace boost::safe_numerics;
25 | // if we don't expect the operation to pass, we can't
26 | // check the constexpr version of the calculation so
27 | // just return success.
28 | if(expected_result == 'x')
29 | return true;
30 | safe_t(v1) < v2;
31 | v1 < safe_t(v2);
32 | safe_t(v1) < safe_t(v2);
33 | return true; // correct result
34 | }
35 |
36 | #if BOOST_CLANG==1
37 | #pragma GCC diagnostic pop
38 | #endif
39 |
40 | #endif // BOOST_TEST_LESS_THAN_CONSTEXPR_HPP
41 |
--------------------------------------------------------------------------------
/example/motor_test1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * david austin
3 | * http://www.embedded.com/design/mcus-processors-and-socs/4006438/Generate-stepper-motor-speed-profiles-in-real-time
4 | * DECEMBER 30, 2004
5 | *
6 | * Demo program for stepper motor control with linear ramps
7 | * Hardware: PIC18F252, L6219
8 | *
9 | * Compile with on Microchip XC8 compiler with the command line:
10 | * XC8 --chip=18F252 motor_test1.c
11 | *
12 | * Copyright (c) 2015 Robert Ramey
13 | *
14 | * Distributed under the Boost Software License, Version 1.0. (See
15 | * accompanying file LICENSE_1_0.txt or copy at
16 | * http://www.boost.org/LICENSE_1_0.txt)
17 | */
18 |
19 | #include
20 | #include
21 | #include /* For true/false definition */
22 |
23 | typedef int8_t int8;
24 | typedef int16_t int16;
25 | typedef int32_t int32;
26 | typedef uint8_t uint8;
27 | typedef uint16_t uint16;
28 | typedef uint32_t uint32;
29 |
30 | // 1st step=50ms; max speed=120rpm (based on 1MHz timer, 1.8deg steps)
31 | #define C0 (50000 << 8)
32 | #define C_MIN (2500 << 8)
33 |
34 | #include "motor1.c"
35 |
36 | void main() {
37 | initialize();
38 | while (1) { // repeat 5 revs forward & back
39 | motor_run(1000);
40 | while (run_flg);
41 | motor_run(0);
42 | while (run_flg);
43 | }
44 | } // main()
45 |
--------------------------------------------------------------------------------
/doc/boostbook/ignore_exception.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | ignore_exception
6 |
7 |
8 | Description
9 |
10 | This exception policy can be used to just ignore conditions which
11 | generate incorrect arithmetic results and continue processing. Programs
12 | using this policy along with the native promotion policy
14 | should function as if the library is not even being used.
15 |
16 |
17 |
18 | Model of
19 |
20 | ExceptionPolicy
22 |
23 |
24 |
25 | Header
26 |
27 | #include
28 | <boost/safe_numerics/exception_policy.hpp>
29 |
30 |
31 |
32 |
33 | Example of use
34 |
35 | safe<int, native, ignore_exception> st(4);
36 |
37 |
38 |
--------------------------------------------------------------------------------
/test/test_concept_integer.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | // test Numeric concept - compile only test
8 |
9 | #include
10 | #include
11 | #include "test_checked_values.hpp"
12 |
13 | // test that all intrinsic signed integers are detected as Numeric
14 | using namespace boost::mp11;
15 | static_assert(
16 | mp_all_of<
17 | signed_test_types,
18 | boost::safe_numerics::Integer
19 | >(),
20 | "Integer concept fails on at least one signed integer type"
21 | );
22 | // test that all intrinsic unigned integers are detected as Numeric
23 | static_assert(
24 | mp_all_of<
25 | unsigned_test_types,
26 | boost::safe_numerics::Integer
27 | >(),
28 | "Integer concept fails on at least one unsigned integer type"
29 | );
30 |
31 | struct X {};
32 |
33 | static_assert(
34 | ! boost::safe_numerics::Integer(),
35 | "Type w/o std::numeric_limits entry erroneously detected as Numeric"
36 | );
37 |
38 | #include
39 | #include
40 |
41 | int main(){
42 | boost::safe_numerics::safe s;
43 | std::cout << s;
44 | return 0;
45 | }
46 |
--------------------------------------------------------------------------------
/test/test_trap.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2012 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | // testing trap
8 |
9 | // this is a compile only test - but since many build systems
10 | // can't handle a compile-only test - make sure it passes trivially.
11 |
12 | #include
13 | #include
14 |
15 | using namespace boost::safe_numerics;
16 | template // T is char, int, etc data type
17 | using safe_t = safe<
18 | T,
19 | native,
20 | loose_trap_policy // use for compiling and running tests
21 | >;
22 |
23 | template
24 | void test(){
25 | safe_t t;
26 | safe_t u;
27 | t + u;
28 | t - u;
29 | t * u;
30 | t / u; // could fail regardless of data type
31 | t % u; // could fail regardless of data type
32 | t << u;
33 | t >> u;
34 | t | u;
35 | t & u;
36 | t ^ u;
37 | }
38 | int main(int, char *[]){
39 | test(); // should compile
40 | test(); // should compile
41 | test(); // should fail to compile
42 | test(); // should fail to compile
43 | return 0;
44 | }
45 |
--------------------------------------------------------------------------------
/test/test_checked_left_shift.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_SAFE_NUMERICS_TEST_CHECKED_LEFT_SHIFT_HPP
2 | #define BOOST_SAFE_NUMERICS_TEST_CHECKED_LEFT_SHIFT_HPP
3 |
4 | // Copyright (c) 2018 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include "test_checked_values.hpp"
11 |
12 | // test result matrices
13 |
14 | // key
15 | // . success
16 | // - negative_overflow_error
17 | // + positive_overflow_error
18 | // ! range_error
19 | // n negative_shift, // negative value in shift operator
20 | // s negative_value_shift, // shift a negative value
21 | // l shift_too_large, // l/r shift exceeds variable size
22 |
23 | constexpr char const * const signed_left_shift_results[] = {
24 | // 012345678
25 | /* 0*/ "!!!!!!!!!",
26 | /* 1*/ "!!!!!!!!!",
27 | /* 2*/ "!!++++++!",
28 | /* 3*/ "!!+++....",
29 | /* 4*/ "!!++.....",
30 | /* 5*/ ".........",
31 | /* 6*/ "!!--.....",
32 | /* 7*/ "!!---....",
33 | /* 8*/ "!!------!",
34 | };
35 |
36 | constexpr char const * const unsigned_left_shift_results[] = {
37 | // 0123456
38 | /* 0*/ "!!!!!!!",
39 | /* 1*/ "!!!!!!!",
40 | /* 2*/ "!!++++!",
41 | /* 3*/ "!!+++..",
42 | /* 4*/ "!!++...",
43 | /* 5*/ ".......",
44 | /* 6*/ "!!----!",
45 | };
46 |
47 | #endif // BOOST_SAFE_NUMERICS_TEST_CHECKED_LEFT_SHIFT_HPP
48 |
49 |
--------------------------------------------------------------------------------
/test/test_checked_right_shift.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_SAFE_NUMERICS_TEST_CHECKED_RIGHT_SHIFT_HPP
2 | #define BOOST_SAFE_NUMERICS_TEST_CHECKED_RIGHT_SHIFT_HPP
3 |
4 | // Copyright (c) 2018 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | #include "test_checked_values.hpp"
11 |
12 | // test result matrices
13 |
14 | // key
15 | // . success
16 | // - negative_overflow_error
17 | // + positive_overflow_error
18 | // ? range_error
19 | // n negative_shift, // negative value in shift operator
20 | // s negative_value_shift, // shift a negative value
21 | // l shift_too_large, // l/r shift exceeds variable size
22 |
23 | constexpr char const * const signed_right_shift_results[] = {
24 | // 012345678
25 | /* 0*/ "!!!!!!!!!",
26 | /* 1*/ "!!!!!!!!!",
27 | /* 2*/ "!!!++++++",
28 | /* 3*/ "!!....+++",
29 | /* 4*/ "!!.....++",
30 | /* 5*/ ".........",
31 | /* 6*/ "!!.....--",
32 | /* 7*/ "!!....---",
33 | /* 8*/ "!!!------",
34 | };
35 |
36 | constexpr char const * const unsigned_right_shift_results[] = {
37 | // 0123456
38 | /* 0*/ "!!!!!!!",
39 | /* 1*/ "!!!!!!!",
40 | /* 2*/ "!!!++++",
41 | /* 3*/ "!!....+",
42 | /* 4*/ "!!....+",
43 | /* 5*/ ".......",
44 | /* 6*/ "!!!----",
45 | };
46 |
47 | #endif // BOOST_SAFE_NUMERICS_TEST_CHECKED_RIGHT_SHIFT_HPP
48 |
--------------------------------------------------------------------------------
/LICENSE_1_0.txt:
--------------------------------------------------------------------------------
1 | Boost Software License - Version 1.0 - August 17th, 2003
2 |
3 | Permission is hereby granted, free of charge, to any person or organization
4 | obtaining a copy of the software and accompanying documentation covered by
5 | this license (the "Software") to use, reproduce, display, distribute,
6 | execute, and transmit the Software, and to prepare derivative works of the
7 | Software, and to permit third-parties to whom the Software is furnished to
8 | do so, all subject to the following:
9 |
10 | The copyright notices in the Software and this entire statement, including
11 | the above license grant, this restriction and the following disclaimer,
12 | must be included in all copies of the Software, in whole or in part, and
13 | all derivative works of the Software, unless such copies or derivative
14 | works are solely in the form of machine-executable object code generated by
15 | a source language processor.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 | DEALINGS IN THE SOFTWARE.
24 |
--------------------------------------------------------------------------------
/include/boost/safe_numerics/concept/promotion_policy.hpp:
--------------------------------------------------------------------------------
1 | #ifndef BOOST_NUMERIC_CONCEPT_PROMOTION_POLICY_HPP
2 | #define BOOST_NUMERIC_CONCEPT_PROMOTION_POLICY_HPP
3 |
4 | // Copyright (c) 2015 Robert Ramey
5 | //
6 | // Distributed under the Boost Software License, Version 1.0. (See
7 | // accompanying file LICENSE_1_0.txt or copy at
8 | // http://www.boost.org/LICENSE_1_0.txt)
9 |
10 | namespace boost {
11 | namespace safe_numerics {
12 |
13 | template
14 | struct PromotionPolicy {
15 | using T = int;
16 | using U = int;
17 | using a_type = typename PP::template addition_result;
18 | using s_type = typename PP::template subtraction_result;
19 | using m_type = typename PP::template multiplication_result;
20 | using d_type = typename PP::template division_result;
21 | using mod_type = typename PP::template modulus_result;
22 | using ls_type = typename PP::template left_shift_result;
23 | using rs_type = typename PP::template right_shift_result;
24 | using cc_type = typename PP::template comparison_result;
25 | using baw_type = typename PP::template bitwise_and_result;
26 | using bow_type = typename PP::template bitwise_or_result;
27 | using bxw_type = typename PP::template bitwise_xor_result;
28 | };
29 |
30 | } // safe_numerics
31 | } // boost
32 |
33 | #endif // BOOST_NUMERIC_CONCEPT_EXCEPTION_POLICY_HPP
34 |
--------------------------------------------------------------------------------
/.drone/drone.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Copyright 2020 Rene Rivera, Sam Darwin
4 | # Distributed under the Boost Software License, Version 1.0.
5 | # (See accompanying file LICENSE.txt or copy at http://boost.org/LICENSE_1_0.txt)
6 |
7 | set -e
8 | export TRAVIS_BUILD_DIR=$(pwd)
9 | export DRONE_BUILD_DIR=$(pwd)
10 | export TRAVIS_BRANCH=$DRONE_BRANCH
11 | export VCS_COMMIT_ID=$DRONE_COMMIT
12 | export GIT_COMMIT=$DRONE_COMMIT
13 | export REPO_NAME=$DRONE_REPO
14 | export PATH=~/.local/bin:/usr/local/bin:$PATH
15 |
16 | if [ "$DRONE_JOB_BUILDTYPE" == "boost" ]; then
17 |
18 | echo '==================================> INSTALL'
19 |
20 | BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
21 | cd ..
22 | git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost
23 | cd boost
24 | git submodule update --init tools/build
25 | git submodule update --init libs/config
26 | git submodule update --init tools/boostdep
27 | git submodule update --init tools/boost_install
28 | git submodule update --init libs/headers
29 | mkdir -p libs/safe_numerics
30 | cp -r $TRAVIS_BUILD_DIR/* libs/safe_numerics
31 | python tools/boostdep/depinst/depinst.py safe_numerics
32 | ./bootstrap.sh
33 | ./b2 headers
34 |
35 | echo '==================================> SCRIPT'
36 |
37 | echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
38 | ./b2 -j 3 libs/safe_numerics/test toolset=$TOOLSET cxxstd=$CXXSTD
39 |
40 | fi
41 |
--------------------------------------------------------------------------------
/example/example2.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 |
9 | #include
10 |
11 | int main(int, const char *[]){
12 | std::cout << "example 2:";
13 | std::cout << "undetected overflow in data type" << std::endl;
14 | // problem: undetected overflow
15 | std::cout << "Not using safe numerics" << std::endl;
16 | try{
17 | int x = INT_MAX;
18 | // the following silently produces an incorrect result
19 | ++x;
20 | std::cout << x << " != " << INT_MAX << " + 1" << std::endl;
21 | std::cout << "error NOT detected!" << std::endl;
22 | }
23 | catch(const std::exception &){
24 | std::cout << "error detected!" << std::endl;
25 | }
26 | // solution: replace int with safe
27 | std::cout << "Using safe numerics" << std::endl;
28 | try{
29 | using namespace boost::safe_numerics;
30 | safe x = INT_MAX;
31 | // throws exception when result is past maximum possible
32 | ++x;
33 | assert(false); // never arrive here
34 | }
35 | catch(const std::exception & e){
36 | std::cout << e.what() << std::endl;
37 | std::cout << "error detected!" << std::endl;
38 | }
39 | return 0;
40 | }
41 |
--------------------------------------------------------------------------------
/example/motor_test2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * david austin
3 | * http://www.embedded.com/design/mcus-processors-and-socs/4006438/Generate-stepper-motor-speed-profiles-in-real-time
4 | * DECEMBER 30, 2004
5 | *
6 | * Demo program for stepper motor control with linear ramps
7 | * Hardware: PIC18F252, L6219
8 | *
9 | * Compile with on Microchip XC8 compiler with the command line:
10 | * XC8 --chip=18F252 motor_test2.c
11 | *
12 | * Copyright (c) 2015 Robert Ramey
13 | *
14 | * Distributed under the Boost Software License, Version 1.0. (See
15 | * accompanying file LICENSE_1_0.txt or copy at
16 | * http://www.boost.org/LICENSE_1_0.txt)
17 | */
18 |
19 | #include
20 | #include
21 | #include /* For true/false definition */
22 |
23 | // ***************************
24 | // alias integer types standard C integer types
25 | typedef int8_t int8;
26 | typedef int16_t int16;
27 | typedef int32_t int32;
28 | typedef uint8_t uint8;
29 | typedef uint16_t uint16;
30 | typedef uint32_t uint32;
31 |
32 | // 1st step=50ms; max speed=120rpm (based on 1MHz timer, 1.8deg steps)
33 | #define C0 (50000*8l)
34 | #define C_MIN (2500*8)
35 |
36 | #include "motor2.c"
37 |
38 | void main() {
39 | initialize();
40 | while (1) { // repeat 5 revs forward & back
41 | motor_run(1000);
42 | while (run_flg);
43 | motor_run(0);
44 | while (run_flg);
45 | motor_run(50000);
46 | while (run_flg);
47 | }
48 | } // main()
49 |
--------------------------------------------------------------------------------
/test/test_concept_numeric.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | // test Numeric concept - compile only test
8 |
9 | #include
10 | #include
11 | #include "test_checked_values.hpp"
12 |
13 | // test that all intrinsic signed integers are detected as Numeric
14 | using namespace boost::mp11;
15 | static_assert(
16 | mp_all_of<
17 | signed_test_types,
18 | boost::safe_numerics::Numeric
19 | >(),
20 | "Numeric concept fails on at least one signed integer type"
21 | );
22 | // test that all intrinsic unigned integers are detected as Numeric
23 | static_assert(
24 | mp_all_of<
25 | unsigned_test_types,
26 | boost::safe_numerics::Numeric
27 | >(),
28 | "Numeric concept fails on at least one unsigned integer type"
29 | );
30 |
31 | // test types without a std::numeric_limits entry are NOT detected as Numeric
32 | struct X {};
33 |
34 | static_assert(
35 | ! boost::safe_numerics::Numeric(),
36 | "Type w/o std::numeric_limits entry erroneously detected as Numeric"
37 | );
38 |
39 | #include
40 | #include
41 |
42 | int main(){
43 | boost::safe_numerics::safe s;
44 | std::cout << s;
45 | return 0;
46 | }
47 |
--------------------------------------------------------------------------------
/test/test_xor_native_constexpr.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 | #include
9 |
10 | template
11 | using safe_t = boost::safe_numerics::safe<
12 | T,
13 | boost::safe_numerics::native
14 | >;
15 |
16 | #include "test_xor_constexpr.hpp"
17 | #include "test_values.hpp"
18 |
19 | using namespace boost::mp11;
20 |
21 | template
22 | struct test_pair {
23 | static const std::size_t i = First();
24 | static const std::size_t j = Second();
25 | constexpr static const bool value = test_xor_constexpr(
26 | mp_at_c()(),
27 | mp_at_c()(),
28 | '.'
29 | );
30 | };
31 |
32 | #include
33 | #include
34 |
35 | int main(){
36 | using namespace boost::mp11;
37 | using value_indices = mp_iota_c::value>;
38 |
39 | static_assert(
40 | mp_all_of<
41 | mp_product<
42 | test_pair,
43 | value_indices,
44 | value_indices
45 | >,
46 | mp_to_bool
47 | >(),
48 | "all values for all integer types correctly xor'ed"
49 | );
50 | return 0;
51 | }
52 |
--------------------------------------------------------------------------------
/test/test_or_native_constexpr.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 | #include
9 |
10 | template
11 | using safe_t = boost::safe_numerics::safe<
12 | T,
13 | boost::safe_numerics::native
14 | >;
15 |
16 | #include "test_or_constexpr.hpp"
17 |
18 | #include "test_values.hpp"
19 |
20 | using namespace boost::mp11;
21 |
22 | template
23 | struct test_pair {
24 | static const std::size_t i = First();
25 | static const std::size_t j = Second();
26 | constexpr static const bool value = test_or_constexpr(
27 | mp_at_c()(),
28 | mp_at_c()(),
29 | '.'
30 | );
31 | };
32 |
33 | #include
34 | #include
35 |
36 | int main(){
37 | using namespace boost::mp11;
38 |
39 | using value_indices = mp_iota_c::value>;
40 |
41 | static_assert(
42 | mp_all_of<
43 | mp_product<
44 | test_pair,
45 | value_indices,
46 | value_indices
47 | >,
48 | mp_to_bool
49 | >(),
50 | "all values for all integer types correctly or'ed"
51 | );
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/test/test_xor_automatic_constexpr.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 | #include
9 |
10 | template
11 | using safe_t = boost::safe_numerics::safe<
12 | T,
13 | boost::safe_numerics::automatic
14 | >;
15 |
16 | #include "test_xor_constexpr.hpp"
17 | #include "test_values.hpp"
18 |
19 | using namespace boost::mp11;
20 |
21 | template
22 | struct test_pair {
23 | static const std::size_t i = First();
24 | static const std::size_t j = Second();
25 | constexpr static const bool value = test_xor_constexpr(
26 | mp_at_c()(),
27 | mp_at_c()(),
28 | '.'
29 | );
30 | };
31 |
32 | #include
33 | #include
34 |
35 | int main(){
36 | using namespace boost::mp11;
37 |
38 | using value_indices = mp_iota_c::value>;
39 |
40 | static_assert(
41 | mp_all_of<
42 | mp_product<
43 | test_pair,
44 | value_indices,
45 | value_indices
46 | >,
47 | mp_to_bool
48 | >(),
49 | "all values for all integer types correctly xor'ed"
50 | );
51 | return 0;
52 | }
53 |
--------------------------------------------------------------------------------
/example/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # CMake build control file for safe numerics Library Examples
2 |
3 | ###########################
4 | # examples
5 |
6 | message( STATUS "Runtimes are stored in ${CMAKE_CURRENT_BINARY_DIR}" )
7 |
8 | set(run_examples_list
9 | example1
10 | example2
11 | example3
12 | example4
13 | example5
14 | example6
15 | example7
16 | example8
17 | example82
18 | example83
19 | example84
20 | example10
21 | example11
22 | example13
23 | example14
24 | example15
25 | example16
26 | example18
27 | example19
28 | example20
29 | example92
30 | example93
31 | )
32 |
33 | foreach(test_name ${run_examples_list})
34 | test_run_pass(${test_name})
35 | set_target_properties(${test_name} PROPERTIES FOLDER "run test examples")
36 | endforeach(test_name)
37 |
38 | test_compile_fail(example17)
39 | set_target_properties(example17 PROPERTIES FOLDER "safe numeric compile fail tests")
40 | test_compile_fail(example81)
41 | set_target_properties(example81 PROPERTIES FOLDER "safe numeric compile fail tests")
42 |
43 | # end examples targets
44 | ####################
45 |
46 | ###########################
47 | # add misc files to IDE
48 |
49 | file(GLOB misc_files
50 | RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
51 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.c"
52 | )
53 | add_custom_target(miscellaneous SOURCES ${misc_files})
54 | set_target_properties(miscellaneous PROPERTIES FOLDER "examples")
55 |
56 | # end headers in IDE
57 | ####################
58 |
--------------------------------------------------------------------------------
/test/test_or_automatic_constexpr.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 | #include
9 |
10 | template
11 | using safe_t = boost::safe_numerics::safe<
12 | T,
13 | boost::safe_numerics::automatic
14 | >;
15 |
16 | #include "test_or_constexpr.hpp"
17 |
18 | #include "test_values.hpp"
19 |
20 | using namespace boost::mp11;
21 |
22 | template
23 | struct test_pair {
24 | static const std::size_t i = First();
25 | static const std::size_t j = Second();
26 | constexpr static const bool value = test_or_constexpr(
27 | mp_at_c()(),
28 | mp_at_c()(),
29 | '.'
30 | );
31 | };
32 |
33 | #include
34 | #include
35 |
36 | int main(){
37 | using namespace boost::mp11;
38 |
39 | using value_indices = mp_iota_c::value>;
40 |
41 | static_assert(
42 | mp_all_of<
43 | mp_product<
44 | test_pair,
45 | value_indices,
46 | value_indices
47 | >,
48 | mp_to_bool
49 | >(),
50 | "all values for all integer types correctly or'ed"
51 | );
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/example/example1.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 |
9 | #include
10 |
11 | int main(int, const char *[]){
12 | std::cout << "example 1:";
13 | std::cout << "undetected erroneous expression evaluation" << std::endl;
14 | std::cout << "Not using safe numerics" << std::endl;
15 | try{
16 | std::int8_t x = 127;
17 | std::int8_t y = 2;
18 | std::int8_t z;
19 | // this produces an invalid result !
20 | z = x + y;
21 | std::cout << "error NOT detected!" << std::endl;
22 | std::cout << (int)z << " != " << (int)x << " + " << (int)y << std::endl;
23 | }
24 | catch(const std::exception &){
25 | std::cout << "error detected!" << std::endl;
26 | }
27 | // solution: replace int with safe
28 | std::cout << "Using safe numerics" << std::endl;
29 | try{
30 | using namespace boost::safe_numerics;
31 | safe x = INT_MAX;
32 | safe y = 2;
33 | safe z;
34 | // rather than producing an invalid result an exception is thrown
35 | z = x + y;
36 | }
37 | catch(const std::exception & e){
38 | // which we can catch here
39 | std::cout << "error detected:" << e.what() << std::endl;
40 | }
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/example/example11.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 |
9 | #include
10 |
11 | int main(int, const char * []){
12 | std::cout << "example 1:";
13 | std::cout << "undetected erroneous expression evaluation" << std::endl;
14 | std::cout << "Not using safe numerics" << std::endl;
15 | // problem: arithmetic operations can yield incorrect results.
16 | try{
17 | std::int8_t x = 127;
18 | std::int8_t y = 2;
19 | std::int8_t z;
20 | // this produces an invalid result !
21 | z = x + y;
22 | std::cout << z << " != " << x + y << std::endl;
23 | std::cout << "error NOT detected!" << std::endl;
24 | }
25 | catch(const std::exception &){
26 | std::cout << "error detected!" << std::endl;
27 | }
28 | // solution: replace std::int8_t with safe
29 | std::cout << "Using safe numerics" << std::endl;
30 | try{
31 | using namespace boost::safe_numerics;
32 | safe x = 127;
33 | safe y = 2;
34 | // rather than producing and invalid result an exception is thrown
35 | x + y;
36 | }
37 | catch(const std::exception & e){
38 | // which can catch here
39 | std::cout << e.what() << std::endl;
40 | }
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/example/example13.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 | #include
9 |
10 | #include
11 |
12 | int main(int, const char *[]){
13 | // problem: cannot recover from arithmetic errors
14 | std::cout << "example 7: ";
15 | std::cout << "cannot recover from arithmetic errors" << std::endl;
16 | std::cout << "Not using safe numerics" << std::endl;
17 |
18 | try{
19 | // can't do this as it will crash the program with no
20 | // opportunity for recovery - comment out for example
21 | // int x = 1;
22 | // int y = 0;
23 | // std::cout << x / y;
24 | std::cout << "error cannot be handled at runtime!" << std::endl;
25 | }
26 | catch(const std::exception &){
27 | std::cout << "error handled at runtime!" << std::endl;
28 | }
29 | // solution: replace int with safe
30 | std::cout << "Using safe numerics" << std::endl;
31 | try{
32 | using namespace boost::safe_numerics;
33 | const safe x = 1;
34 | const safe y = 0;
35 | std::cout << x / y;
36 | std::cout << "error NOT detected!" << std::endl;
37 | }
38 | catch(const std::exception & e){
39 | std::cout << "error handled at runtime!" << e.what() << std::endl;
40 | }
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/test/test_equal_native_constexpr.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 | #include
9 | #include "test_compare_native.hpp"
10 |
11 | template
12 | using safe_t = boost::safe_numerics::safe<
13 | T,
14 | boost::safe_numerics::native
15 | >;
16 |
17 | #include "test_equal_constexpr.hpp"
18 |
19 | using namespace boost::mp11;
20 |
21 | template
22 | struct test_pair {
23 | static const std::size_t i = First();
24 | static const std::size_t j = Second();
25 | constexpr static const bool value = test_equal_constexpr(
26 | mp_at_c()(),
27 | mp_at_c()(),
28 | test_compare_native_result[i][j]
29 | );
30 | };
31 |
32 | #include
33 | #include
34 |
35 | int main(){
36 | using namespace boost::mp11;
37 |
38 | using value_indices = mp_iota_c::value>;
39 |
40 | static_assert(
41 | mp_all_of<
42 | mp_product<
43 | test_pair,
44 | value_indices,
45 | value_indices
46 | >,
47 | mp_to_bool
48 | >(),
49 | "all values for all integer types correctly compared for equality"
50 | );
51 | return 0;
52 | }
53 |
--------------------------------------------------------------------------------
/test/test_less_than_native_constexpr.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Robert Ramey
2 | //
3 | // Distributed under the Boost Software License, Version 1.0. (See
4 | // accompanying file LICENSE_1_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include
8 | #include
9 | #include "test_compare_native.hpp"
10 |
11 | template
12 | using safe_t = boost::safe_numerics::safe<
13 | T,
14 | boost::safe_numerics::native
15 | >;
16 |
17 | #include "test_less_than_constexpr.hpp"
18 |
19 | using namespace boost::mp11;
20 |
21 | template
22 | struct test_pair {
23 | static const std::size_t i = First();
24 | static const std::size_t j = Second();
25 | constexpr static const bool value = test_less_than_constexpr(
26 | mp_at_c()(),
27 | mp_at_c()(),
28 | test_compare_native_result[i][j]
29 | );
30 | };
31 |
32 | #include
33 | #include