mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 06:33:35 +08:00
Added pow.
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "math.hpp"
|
||||
|
||||
namespace matrix
|
||||
@@ -67,6 +70,14 @@ public:
|
||||
(*this) /= norm();
|
||||
}
|
||||
|
||||
Vector pow(Type v) const {
|
||||
const Vector &a(*this);
|
||||
Vector r;
|
||||
for (size_t i = 0; i<M; i++) {
|
||||
r(i) = Type(::pow(a(i), v));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace matrix
|
||||
|
||||
@@ -18,6 +18,9 @@ int main()
|
||||
v2.normalize();
|
||||
Vector<float, 5> v3(v2);
|
||||
TEST(v2 == v3);
|
||||
float data1_sq[] = {1,4,9,16,25};
|
||||
Vector<float, 5> v4(data1_sq);
|
||||
TEST(v1 == v4.pow(0.5));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user