You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
#include "ExtendedVector.h"
|
|
|
|
double ExtendedVector::max(const vector<double> &v) {
|
|
double max = numeric_limits<double>::min();
|
|
for (auto it = v.begin(); it != v.end(); ++it) {
|
|
// ich war so erleichtert, als ich endlich std::signbit gefunden habe!
|
|
if ( signbit(max - *it))
|
|
max = *it;
|
|
}
|
|
return max;
|
|
}
|
|
|
|
bool ExtendedVector::allPositive(const vector<double> &v) {
|
|
for (auto it = v.begin(); it != v.end(); ++it) {
|
|
if ( signbit(*it) || (*it == 0) )
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
double ExtendedVector::product(const vector<double> &v1, const vector<double> &v2) {
|
|
double product = 0;
|
|
long unsigned int size = v1.size();
|
|
if ( v1.size() > v2.size() )
|
|
size = v2.size();
|
|
for (long unsigned int i = 0; i < size; i++) {
|
|
product += v1[i] * v2[i];
|
|
}
|
|
return product;
|
|
}
|
|
|
|
vector<double> ExtendedVector::product(const vector<double> &v, double f) {
|
|
vector<double> product;
|
|
for (auto it = v.begin(); it != v.end(); ++it) {
|
|
product.push_back(*it * f);
|
|
}
|
|
return product;
|
|
}
|
|
|
|
double ExtendedVector::norm(const vector<double> &v) {
|
|
return sqrt( ExtendedVector::product(v, v) );
|
|
}
|
|
|
|
void ExtendedVector::normalise(vector<double> &v) {
|
|
vector <double> *address = &v;
|
|
*address = ExtendedVector::product(v, (1.0)/(ExtendedVector::norm(v)));
|
|
return;
|
|
}
|