-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoperations.cpp
90 lines (74 loc) · 2.09 KB
/
operations.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright 2020 Casey Sanchez
*/
#include "operations.hpp"
ExponentiationNode::ExponentiationNode(std::initializer_list<Scalar> const &arguments) : Node(arguments)
{
if (arguments.size() != 2) {
throw std::invalid_argument("ExponentiationNode accepts only 2 arguments");
}
}
std::string ExponentiationNode::Type() const
{
return "ExponentiationNode";
}
std::complex<double> ExponentiationNode::Value() const
{
return std::pow(Argument(0)->Value(), Argument(1)->Value());
}
MultiplicationNode::MultiplicationNode(std::initializer_list<Scalar> const &arguments) : Node(arguments)
{
if (arguments.size() != 2) {
throw std::invalid_argument("MultiplicationNode accepts only 2 arguments");
}
}
std::string MultiplicationNode::Type() const
{
return "MultiplicationNode";
}
std::complex<double> MultiplicationNode::Value() const
{
return Argument(0)->Value() * Argument(1)->Value();
}
DivisionNode::DivisionNode(std::initializer_list<Scalar> const &arguments) : Node(arguments)
{
if (arguments.size() != 2) {
throw std::invalid_argument("DivisionNode accepts only 2 arguments");
}
}
std::string DivisionNode::Type() const
{
return "DivisionNode";
}
std::complex<double> DivisionNode::Value() const
{
return Argument(0)->Value() / Argument(1)->Value();
}
AdditionNode::AdditionNode(std::initializer_list<Scalar> const &arguments) : Node(arguments)
{
if (arguments.size() != 2) {
throw std::invalid_argument("AdditionNode accepts only 2 arguments");
}
}
std::string AdditionNode::Type() const
{
return "AdditionNode";
}
std::complex<double> AdditionNode::Value() const
{
return Argument(0)->Value() + Argument(1)->Value();
}
SubtractionNode::SubtractionNode(std::initializer_list<Scalar> const &arguments) : Node(arguments)
{
if (arguments.size() != 2) {
throw std::invalid_argument("SubtractionNode accepts only 2 arguments");
}
}
std::string SubtractionNode::Type() const
{
return "SubtractionNode";
}
std::complex<double> SubtractionNode::Value() const
{
return Argument(0)->Value() - Argument(1)->Value();
}