Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/multiprecision/detail/number_base.hpp @ 101:c530137014c0
Update Boost headers (1.58.0)
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:12:49 +0100 |
parents | 2665513ce2d3 |
children |
comparison
equal
deleted
inserted
replaced
100:793467b5e61c | 101:c530137014c0 |
---|---|
73 namespace detail{ | 73 namespace detail{ |
74 // | 74 // |
75 // Workaround for missing abs(long long) and abs(__int128) on some compilers: | 75 // Workaround for missing abs(long long) and abs(__int128) on some compilers: |
76 // | 76 // |
77 template <class T> | 77 template <class T> |
78 typename enable_if_c<(is_signed<T>::value || is_floating_point<T>::value), T>::type abs(T t) BOOST_NOEXCEPT | 78 BOOST_CONSTEXPR typename enable_if_c<(is_signed<T>::value || is_floating_point<T>::value), T>::type abs(T t) BOOST_NOEXCEPT |
79 { | 79 { |
80 return t < 0 ? -t : t; | 80 // This strange expression avoids a hardware trap in the corner case |
81 } | 81 // that val is the most negative value permitted in long long. |
82 template <class T> | 82 // See https://svn.boost.org/trac/boost/ticket/9740. |
83 typename enable_if_c<(is_unsigned<T>::value), T>::type abs(T t) BOOST_NOEXCEPT | 83 return t < 0 ? T(1u) + T(-(t + 1)) : t; |
84 } | |
85 template <class T> | |
86 BOOST_CONSTEXPR typename enable_if_c<(is_unsigned<T>::value), T>::type abs(T t) BOOST_NOEXCEPT | |
84 { | 87 { |
85 return t; | 88 return t; |
86 } | 89 } |
87 | 90 |
88 #define BOOST_MP_USING_ABS using boost::multiprecision::detail::abs; | 91 #define BOOST_MP_USING_ABS using boost::multiprecision::detail::abs; |
92 | |
93 template <class T> | |
94 BOOST_CONSTEXPR typename enable_if_c<(is_signed<T>::value || is_floating_point<T>::value), typename make_unsigned<T>::type>::type unsigned_abs(T t) BOOST_NOEXCEPT | |
95 { | |
96 // This strange expression avoids a hardware trap in the corner case | |
97 // that val is the most negative value permitted in long long. | |
98 // See https://svn.boost.org/trac/boost/ticket/9740. | |
99 return t < 0 ? static_cast<typename make_unsigned<T>::type>(1u) + static_cast<typename make_unsigned<T>::type>(-(t + 1)) : static_cast<typename make_unsigned<T>::type>(t); | |
100 } | |
101 template <class T> | |
102 BOOST_CONSTEXPR typename enable_if_c<(is_unsigned<T>::value), T>::type unsigned_abs(T t) BOOST_NOEXCEPT | |
103 { | |
104 return t; | |
105 } | |
89 | 106 |
90 // | 107 // |
91 // Move support: | 108 // Move support: |
92 // | 109 // |
93 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES | 110 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES |
126 template <class B, class Backend, class Tag> | 143 template <class B, class Backend, class Tag> |
127 struct canonical_imp<number<B, et_off>, Backend, Tag> | 144 struct canonical_imp<number<B, et_off>, Backend, Tag> |
128 { | 145 { |
129 typedef B type; | 146 typedef B type; |
130 }; | 147 }; |
148 #ifdef __SUNPRO_CC | |
149 template <class B, class Backend> | |
150 struct canonical_imp<number<B, et_on>, Backend, mpl::int_<3> > | |
151 { | |
152 typedef B type; | |
153 }; | |
154 template <class B, class Backend> | |
155 struct canonical_imp<number<B, et_off>, Backend, mpl::int_<3> > | |
156 { | |
157 typedef B type; | |
158 }; | |
159 #endif | |
131 template <class Val, class Backend> | 160 template <class Val, class Backend> |
132 struct canonical_imp<Val, Backend, mpl::int_<0> > | 161 struct canonical_imp<Val, Backend, mpl::int_<0> > |
133 { | 162 { |
134 typedef typename has_enough_bits<bits_of<Val>::value>::template type<mpl::_> pred_type; | 163 typedef typename has_enough_bits<bits_of<Val>::value>::template type<mpl::_> pred_type; |
135 typedef typename mpl::find_if< | 164 typedef typename mpl::find_if< |
587 if(digits > 1) | 616 if(digits > 1) |
588 str.append(size_type(digits - 1), '0'); | 617 str.append(size_type(digits - 1), '0'); |
589 } | 618 } |
590 } | 619 } |
591 if(neg) | 620 if(neg) |
592 str.insert(0, 1, '-'); | 621 str.insert(static_cast<std::string::size_type>(0), 1, '-'); |
593 else if(showpos) | 622 else if(showpos) |
594 str.insert(0, 1, '+'); | 623 str.insert(static_cast<std::string::size_type>(0), 1, '+'); |
595 return; | 624 return; |
596 } | 625 } |
597 | 626 |
598 if(!fixed && !scientific && !showpoint) | 627 if(!fixed && !scientific && !showpoint) |
599 { | 628 { |
634 } | 663 } |
635 else if(my_exp + 1 < static_cast<boost::intmax_t>(str.size())) | 664 else if(my_exp + 1 < static_cast<boost::intmax_t>(str.size())) |
636 { | 665 { |
637 if(my_exp < 0) | 666 if(my_exp < 0) |
638 { | 667 { |
639 str.insert(0, static_cast<std::string::size_type>(-1 - my_exp), '0'); | 668 str.insert(static_cast<std::string::size_type>(0), static_cast<std::string::size_type>(-1 - my_exp), '0'); |
640 str.insert(0, "0."); | 669 str.insert(static_cast<std::string::size_type>(0), "0."); |
641 } | 670 } |
642 else | 671 else |
643 { | 672 { |
644 // Insert the decimal point: | 673 // Insert the decimal point: |
645 str.insert(static_cast<std::string::size_type>(my_exp + 1), 1, '.'); | 674 str.insert(static_cast<std::string::size_type>(my_exp + 1), 1, '.'); |
660 else | 689 else |
661 { | 690 { |
662 BOOST_MP_USING_ABS | 691 BOOST_MP_USING_ABS |
663 // Scientific format: | 692 // Scientific format: |
664 if(showpoint || (str.size() > 1)) | 693 if(showpoint || (str.size() > 1)) |
665 str.insert(1, 1, '.'); | 694 str.insert(static_cast<std::string::size_type>(1u), 1, '.'); |
666 str.append(1, 'e'); | 695 str.append(static_cast<std::string::size_type>(1u), 'e'); |
667 S e = boost::lexical_cast<S>(abs(my_exp)); | 696 S e = boost::lexical_cast<S>(abs(my_exp)); |
668 if(e.size() < BOOST_MP_MIN_EXPONENT_DIGITS) | 697 if(e.size() < BOOST_MP_MIN_EXPONENT_DIGITS) |
669 e.insert(0, BOOST_MP_MIN_EXPONENT_DIGITS-e.size(), '0'); | 698 e.insert(static_cast<std::string::size_type>(0), BOOST_MP_MIN_EXPONENT_DIGITS - e.size(), '0'); |
670 if(my_exp < 0) | 699 if(my_exp < 0) |
671 e.insert(0, 1, '-'); | 700 e.insert(static_cast<std::string::size_type>(0), 1, '-'); |
672 else | 701 else |
673 e.insert(0, 1, '+'); | 702 e.insert(static_cast<std::string::size_type>(0), 1, '+'); |
674 str.append(e); | 703 str.append(e); |
675 } | 704 } |
676 if(neg) | 705 if(neg) |
677 str.insert(0, 1, '-'); | 706 str.insert(static_cast<std::string::size_type>(0), 1, '-'); |
678 else if(showpos) | 707 else if(showpos) |
679 str.insert(0, 1, '+'); | 708 str.insert(static_cast<std::string::size_type>(0), 1, '+'); |
680 } | 709 } |
681 | 710 |
682 template <class V> | 711 template <class V> |
683 void check_shift_range(V val, const mpl::true_&, const mpl::true_&) | 712 void check_shift_range(V val, const mpl::true_&, const mpl::true_&) |
684 { | 713 { |
766 typedef typename boost::multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type val_type; | 795 typedef typename boost::multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type val_type; |
767 return val_type(val).template convert_to<R>(); | 796 return val_type(val).template convert_to<R>(); |
768 } | 797 } |
769 | 798 |
770 | 799 |
771 }}} | 800 } |
801 | |
802 namespace constants{ | |
803 | |
804 template <class T> | |
805 struct is_explicitly_convertible_from_string; | |
806 | |
807 template <class B, boost::multiprecision::expression_template_option ET> | |
808 struct is_explicitly_convertible_from_string<boost::multiprecision::number<B, ET> > | |
809 { | |
810 static const bool value = true; | |
811 }; | |
812 | |
813 } | |
814 | |
815 }} | |
772 | 816 |
773 #endif // BOOST_MATH_BIG_NUM_BASE_HPP | 817 #endif // BOOST_MATH_BIG_NUM_BASE_HPP |
774 | 818 |
775 | 819 |