Giter Club home page Giter Club logo

integer's Introduction

Boost.Integer

Boost.Integer, part of collection of the Boost C++ Libraries, provides integer type support, particularly helpful in generic programming. It provides the means to select an integer type based upon its properties, like the number of bits or the maximum supported value, as well as compile-time bit mask selection. There is a derivative of std::numeric_limits that provides integral constant expressions for min and max... Finally, it provides two compile-time algorithms: determining the highest power of two in a compile-time value; and computing min and max of constant expressions.

Directories

  • doc - QuickBook documentation sources
  • include - Interface headers of Boost.Integer
  • test - Boost.Integer unit tests

More information

  • Documentation
  • Report bugs. Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well.
  • Submit your patches as pull requests against develop branch. Note that by submitting patches you agree to license your modifications under the Boost Software License, Version 1.0.

Build status

Branch GitHub Actions Drone AppVeyor Test Matrix Dependencies
master GitHub Actions Drone AppVeyor Tests Dependencies
develop GitHub Actions Drone AppVeyor Tests Dependencies

License

Distributed under the Boost Software License, Version 1.0.

integer's People

Contributors

beman avatar bernardosulzbach avatar ctmacuser avatar dabrahams avatar danielae avatar danieljames avatar douggregor avatar eldiener avatar flast avatar glenfe avatar grafikrobot avatar hkaiser avatar imikejackson avatar jensmaurer avatar jewillco avatar joaquintides avatar jsiek avatar jzmaddock avatar lastique avatar mclow avatar nathompson avatar pabristow avatar pdimov avatar rogeeff avatar sdarwin avatar steveire avatar straszheim avatar swatanabe avatar tinko92 avatar viboes avatar

Stargazers

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

Watchers

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

integer's Issues

include/boost/integer_traits.hpp:83:64: error: narrowing conversion of '255' from 'int' to 'char' [-Wnarrowing]

While trying to build ceph with GCC12 in openSUSE Tumbleweed aarch64, we get an error on boost header:

[14382s] [ 58%] Building CXX object src/rgw/CMakeFiles/rgw_common.dir/rgw_tag_s3.cc.o
[14397s] In file included from /home/abuild/rpmbuild/BUILD/ceph-16.2.7-654-gd5a90ff46f0/build/boost/include/boost/integer.hpp:20,
[14397s]                  from /home/abuild/rpmbuild/BUILD/ceph-16.2.7-654-gd5a90ff46f0/build/boost/include/boost/integer/integer_mask.hpp:16,
[14397s]                  from /home/abuild/rpmbuild/BUILD/ceph-16.2.7-654-gd5a90ff46f0/build/boost/include/boost/random/mersenne_twister.hpp:26,
[14397s]                  from /home/abuild/rpmbuild/BUILD/ceph-16.2.7-654-gd5a90ff46f0/build/boost/include/boost/uuid/random_generator.hpp:17,
[14397s]                  from /home/abuild/rpmbuild/BUILD/ceph-16.2.7-654-gd5a90ff46f0/build/boost/include/boost/uuid/uuid_generators.hpp:17,
[14397s]                  from /home/abuild/rpmbuild/BUILD/ceph-16.2.7-654-gd5a90ff46f0/src/include/uuid.h:16,
[14397s]                  from /home/abuild/rpmbuild/BUILD/ceph-16.2.7-654-gd5a90ff46f0/src/include/types.h:21,
[14397s]                  from /home/abuild/rpmbuild/BUILD/ceph-16.2.7-654-gd5a90ff46f0/src/ceph_mgr.cc:21:
[14397s] /home/abuild/rpmbuild/BUILD/ceph-16.2.7-654-gd5a90ff46f0/build/boost/include/boost/integer_traits.hpp:83:64: error: narrowing conversion of '255' from 'int' to 'char' [-Wnarrowing]
[14397s]    83 |     public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX>
[14397s]       |                                                                ^

x86 is fine, so this is likely an issue with char being by default signed or unsigned, depending on architecture.

undefined behavior in gcd when parameters are minimum values of signed integers

This is being reported to me via a clang-analyzer check, and it refers to the gcd template function in common_factor_rt.hpp

Integer template parameter type is a signed integer, and both parameters ('a' and 'b') are std::numeric_limits<Integer>::min.

444 template <typename Integer>
445 inline BOOST_CXX14_CONSTEXPR Integer gcd(Integer const &a, Integer const &b) BOOST_GCD_NOEXCEPT(Integer)
446 {
447     if(a == (std::numeric_limits<Integer>::min)())
448        return a == static_cast<Integer>(0) ? gcd_detail::gcd_traits<Integer>::abs(b) : boost::integer::gcd(static_cast<Integer>(a % b), b);
449     else if (b == (std::numeric_limits<Integer>::min)())
450        return b == static_cast<Integer>(0) ? gcd_detail::gcd_traits<Integer>::abs(a) : boost::integer::gcd(a, static_cast<Integer>(b % a));
451     return gcd_detail::optimal_gcd_select(static_cast<Integer>(gcd_detail::gcd_traits<Integer>::abs(a)), static_cast<Integer>(gcd_detail::gcd_traits<Integer>::abs(b)));
452 }

In the initial invocation, the condition on 447 is true, and the condition on 448 is false. This leads to a recursive call to the function with parameters a=0 and b=std::numeric_limits<Integer>::min.

In the recursive call, the condition on 447 is false, the condition on 449 is true, and the condition on 450 is false. Another recursive call is on-deck with a=0 and b=b%a, But a is zero at this point. Anything mod 0 is undefined behavior.

My suggested fix is to check if a and b are the same value at the start of the function, and return a right away.

Specialize integer_log2 with intrisinc

I think the integer_log2 can be replaced in with an intrisic approach. As far as I can tell, the current approach is not recognized by clang 11.0 as an idiom for integer_log2.

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.