summaryrefslogtreecommitdiff
path: root/nuttx/lib/math/lib_asin.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/lib/math/lib_asin.c')
-rw-r--r--nuttx/lib/math/lib_asin.c107
1 files changed, 44 insertions, 63 deletions
diff --git a/nuttx/lib/math/lib_asin.c b/nuttx/lib/math/lib_asin.c
index 9d72e8042..1469d1ed8 100644
--- a/nuttx/lib/math/lib_asin.c
+++ b/nuttx/lib/math/lib_asin.c
@@ -1,4 +1,14 @@
-/*
+/************************************************************************
+ * lib/math/lib_sin.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -12,77 +22,48 @@
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
+ *
+ ************************************************************************/
-#include <apps/math.h>
-#include <float.h>
-
-float asinf(float x) {
- long double y, y_sin, y_cos;
-
- y = 0;
-
- while (1) {
- y_sin = sinf(y);
- y_cos = cosf(y);
-
- if (y > M_PI_2 || y < -M_PI_2) {
- y = fmodf(y, M_PI);
- }
-
- if (y_sin + DBL_EPSILON >= x && y_sin - DBL_EPSILON <= x) {
- break;
- }
-
- y = y - (y_sin - x) / y_cos;
- }
-
- return y;
-}
-
-double asin(double x) {
- long double y, y_sin, y_cos;
-
- y = 0;
-
- while (1) {
- y_sin = sin(y);
- y_cos = cos(y);
+/************************************************************************
+ * Included Files
+ ************************************************************************/
- if (y > M_PI_2 || y < -M_PI_2) {
- y = fmod(y, M_PI);
- }
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
- if (y_sin + DBL_EPSILON >= x && y_sin - DBL_EPSILON <= x) {
- break;
- }
-
- y = y - (y_sin - x) / y_cos;
- }
+#include <math.h>
+#include <float.h>
- return y;
-}
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
-long double asinl(long double x) {
- long double y, y_sin, y_cos;
+#if CONFIG_HAVE_DOUBLE
+double asin(double x)
+{
+ long double y, y_sin, y_cos;
- y = 0;
+ y = 0;
- while (1) {
- y_sin = sinl(y);
- y_cos = cosl(y);
+ while (1)
+ {
+ y_sin = sin(y);
+ y_cos = cos(y);
- if (y > M_PI_2 || y < -M_PI_2) {
- y = fmodl(y, M_PI);
- }
+ if (y > M_PI_2 || y < -M_PI_2)
+ {
+ y = fmod(y, M_PI);
+ }
- if (y_sin + LDBL_EPSILON >= x && y_sin - LDBL_EPSILON <= x) {
- break;
- }
+ if (y_sin + DBL_EPSILON >= x && y_sin - DBL_EPSILON <= x)
+ {
+ break;
+ }
- y = y - (y_sin - x) / y_cos;
- }
+ y = y - (y_sin - x) / y_cos;
+ }
- return y;
+ return y;
}
-
+#endif