scifir-units
2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
meca_number
complex_number.cpp
Go to the documentation of this file.
1
#include "
./complex_number.hpp
"
2
3
using namespace
std;
4
5
namespace
scifir
6
{
7
bool
is_complex
(
const
string
&
init_complex_number
)
8
{
9
if
((
init_complex_number
.find(
"+"
) != string::npos
or
init_complex_number
.find(
"-"
) != string::npos)
and
init_complex_number
.length() > 1)
10
{
11
vector<string>
numbers
;
12
boost::split(
numbers
,
init_complex_number
,boost::is_any_of(
"+-"
));
13
if
(
numbers
.size() != 2)
14
{
15
return
false
;
16
}
17
if
((
int
(
numbers
[1].
length
()) - 3) <= 0)
18
{
19
return
false
;
20
}
21
unsigned
int
imaginary_length
=
int
(
numbers
[1].
length
()) - 3;
22
if
(
numbers
[1].
substr
(
imaginary_length
) ==
"(i)"
)
23
{
24
bool
dot_present
=
false
;
25
bool
after_whitespace
=
false
;
26
bool
after_alpha
=
false
;
27
boost::trim(
numbers
[0]);
28
boost::trim(
numbers
[1]);
29
for
(
unsigned
int
i
= 0;
i
<
numbers
[0].length();
i
++)
30
{
31
if
(
numbers
[0][
i
] ==
'.'
)
32
{
33
if
(
dot_present
)
34
{
35
return
false
;
36
}
37
else
38
{
39
dot_present
=
true
;
40
continue
;
41
}
42
}
43
else
if
(
numbers
[0][
i
] ==
' '
)
44
{
45
after_whitespace
=
true
;
46
continue
;
47
}
48
else
if
(!std::isdigit(
numbers
[0][
i
])
and
after_whitespace
==
false
)
49
{
50
return
false
;
51
}
52
else
if
(
after_whitespace
==
true
)
53
{
54
if
(
after_alpha
==
true
and
std::isalpha(
numbers
[0][
i
]))
55
{
56
return
false
;
57
}
58
else
if
(std::isalpha(
numbers
[0][
i
]))
59
{
60
continue
;
61
}
62
else
if
(std::isdigit(
numbers
[0][
i
]))
63
{
64
after_alpha
=
true
;
65
}
66
}
67
}
68
dot_present
=
false
;
69
after_whitespace
=
false
;
70
after_alpha
=
false
;
71
for
(
unsigned
int
i
= 0;
i
<
imaginary_length
;
i
++)
72
{
73
if
(
numbers
[1][
i
] ==
'.'
)
74
{
75
if
(
dot_present
)
76
{
77
return
false
;
78
}
79
else
80
{
81
dot_present
=
true
;
82
continue
;
83
}
84
}
85
else
if
(
numbers
[1][
i
] ==
' '
)
86
{
87
after_whitespace
=
true
;
88
continue
;
89
}
90
else
if
(!std::isdigit(
numbers
[1][
i
])
and
after_whitespace
==
false
)
91
{
92
return
false
;
93
}
94
else
if
(
after_whitespace
==
true
)
95
{
96
if
(
after_alpha
==
true
and
std::isalpha(
numbers
[1][
i
]))
97
{
98
return
false
;
99
}
100
else
if
(std::isalpha(
numbers
[1][
i
]))
101
{
102
continue
;
103
}
104
else
if
(std::isdigit(
numbers
[1][
i
]))
105
{
106
after_alpha
=
true
;
107
}
108
}
109
}
110
return
true
;
111
}
112
else
113
{
114
return
false
;
115
}
116
}
117
else
118
{
119
return
false
;
120
}
121
}
122
}
scifir::coordinates_1d
Definition
coordinates_1d.hpp:18
complex_number.hpp
scifir
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition
address.cpp:6
scifir::is_complex
bool is_complex(const string &init_complex_number)
Definition
complex_number.cpp:7
Generated by
1.9.8