-
Notifications
You must be signed in to change notification settings - Fork 0
/
Polynomial.inl
executable file
·74 lines (70 loc) · 2.1 KB
/
Polynomial.inl
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
#ifndef POLYNOMIAL_INL
#define POLYNOMIAL_INL
template <>
inline Polynomial<long int>::Polynomial(const std::vector<std::pair<int, std::string> >& terms)
{
_coefficients.resize(get_max_power(terms) + 1);
for (size_t i = 0; i < terms.size(); ++i)
{
_coefficients[terms[i].first] += ::atol(terms[i].second.c_str());
}
check_degree();
}
template <>
inline Polynomial<double>::Polynomial(const std::vector<std::pair<int, std::string> >& terms)
{
_coefficients.resize(get_max_power(terms) + 1);
for (size_t i = 0; i < terms.size(); ++i)
{
_coefficients[terms[i].first] += ::atof(terms[i].second.c_str());
}
check_degree();
}
template <>
inline Polynomial<Quotient<long int> >::Polynomial(const std::vector<std::pair<int, std::string> >& terms)
{
_coefficients.resize(get_max_power(terms) + 1);
for (size_t i = 0; i < terms.size(); ++i)
{
const char* c = terms[i].second.c_str();
const char* d = c;
while (c && *c && *c != '/')
{
++c;
}
if (*c == '/')
{
_coefficients[terms[i].first] += Quotient<long int>(::atoi(d), ::atoi(c + 1));
}
else
{
_coefficients[terms[i].first] += Quotient<long int>(::atoi(d));
}
//std::cout << "_coefficients[" << terms[i].first << "] = [" << _coefficients[terms[i].first] << "]" << std::endl;
}
check_degree();
}
template <>
inline Polynomial<Quotient<VeryLong> >::Polynomial(const std::vector<std::pair<int, std::string> >& terms)
{
_coefficients.resize(get_max_power(terms) + 1);
for (size_t i = 0; i < terms.size(); ++i)
{
const char* c = terms[i].second.c_str();
const char* d = c;
while (c && *c && *c != '/')
{
++c;
}
if (*c == '/')
{
_coefficients[terms[i].first] += Quotient<VeryLong>(VeryLong(std::string(d, c - d)), VeryLong(std::string(c + 1)));
}
else
{
_coefficients[terms[i].first] += Quotient<VeryLong>(VeryLong(std::string(d)));
}
}
check_degree();
}
#endif