ALPSCore reference
checked_divide.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
7 /* $Id$ */
8 
9 #ifndef ALPS_NUMERIC_CHECKED_DIVIDE_HPP
10 #define ALPS_NUMERIC_CHECKED_DIVIDE_HPP
11 
13 
14 #include <type_traits>
15 
16 namespace alps { namespace numeric {
17 
18 
19 
20 template <class T>
21 inline typename std::enable_if<!is_sequence<T>::value,T>::type
22 checked_divide(const T& a,const T& b)
23 {
24  return (b==T() && a==T()? 1. : a/b);
25 }
26 
27 template <class T>
28 inline typename std::enable_if<is_sequence<T>::value,T>::type
29 checked_divide(T a,const T& b)
30 {
31  for(std::size_t i=0;i<b.size();++i)
32  a[i] = checked_divide(a[i],b[i]);
33  return a;
34 }
35 
36 
37 } } // end namespace alps::numeric
38 
39 #endif // ALPS_NUMERIC_CHECKED_DIVIDE_HPP
std::enable_if<!is_sequence< T >::value, T >::type checked_divide(const T &a, const T &b)