summaryrefslogtreecommitdiff
path: root/nuttx/include
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-10-28 18:42:09 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-10-28 18:42:09 +0000
commit2e745de2f7768f4932e365f0a49edbe15a448818 (patch)
tree73b8411e1d00ef6df3dd5fa2ed717241174ae14b /nuttx/include
parent83edd56f6581555c199f3cc3a96ed80f58554c1a (diff)
downloadpx4-nuttx-2e745de2f7768f4932e365f0a49edbe15a448818.tar.gz
px4-nuttx-2e745de2f7768f4932e365f0a49edbe15a448818.tar.bz2
px4-nuttx-2e745de2f7768f4932e365f0a49edbe15a448818.zip
lib/math files not follow coding standard; float, double, and long double versions in separate files to reduce size of dumb link
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5270 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/include')
-rw-r--r--nuttx/include/nuttx/compiler.h8
-rw-r--r--nuttx/include/nuttx/float.h225
-rw-r--r--nuttx/include/nuttx/math.h262
3 files changed, 491 insertions, 4 deletions
diff --git a/nuttx/include/nuttx/compiler.h b/nuttx/include/nuttx/compiler.h
index bbb23d01d..510f7d411 100644
--- a/nuttx/include/nuttx/compiler.h
+++ b/nuttx/include/nuttx/compiler.h
@@ -196,8 +196,9 @@
/* GCC supports both types double and long long */
-# define CONFIG_HAVE_DOUBLE 1
# define CONFIG_HAVE_LONG_LONG 1
+# define CONFIG_HAVE_DOUBLE 1
+# define CONFIG_HAVE_LONG_DOUBLE 1
/* Structures and unions can be assigned and passed as values */
@@ -301,6 +302,7 @@
# undef CONFIG_HAVE_LONG_LONG
# undef CONFIG_HAVE_DOUBLE
+# undef CONFIG_HAVE_LONG_DOUBLE
/* Structures and unions cannot be passed as values or used
* in assignments.
@@ -403,8 +405,9 @@
* simply do not support long long or double.
*/
-# undef CONFIG_HAVE_DOUBLE
# undef CONFIG_HAVE_LONG_LONG
+# undef CONFIG_HAVE_DOUBLE
+# undef CONFIG_HAVE_LONG_DOUBLE
/* Structures and unions can be assigned and passed as values */
@@ -441,6 +444,7 @@
# define inline
# undef CONFIG_HAVE_LONG_LONG
# undef CONFIG_HAVE_DOUBLE
+# undef CONFIG_HAVE_LONG_DOUBLE
# undef CONFIG_CAN_PASS_STRUCTS
#endif
diff --git a/nuttx/include/nuttx/float.h b/nuttx/include/nuttx/float.h
new file mode 100644
index 000000000..a8e4aa28b
--- /dev/null
+++ b/nuttx/include/nuttx/float.h
@@ -0,0 +1,225 @@
+/****************************************************************************
+ * include/nuttx/float.h
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Reference: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/float.h.html
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_FLOAT_H
+#define __INCLUDE_NUTTX_FLOAT_H
+
+/* TODO: These values could vary with architectures toolchains. This
+ * logic should be move at least to the include/arch directory.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Radix of exponent representation, b. */
+
+#define FLT_RADIX 2
+
+/* Number of base-FLT_RADIX digits in the floating-point significand, p. */
+
+#define FLT_MANT_DIG 24
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MANT_DIG 53
+#else
+# define DBL_MANT_DIG FLT_MANT_DIG
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MANT_DIG DBL_MANT_DIG /* FIX ME */
+#else
+# define LDBL_MANT_DIG DBL_MANT_DIG
+#endif
+
+/* Number of decimal digits, n, such that any floating-point number in the
+ * widest supported floating type with pmax radix b digits can be rounded
+ * to a floating-point number with n decimal digits and back again without
+ * change to the value.
+ */
+
+#define DECIMAL_DIG 10
+
+/* Number of decimal digits, q, such that any floating-point number with q
+ * decimal digits can be rounded into a floating-point number with p radix
+ * b digits and back again without change to the q decimal digits.
+ */
+
+#define FLT_DIG 6
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_DIG 15 /* 10 */
+#else
+# define DBL_DIG FLT_DIG
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_DIG DBL_DIG /* FIX ME */
+#else
+# define LDBL_DIG DBL_DIG
+#endif
+
+/* Minimum negative integer such that FLT_RADIX raised to that power minus
+ * 1 is a normalized floating-point number, emin.
+ */
+
+#define FLT_MIN_EXP (-125)
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MIN_EXP (-1021)
+#else
+# define DBL_MIN_EXP FLT_MIN_EXP
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MIN_EXP DBL_MIN_EXP /* FIX ME */
+#else
+# define LDBL_MIN_EXP DBL_MIN_EXP
+#endif
+
+/* inimum negative integer such that 10 raised to that power is in the range
+ * of normalized floating-point numbers.
+ */
+
+#define FLT_MIN_10_EXP (-37)
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MIN_10_EXP (-307) /* -37 */
+#else
+# define DBL_MIN_10_EXP FLT_MIN_10_EXP
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MIN_10_EXP DBL_MIN_10_EXP /* FIX ME */
+#else
+# define LDBL_MIN_10_EXP DBL_MIN_10_EXP
+#endif
+
+/* Maximum integer such that FLT_RADIX raised to that power minus 1 is a
+ * representable finite floating-point number, emax.
+ */
+
+#define FLT_MAX_EXP 128
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MAX_EXP 1024
+#else
+# define DBL_MAX_EXP FLT_MAX_EXP
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MAX_EXP DBL_MAX_EXP /* FIX ME */
+#else
+# define LDBL_MAX_EXP DBL_MAX_EXP
+#endif
+
+/* Maximum integer such that 10 raised to that power is in the range of
+ * representable finite floating-point numbers.
+ */
+
+#define FLT_MAX_10_EXP 38 /* 37 */
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MAX_10_EXP 308 /* 37 */
+#else
+# define DBL_MAX_10_EXP FLT_MAX_10_EXP
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MAX_10_EXP DBL_MAX_10_EXP /* FIX ME */
+#else
+# define LDBL_MAX_10_EXP DBL_MAX_10_EXP
+#endif
+
+/* Maximum representable finite floating-point number. */
+
+#define FLT_MAX 3.40282347e+38F /* 1E+37 */
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MAX 1.7976931348623157e+308 /* 1E+37 */
+#else
+# define DBL_MAX FLT_MAX
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MAX DBL_MAX /* FIX ME */
+#else
+# define LDBL_MAX DBL_MAX
+#endif
+
+/* The difference between 1 and the least value greater than 1 that is
+ * representable in the given floating-point type, b1-p.
+ */
+
+#define FLT_EPSILON 1.1920929e-07F /* 1E-5 */
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_EPSILON 2.2204460492503131e-16 /* 1E-9 */
+#else
+# define DBL_EPSILON FLT_EPSILON
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_EPSILON DBL_EPSILON /* FIX ME */
+#else
+# define LDBL_EPSILON DBL_EPSILON
+#endif
+
+/* Minimum normalized positive floating-point number, bemin -1. */
+
+#define FLT_MIN 1.17549435e-38F /* 1E-37 */
+
+#if CONFIG_HAVE_DOUBLE
+#define DBL_MIN 2.2250738585072014e-308 /* 1E-37 */
+#else
+# define DBL_MIN FLT_MIN
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MIN DBL_MIN /* FIX ME */
+#else
+# define LDBL_MIN DBL_MIN
+#endif
+
+#endif /* __INCLUDE_NUTTX_FLOAT_H */
diff --git a/nuttx/include/nuttx/math.h b/nuttx/include/nuttx/math.h
index 84dbea6e0..160926d07 100644
--- a/nuttx/include/nuttx/math.h
+++ b/nuttx/include/nuttx/math.h
@@ -50,14 +50,272 @@
#ifdef CONFIG_ARCH_MATH_H
# include <arch/math.h>
-#endif
+
+/* If CONFIG_LIB is enabled, then the math library at lib/math will be
+ * built. This library was taken from the math library developed for the
+ * Rhombus OS by Nick Johnson (https://github.com/nickbjohnson4224/rhombus).
+ * The port or the Rhombus math library was contributed by Darcy Gong.
+ */
+
+#else if defined CONFIG_LIBM
/****************************************************************************
- * Type Definitions
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * 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 <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* General Constants ********************************************************/
+
+#define INFINITY (1.0/0.0)
+#define NAN (0.0/0.0)
+#define HUGE_VAL INFINITY
+
+#define isnan(x) ((x) != (x))
+#define isinf(x) (((x) == INFINITY) || ((x) == -INFINITY))
+
+/* Exponential and Logarithmic constants ************************************/
+
+#define M_E 2.7182818284590452353602874713526625
+#define M_SQRT2 1.4142135623730950488016887242096981
+#define M_SQRT1_2 0.7071067811865475244008443621048490
+#define M_LOG2E 1.4426950408889634073599246810018921
+#define M_LOG10E 0.4342944819032518276511289189166051
+#define M_LN2 0.6931471805599453094172321214581765
+#define M_LN10 2.3025850929940456840179914546843642
+
+/* Trigonometric Constants **************************************************/
+
+#define M_PI 3.1415926535897932384626433832795029
+#define M_PI_2 1.5707963267948966192313216916397514
+#define M_PI_4 0.7853981633974483096156608458198757
+#define M_1_PI 0.3183098861837906715377675267450287
+#define M_2_PI 0.6366197723675813430755350534900574
+#define M_2_SQRTPI 1.1283791670955125738961589031215452
+
+/****************************************************************************
* Public Function Prototypes
****************************************************************************/
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* General Functions ********************************************************/
+
+float ceilf (float x);
+#if CONFIG_HAVE_DOUBLE
+double ceil (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double ceill (long double x);
+#endif
+
+float floorf(float x);
+#if CONFIG_HAVE_DOUBLE
+double floor (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double floorl(long double x);
+#endif
+
+float fabsf (float x);
+#if CONFIG_HAVE_DOUBLE
+double fabs (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double fabsl (long double x);
+#endif
+
+float modff (float x, float *iptr);
+#if CONFIG_HAVE_DOUBLE
+double modf (double x, double *iptr);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double modfl (long double x, long double *iptr);
+#endif
+
+float fmodf (float x, float div);
+#if CONFIG_HAVE_DOUBLE
+double fmod (double x, double div);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double fmodl (long double x, long double div);
+#endif
+
+/* Exponential and Logarithmic Functions ************************************/
+
+float powf (float b, float e);
+#if CONFIG_HAVE_DOUBLE
+double pow (double b, double e);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double powl (long double b, long double e);
+#endif
+
+float expf (float x);
+#if CONFIG_HAVE_DOUBLE
+double exp (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double expl (long double x);
+#endif
+
+float logf (float x);
+#if CONFIG_HAVE_DOUBLE
+double log (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double logl (long double x);
+#endif
+
+float log10f(float x);
+#if CONFIG_HAVE_DOUBLE
+double log10 (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double log10l(long double x);
+#endif
+
+float log2f (float x);
+#if CONFIG_HAVE_DOUBLE
+double log2 (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double log2l (long double x);
+#endif
+
+float sqrtf (float x);
+#if CONFIG_HAVE_DOUBLE
+double sqrt (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double sqrtl (long double x);
+#endif
+
+float ldexpf(float x, int n);
+#if CONFIG_HAVE_DOUBLE
+double ldexp (double x, int n);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double ldexpl(long double x, int n);
+#endif
+
+float frexpf(float x, int *exp);
+#if CONFIG_HAVE_DOUBLE
+double frexp (double x, int *exp);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double frexpl(long double x, int *exp);
+#endif
+
+/* Trigonometric Functions **************************************************/
+
+float sinf (float x);
+#if CONFIG_HAVE_DOUBLE
+double sin (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double sinl (long double x);
+#endif
+
+float cosf (float x);
+#if CONFIG_HAVE_DOUBLE
+double cos (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double cosl (long double x);
+#endif
+
+float tanf (float x);
+#if CONFIG_HAVE_DOUBLE
+double tan (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double tanl (long double x);
+#endif
+
+float asinf (float x);
+#if CONFIG_HAVE_DOUBLE
+double asin (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double asinl (long double x);
+#endif
+
+float acosf (float x);
+#if CONFIG_HAVE_DOUBLE
+double acos (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double acosl (long double x);
+#endif
+
+float atanf (float x);
+#if CONFIG_HAVE_DOUBLE
+double atan (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double atanl (long double x);
+#endif
+
+float atan2f(float y, float x);
+#if CONFIG_HAVE_DOUBLE
+double atan2 (double y, double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double atan2l(long double y, long double x);
+#endif
+
+float sinhf (float x);
+#if CONFIG_HAVE_DOUBLE
+double sinh (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double sinhl (long double x);
+#endif
+
+float coshf (float x);
+#if CONFIG_HAVE_DOUBLE
+double cosh (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double coshl (long double x);
+#endif
+
+float tanhf (float x);
+#if CONFIG_HAVE_DOUBLE
+double tanh (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double tanhl (long double x);
+#endif
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* CONFIG_LIBM */
#endif /* __INCLUDE_NUTTX_MATH_H */