I have been developing control software for a three-phase induction motor. The main task of this C++ code is to control the torque of the motor. In one part of the algorithm (The control algorithm is executed with a period of 100 µs.), I need to calculate the arcsine function. Here is my implementation. I would appreciate your assessment.
Math.h
#include <cstdint>
class Math {
public:
/**
* @brief Function calculates arcsine of a given argument.
* @param x argument, \f$x\in\left<-1, 1\right>\f$
* @return arcsine value of x
*/
static float arcsine(float x);
private:
static const uint16_t kArcSineLutSize = 101;
static const float arcsine_lut[kArcSineLutSize];
}
Math.cpp
float Math::arcsine(float x)
{
bool neg_table_value = false;
if (x < 0) {
// arcsin(-x) = -arcsin(x)
x = -x;
neg_table_value = true;
}
uint16_t index = static_cast<uint16_t>(x * 100.0);
float tmp =
(arcsine_lut[index + 1] - arcsine_lut[index]) * (100.0 * x - index) +
arcsine_lut[index];
if (neg_table_value) {
return -tmp;
} else {
return tmp;
}
}
const float Math::arcsine_lut[Math::kArcSineLutSize] = {
0.0000, 0.0100, 0.0200, 0.0300, 0.0400, 0.0500, 0.0600, 0.0701, 0.0801,
0.0901, 0.1002, 0.1102, 0.1203, 0.1304, 0.1405, 0.1506, 0.1607, 0.1708,
0.1810, 0.1912, 0.2014, 0.2116, 0.2218, 0.2321, 0.2424, 0.2527, 0.2630,
0.2734, 0.2838, 0.2942, 0.3047, 0.3152, 0.3257, 0.3363, 0.3469, 0.3576,
0.3683, 0.3790, 0.3898, 0.4006, 0.4115, 0.4225, 0.4334, 0.4445, 0.4556,
0.4668, 0.4780, 0.4893, 0.5007, 0.5121, 0.5236, 0.5352, 0.5469, 0.5586,
0.5704, 0.5824, 0.5944, 0.6065, 0.6187, 0.6311, 0.6435, 0.6561, 0.6687,
0.6816, 0.6945, 0.7076, 0.7208, 0.7342, 0.7478, 0.7615, 0.7754, 0.7895,
0.8038, 0.8183, 0.8331, 0.8481, 0.8633, 0.8788, 0.8947, 0.9108, 0.9273,
0.9442, 0.9614, 0.9791, 0.9973, 1.0160, 1.0353, 1.0552, 1.0759, 1.0973,
1.1198, 1.1433, 1.1681, 1.1944, 1.2226, 1.2532, 1.2870, 1.3252, 1.3705,
1.4293, 1.5708};