Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:18

0001 #ifndef BOOST_RATIO_DETAIL_GCD_LCM_HPP
0002 #define BOOST_RATIO_DETAIL_GCD_LCM_HPP
0003 
0004 // Copyright 2023 Peter Dimov
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // https://www.boost.org/LICENSE_1_0.txt
0007 
0008 #include <type_traits>
0009 #include <cstdint>
0010 
0011 namespace boost
0012 {
0013 namespace ratio_detail
0014 {
0015 
0016 template<std::intmax_t A> struct abs_: std::integral_constant<std::intmax_t, A < 0? -A: A>
0017 {
0018 };
0019 
0020 template<> struct abs_<INTMAX_MIN>: std::integral_constant<std::intmax_t, INTMAX_MIN>
0021 {
0022 };
0023 
0024 template<std::intmax_t A, std::intmax_t B> struct gcd_: public gcd_<B, A % B>
0025 {
0026 };
0027 
0028 template<std::intmax_t A> struct gcd_<A, 0>: std::integral_constant<std::intmax_t, A>
0029 {
0030 };
0031 
0032 template<std::intmax_t A, std::intmax_t B> struct lcm_: std::integral_constant<std::intmax_t, (A / gcd_<A, B>::value) * B>
0033 {
0034 };
0035 
0036 template<> struct lcm_<0, 0>: std::integral_constant<std::intmax_t, 0>
0037 {
0038 };
0039 
0040 //
0041 
0042 template<std::intmax_t A, std::intmax_t B> struct gcd: abs_< gcd_<A, B>::value >
0043 {
0044 };
0045 
0046 template<std::intmax_t A, std::intmax_t B> struct lcm: abs_< lcm_<A, B>::value >
0047 {
0048 };
0049 
0050 } // namespace ratio_detail
0051 } // namespace boost
0052 
0053 #endif // BOOST_RATIO_DETAIL_GCD_LCM_HPP