1 // Copyright (c) 2006-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/Scalar_factor_traits.h $ 7 // $Id: Scalar_factor_traits.h 52164b1 2019-10-19T15:34:59+02:00 Sébastien Loriot 8 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial 9 // 10 // 11 // Author(s) : Michael Hemmer <hemmer@mpi-inf.mpg.de> 12 13 14 #ifndef CGAL_SQRT_EXTENSION_SCALAR_FACTOR_TRAITS_H 15 #define CGAL_SQRT_EXTENSION_SCALAR_FACTOR_TRAITS_H 16 17 #include <CGAL/basic.h> 18 19 namespace CGAL { 20 21 // This is the specialization for Sqrt_extension 22 template <class COEFF, class ROOT, class ACDE_TAG,class FP_TAG> 23 class Scalar_factor_traits< Sqrt_extension<COEFF, ROOT, ACDE_TAG,FP_TAG> > { 24 public: 25 26 //! the number type for which this instance has been instantiated 27 typedef Sqrt_extension<COEFF, ROOT,ACDE_TAG,FP_TAG> NT; 28 //! the number type of scalars that can be extracted from NT 29 typedef typename Scalar_factor_traits<COEFF>::Scalar Scalar; 30 31 class Scalar_factor 32 { 33 public: 34 //! argument type 35 typedef NT argument_type; 36 //! first argument type 37 typedef NT first_argument_type; 38 //! second argument type 39 typedef Scalar second_argument_type; 40 //! result type 41 typedef Scalar result_type; 42 43 Scalar operator()44 operator () (const NT& x, const Scalar& d_ = Scalar(0) ) { 45 typename Scalar_factor_traits<COEFF>::Scalar_factor sfac; 46 47 Scalar d(d_); 48 Scalar unity(1); 49 if(d==unity) return d; 50 d=sfac(x.a0(),d); 51 if(d==unity) return d; 52 if(x.is_extended()) 53 d=sfac(x.a1(),d); 54 return d; 55 } 56 }; 57 58 class Scalar_div 59 { 60 public: 61 //! first_argument_type 62 typedef NT first_argument_type; 63 //! second_argument_type 64 typedef Scalar second_argument_type; 65 //! divides an extension \c a by a scalar factor \c b operator()66 void operator () (NT& a, const Scalar& b) { 67 CGAL_precondition(b != Scalar(0)); 68 typename Scalar_factor_traits<COEFF>::Scalar_div sdiv; 69 sdiv(a.a0(), b); sdiv(a.a1(), b); // perform division in place 70 } 71 }; 72 }; 73 74 } //namespace CGAL 75 76 #endif 77