Server IP : 172.67.216.182 / Your IP : 108.162.226.149 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/server/mysql/src/boost/boost_1_59_0/boost/multiprecision/cpp_int/ |
Upload File : |
// Copyright 2012 John Maddock. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_ #ifndef BOOST_MP_CPP_INT_CHECKED_HPP #define BOOST_MP_CPP_INT_CHECKED_HPP namespace boost{ namespace multiprecision{ namespace backends{ namespace detail{ // // Simple routines for performing checked arithmetic with a builtin arithmetic type. // Note that this is not a complete header, it must be included as part of boost/multiprecision/cpp_int.hpp. // inline void raise_overflow(std::string op) { BOOST_THROW_EXCEPTION(std::overflow_error("overflow in " + op)); } inline void raise_add_overflow() { raise_overflow("addition"); } inline void raise_subtract_overflow() { BOOST_THROW_EXCEPTION(std::range_error("Subtraction resulted in a negative value, but the type is unsigned")); } inline void raise_mul_overflow() { raise_overflow("multiplication"); } inline void raise_div_overflow() { raise_overflow("division"); } template <class A> inline A checked_add_imp(A a, A b, const mpl::true_&) { if(a > 0) { if((b > 0) && ((integer_traits<A>::const_max - b) < a)) raise_add_overflow(); } else { if((b < 0) && ((integer_traits<A>::const_min - b) > a)) raise_add_overflow(); } return a + b; } template <class A> inline A checked_add_imp(A a, A b, const mpl::false_&) { if((integer_traits<A>::const_max - b) < a) raise_add_overflow(); return a + b; } template <class A> inline A checked_add(A a, A b, const mpl::int_<checked>&) { return checked_add_imp(a, b, boost::is_signed<A>()); } template <class A> inline A checked_add(A a, A b, const mpl::int_<unchecked>&) { return a + b; } template <class A> inline A checked_subtract_imp(A a, A b, const mpl::true_&) { if(a > 0) { if((b < 0) && ((integer_traits<A>::const_max + b) < a)) raise_subtract_overflow(); } else { if((b > 0) && ((integer_traits<A>::const_min + b) > a)) raise_subtract_overflow(); } return a - b; } template <class A> inline A checked_subtract_imp(A a, A b, const mpl::false_&) { if(a < b) raise_subtract_overflow(); return a - b; } template <class A> inline A checked_subtract(A a, A b, const mpl::int_<checked>&) { return checked_subtract_imp(a, b, boost::is_signed<A>()); } template <class A> inline A checked_subtract(A a, A b, const mpl::int_<unchecked>&) { return a - b; } template <class A> inline A checked_multiply(A a, A b, const mpl::int_<checked>&) { BOOST_MP_USING_ABS if(a && (integer_traits<A>::const_max / abs(a) < abs(b))) raise_mul_overflow(); return a * b; } template <class A> inline A checked_multiply(A a, A b, const mpl::int_<unchecked>&) { return a * b; } template <class A> inline A checked_divide(A a, A b, const mpl::int_<checked>&) { if(b == 0) raise_div_overflow(); return a / b; } template <class A> inline A checked_divide(A a, A b, const mpl::int_<unchecked>&) { return a / b; } template <class A> inline A checked_left_shift(A a, boost::ulong_long_type shift, const mpl::int_<checked>&) { if(a && shift) { if((shift > sizeof(A) * CHAR_BIT) || (a >> (sizeof(A) * CHAR_BIT - shift))) BOOST_THROW_EXCEPTION(std::overflow_error("Shift out of range")); } return a << shift; } template <class A> inline A checked_left_shift(A a, boost::ulong_long_type shift, const mpl::int_<unchecked>&) { return (shift >= sizeof(A) * CHAR_BIT) ? 0 : a << shift; } }}}} // namespaces #endif