-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC2SCalculator.h
46 lines (41 loc) · 876 Bytes
/
C2SCalculator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef C2S_CALCULATOR_H
#define C2S_CALCULATOR_H
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/number.hpp>
namespace c2s
{
namespace calculator
{
template <class T>
class C2SCalculator{
public:
static T add(T a,T b){
return a+b;
}
static T sub(T a,T b){
return a-b;
}
static T mul(T a,T b){
return a*b;
}
static T div(T a,T b){
if(b == 0)
throw std::invalid_argument( "divide by zero" );
return a/b;
}
static T mod(T a, T b){
if(b == 0)
throw std::invalid_argument( "divide by zero" );
return a%b;
}
static T sqrt(T num){
if(num < 0)
throw std::invalid_argument( "imaginary number" );
return boost::multiprecision::sqrt(num);
}
};
}
}
#endif