diff --git a/src/Function1D.cpp b/src/Function1D.cpp index cc9c3c4..709968f 100644 --- a/src/Function1D.cpp +++ b/src/Function1D.cpp @@ -328,9 +328,9 @@ Matrix Aurora::log(const Matrix& aMatrix, int aBaseNum) { double baseNum = aBaseNum; double temp; + vdLn(1, &baseNum, &temp); for (size_t i = 0; i < size; i++) { - vdLn(1, &baseNum, &temp); data[i] /= temp; } } @@ -371,3 +371,17 @@ Matrix Aurora::mod(const Matrix& aMatrix, double aValue) return Matrix::New(resultData, aMatrix); } + +Matrix Aurora::acos(const Matrix& aMatrix) +{ + if(aMatrix.isComplex() || aMatrix.isNull()) + { + return Matrix(); + } + + size_t size = aMatrix.getDataSize(); + double* matrixData = aMatrix.getData(); + double* resultData = Aurora::malloc(size); + vdAcos(size, matrixData, resultData); + return Matrix::New(resultData, aMatrix); +} diff --git a/src/Function1D.h b/src/Function1D.h index 1b8e54f..456b5cf 100644 --- a/src/Function1D.h +++ b/src/Function1D.h @@ -53,6 +53,8 @@ namespace Aurora { Matrix mod(const Matrix& aMatrix, double aValue); + Matrix acos(const Matrix& aMatrix); + /** * 多项式计算 * @brief 例如p[1 0 1],x[3 2 5],代表对多项式 y = x^2 + 1 求(x=3, x=2, x=5)时所有的y diff --git a/test/Function1D_Test.cpp b/test/Function1D_Test.cpp index 4c37543..ecf70ec 100644 --- a/test/Function1D_Test.cpp +++ b/test/Function1D_Test.cpp @@ -246,3 +246,12 @@ TEST_F(Function1D_Test, mod) { EXPECT_DOUBLE_AE(result.getData()[1],0.83); EXPECT_DOUBLE_AE(result.getData()[2],0.4); } + +TEST_F(Function1D_Test, acos) { + double *data = new double[3]{0.02,0.83,0.4,}; + auto matrix = Aurora::Matrix::fromRawData(data, 3); + auto result = Aurora::acos(matrix); + EXPECT_DOUBLE_AE(result.getData()[0],1.5508); + EXPECT_DOUBLE_AE(result.getData()[1],0.5917); + EXPECT_DOUBLE_AE(result.getData()[2],1.1593); +}