summaryrefslogtreecommitdiff
path: root/nuttx/lib/math/lib_modf.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/lib/math/lib_modf.c')
-rw-r--r--nuttx/lib/math/lib_modf.c87
1 files changed, 40 insertions, 47 deletions
diff --git a/nuttx/lib/math/lib_modf.c b/nuttx/lib/math/lib_modf.c
index 1e6fadc11..3b33cde42 100644
--- a/nuttx/lib/math/lib_modf.c
+++ b/nuttx/lib/math/lib_modf.c
@@ -1,4 +1,14 @@
-/*
+/************************************************************************
+ * lib/math/lib_modf.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,54 +22,37 @@
* 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.
- */
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
-#include <apps/math.h>
-#include <float.h>
#include <stdint.h>
+#include <math.h>
-float modff(float x, float *iptr) {
- if (fabsf(x) >= 8388608.0) {
- *iptr = x;
- return 0.0;
- }
- else if (fabs(x) < 1.0) {
- *iptr = 0.0;
- return x;
- }
- else {
- *iptr = (float) (int) x;
- return (x - *iptr);
- }
-}
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
-double modf(double x, double *iptr) {
- if (fabs(x) >= 4503599627370496.0) {
- *iptr = x;
- return 0.0;
- }
- else if (fabs(x) < 1.0) {
- *iptr = 0.0;
- return x;
- }
- else {
- *iptr = (double) (int64_t) x;
- return (x - *iptr);
- }
+#if CONFIG_HAVE_DOUBLE
+double modf(double x, double *iptr)
+{
+ if (fabs(x) >= 4503599627370496.0)
+ {
+ *iptr = x;
+ return 0.0;
+ }
+ else if (fabs(x) < 1.0)
+ {
+ *iptr = 0.0;
+ return x;
+ }
+ else
+ {
+ *iptr = (double)(int64_t) x;
+ return (x - *iptr);
+ }
}
-
-long double modfl(long double x, long double *iptr) {
- if (fabs(x) >= 4503599627370496.0) {
- *iptr = x;
- return 0.0;
- }
- else if (fabs(x) < 1.0) {
- *iptr = 0.0;
- return x;
- }
- else {
- *iptr = (long double) (int64_t) x;
- return (x - *iptr);
- }
-}
-
+#endif