1 // Copyright (c) 2008 Max-Planck-Institute Saarbruecken (Germany). 2 // All rights reserved. 3 // 4 // This file is part of CGAL (www.cgal.org) 5 // 6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Number_types/include/CGAL/Sqrt_extension/Chinese_remainder_traits.h $ 7 // $Id: Chinese_remainder_traits.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot 8 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial 9 // 10 // 11 // Author(s) : Michael Hemmer <hemmer@informatik.uni-mainz.de> 12 13 #ifndef CGAL_SQRT_EXTENSION_CHINESE_REMAINDER_TRAITS 14 #define CGAL_SQRT_EXTENSION_CHINESE_REMAINDER_TRAITS 15 16 #include <CGAL/basic.h> 17 #include <CGAL/Chinese_remainder_traits.h> 18 #include <CGAL/Sqrt_extension/Sqrt_extension_type.h> 19 20 namespace CGAL { 21 22 template <class NT, class ROOT, class ACDE_TAG,class FP_TAG> 23 class Chinese_remainder_traits<CGAL::Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG> >{ 24 private: 25 typedef CGAL::Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG> EXT; 26 typedef Chinese_remainder_traits<NT> CRT_NT; 27 typedef Chinese_remainder_traits<ROOT> CRT_ROOT; 28 29 public : 30 typedef EXT Type; 31 typedef typename CRT_NT::Scalar_type Scalar_type; 32 33 struct Chinese_remainder{ operatorChinese_remainder34 void operator() ( 35 const Scalar_type& m1, const Scalar_type& m2, 36 const Scalar_type& m, 37 const Scalar_type& s, const Scalar_type& t, 38 const Type& u1, const Type& u2, 39 Type& u) const 40 { 41 NT a0,a1; 42 ROOT root; 43 typename CRT_NT::Chinese_remainder chinese_remainder_nt; 44 chinese_remainder_nt(m1,m2,m,s,t,u1.a0(),u2.a0(),a0); 45 46 CGAL_postcondition_msg(!((u1.is_extended() && !u2.is_extended()) 47 || (!u1.is_extended() && u2.is_extended())), 48 " chinese remainder not possible for these numbers"); 49 50 if(u1.is_extended() || u2.is_extended()){ 51 chinese_remainder_nt(m1,m2,m,s,t,u1.a1(),u2.a1(),a1); 52 typename CRT_ROOT::Chinese_remainder chinese_remainder_root; 53 chinese_remainder_root(m1,m2,m,s,t,u1.root(),u2.root(),root); 54 u=Type(a0,a1,root); 55 }else{ 56 u=Type(a0); 57 } 58 } operatorChinese_remainder59 void operator() ( 60 const Scalar_type& m1, const Type& u1, 61 const Scalar_type& m2, const Type& u2, 62 Scalar_type& m, Type& u) const { 63 Scalar_type s,t; 64 CGAL::extended_euclidean_algorithm(m1,m2,s,t); 65 m = m1 * m2; 66 this->operator()(m1,m2,m,s,t,u1,u2,u); 67 } 68 }; 69 }; 70 71 } // namespace CGAL 72 73 #endif // CGAL_SQRT_EXTENSION_CHINESE_REMAINDER_TRAITS 74