mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
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
This commit is contained in:
@@ -192,6 +192,28 @@ lib/string/lib_vikmemcpy.c
|
|||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
|
|
||||||
|
lib/math
|
||||||
|
^^^^^^^^
|
||||||
|
|
||||||
|
If you enable CONFIG_LIB, you will build the math library at lib/math.
|
||||||
|
This library was taken from the math library developed for the Rhombus
|
||||||
|
OS by Nick Johnson (https://github.com/nickbjohnson4224/rhombus). This
|
||||||
|
port was contributed by Darcy Gong. The Rhombus math library has this
|
||||||
|
compatible MIT license:
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
Documents/rss.gif
|
Documents/rss.gif
|
||||||
^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|||||||
@@ -3529,3 +3529,10 @@
|
|||||||
the math library from the Rhombus OS
|
the math library from the Rhombus OS
|
||||||
* lib/math: Now contains the math library from the Rhombus OS by Nick Johnson
|
* lib/math: Now contains the math library from the Rhombus OS by Nick Johnson
|
||||||
(submitted by Darcy Gong).
|
(submitted by Darcy Gong).
|
||||||
|
* include/float.h: Add a first cut at the float.h header file. This
|
||||||
|
really should be an architecture/toolchain-specific header file. It
|
||||||
|
is only used if CONFIG_ARCH_FLOAT_H is defined.
|
||||||
|
* lib/math: Files now conform to coding standards. Separated float,
|
||||||
|
double, and long double versions of code into separate files so that
|
||||||
|
they don't draw in so much un-necessary code when doing a dumb link.
|
||||||
|
|
||||||
|
|||||||
@@ -192,6 +192,17 @@ config ARCH_MATH_H
|
|||||||
that don't select ARCH_MATH_H, the redirecting math.h header file
|
that don't select ARCH_MATH_H, the redirecting math.h header file
|
||||||
will stay out-of-the-way in include/nuttx/.
|
will stay out-of-the-way in include/nuttx/.
|
||||||
|
|
||||||
|
config ARCH_FLOAT_H
|
||||||
|
bool "float.h"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
The float.h header file defines the properties of your floating
|
||||||
|
point implementation. It would always be best to use your
|
||||||
|
toolchain's float.h header file but if none is avaiable, a default
|
||||||
|
float.h header file will provided if this option is selected. However
|
||||||
|
there is no assurance that the settings in this float.h are actually
|
||||||
|
correct for your platform!
|
||||||
|
|
||||||
config ARCH_STDARG_H
|
config ARCH_STDARG_H
|
||||||
bool "stdarg.h"
|
bool "stdarg.h"
|
||||||
default n
|
default n
|
||||||
|
|||||||
@@ -263,15 +263,47 @@ all: $(BIN)
|
|||||||
# Target used to copy include/nuttx/math.h. If CONFIG_ARCH_MATH_H is
|
# Target used to copy include/nuttx/math.h. If CONFIG_ARCH_MATH_H is
|
||||||
# defined, then there is an architecture specific math.h header file
|
# defined, then there is an architecture specific math.h header file
|
||||||
# that will be included indirectly from include/math.h. But first, we
|
# that will be included indirectly from include/math.h. But first, we
|
||||||
# have to copy math.h from include/nuttx/. to include/.
|
# have to copy math.h from include/nuttx/. to include/. Logic within
|
||||||
|
# include/nuttx/math.h will hand the redirection to the architecture-
|
||||||
|
# specific math.h header file.
|
||||||
|
#
|
||||||
|
# If the CONFIG_LIBM is defined, the Rhombus libm will be built at lib/math.
|
||||||
|
# Definitions and prototypes for the Rhombus libm are also contained in
|
||||||
|
# include/nuttx/math.h and so the file must also be copied in that case.
|
||||||
|
#
|
||||||
|
# If neither CONFIG_ARCH_MATH_H nor CONFIG_LIBM is defined, then no math.h
|
||||||
|
# header file will be provided. You would want that behavior if (1) you
|
||||||
|
# don't use libm, or (2) you want to use the math.h and libm provided
|
||||||
|
# within your toolchain.
|
||||||
|
|
||||||
ifeq ($(CONFIG_ARCH_MATH_H),y)
|
ifeq ($(CONFIG_ARCH_MATH_H),y)
|
||||||
|
NEED_MATH_H = y
|
||||||
|
else
|
||||||
|
ifeq ($(CONFIG_LIBM),y)
|
||||||
|
NEED_MATH_H = y
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(NEED_MATH_H),y)
|
||||||
include/math.h: include/nuttx/math.h
|
include/math.h: include/nuttx/math.h
|
||||||
@cp -f include/nuttx/math.h include/math.h
|
@cp -f include/nuttx/math.h include/math.h
|
||||||
else
|
else
|
||||||
include/math.h:
|
include/math.h:
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# The float.h header file defines the properties of your floating point
|
||||||
|
# implementation. It would always be best to use your toolchain's float.h
|
||||||
|
# header file but if none is avaiable, a default float.h header file will
|
||||||
|
# provided if this option is selected. However there is no assurance that
|
||||||
|
# the settings in this float.h are actually correct for your platform!
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ARCH_FLOAT_H),y)
|
||||||
|
include/float.h: include/nuttx/float.h
|
||||||
|
@cp -f include/nuttx/float.h include/float.h
|
||||||
|
else
|
||||||
|
include/float.h:
|
||||||
|
endif
|
||||||
|
|
||||||
# Target used to copy include/nuttx/stdarg.h. If CONFIG_ARCH_STDARG_H is
|
# Target used to copy include/nuttx/stdarg.h. If CONFIG_ARCH_STDARG_H is
|
||||||
# defined, then there is an architecture specific stdarg.h header file
|
# defined, then there is an architecture specific stdarg.h header file
|
||||||
# that will be included indirectly from include/stdarg.h. But first, we
|
# that will be included indirectly from include/stdarg.h. But first, we
|
||||||
@@ -364,7 +396,7 @@ dirlinks: include/arch include/arch/board include/arch/chip $(ARCH_SRC)/board $(
|
|||||||
# the config.h and version.h header files in the include/nuttx directory and
|
# the config.h and version.h header files in the include/nuttx directory and
|
||||||
# the establishment of symbolic links to configured directories.
|
# the establishment of symbolic links to configured directories.
|
||||||
|
|
||||||
context: check_context include/nuttx/config.h include/nuttx/version.h include/math.h include/stdarg.h dirlinks
|
context: check_context include/nuttx/config.h include/nuttx/version.h include/math.h include/float.h include/stdarg.h dirlinks
|
||||||
@for dir in $(CONTEXTDIRS) ; do \
|
@for dir in $(CONTEXTDIRS) ; do \
|
||||||
$(MAKE) -C $$dir TOPDIR="$(TOPDIR)" context; \
|
$(MAKE) -C $$dir TOPDIR="$(TOPDIR)" context; \
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -196,8 +196,9 @@
|
|||||||
|
|
||||||
/* GCC supports both types double and long long */
|
/* GCC supports both types double and long long */
|
||||||
|
|
||||||
# define CONFIG_HAVE_DOUBLE 1
|
|
||||||
# define CONFIG_HAVE_LONG_LONG 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 */
|
/* Structures and unions can be assigned and passed as values */
|
||||||
|
|
||||||
@@ -301,6 +302,7 @@
|
|||||||
|
|
||||||
# undef CONFIG_HAVE_LONG_LONG
|
# undef CONFIG_HAVE_LONG_LONG
|
||||||
# undef CONFIG_HAVE_DOUBLE
|
# undef CONFIG_HAVE_DOUBLE
|
||||||
|
# undef CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
|
||||||
/* Structures and unions cannot be passed as values or used
|
/* Structures and unions cannot be passed as values or used
|
||||||
* in assignments.
|
* in assignments.
|
||||||
@@ -403,8 +405,9 @@
|
|||||||
* simply do not support long long or double.
|
* simply do not support long long or double.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
# undef CONFIG_HAVE_DOUBLE
|
|
||||||
# undef CONFIG_HAVE_LONG_LONG
|
# undef CONFIG_HAVE_LONG_LONG
|
||||||
|
# undef CONFIG_HAVE_DOUBLE
|
||||||
|
# undef CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
|
||||||
/* Structures and unions can be assigned and passed as values */
|
/* Structures and unions can be assigned and passed as values */
|
||||||
|
|
||||||
@@ -441,6 +444,7 @@
|
|||||||
# define inline
|
# define inline
|
||||||
# undef CONFIG_HAVE_LONG_LONG
|
# undef CONFIG_HAVE_LONG_LONG
|
||||||
# undef CONFIG_HAVE_DOUBLE
|
# undef CONFIG_HAVE_DOUBLE
|
||||||
|
# undef CONFIG_HAVE_LONG_DOUBLE
|
||||||
# undef CONFIG_CAN_PASS_STRUCTS
|
# undef CONFIG_CAN_PASS_STRUCTS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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 */
|
||||||
+260
-2
@@ -50,14 +50,272 @@
|
|||||||
|
|
||||||
#ifdef CONFIG_ARCH_MATH_H
|
#ifdef CONFIG_ARCH_MATH_H
|
||||||
# include <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
|
* 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 */
|
#endif /* __INCLUDE_NUTTX_MATH_H */
|
||||||
|
|||||||
+1
-21
@@ -30,27 +30,7 @@ config LIB_HOMEDIR
|
|||||||
---help---
|
---help---
|
||||||
The home directory to use with operations like such as 'cd ~'
|
The home directory to use with operations like such as 'cd ~'
|
||||||
|
|
||||||
config LIBM
|
source lib/math/Kconfig
|
||||||
bool "Math library"
|
|
||||||
default n
|
|
||||||
depends on !ARCH_MATH_H
|
|
||||||
---help---
|
|
||||||
By default, no math library will be provided by NuttX. In this this case, it
|
|
||||||
is assumed that (1) no math library is required, or (2) you will be using the
|
|
||||||
math.h header file and the libm library provided by your toolchain.
|
|
||||||
|
|
||||||
This is may be a very good choice is possible because your toolchain may have
|
|
||||||
have a highly optimized version of libm.
|
|
||||||
|
|
||||||
Another possibility is that you have a custom, architecture-specific math
|
|
||||||
libary and that the corresponding math.h file resides at arch/<architecture>/include/math.h.
|
|
||||||
The option is selected via ARCH_MATH_H. If ARCH_MATH_H is selected,then the include/nuttx/math.h
|
|
||||||
header file will be copied to include/math.h where it can be used by your applications.
|
|
||||||
|
|
||||||
If ARCH_MATH_H is not defined, then this option can be selected to build a generic,
|
|
||||||
math library built into NuttX. This math library comes from the Rhombus OS and
|
|
||||||
was written by Nick Johnson. The Rhombus OS math library port was contributed by
|
|
||||||
Darcy Gong.
|
|
||||||
|
|
||||||
config NOPRINTF_FIELDWIDTH
|
config NOPRINTF_FIELDWIDTH
|
||||||
bool "Disable sprintf support fieldwidth"
|
bool "Disable sprintf support fieldwidth"
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ include pthread/Make.defs
|
|||||||
include semaphore/Make.defs
|
include semaphore/Make.defs
|
||||||
include signal/Make.defs
|
include signal/Make.defs
|
||||||
include mqueue/Make.defs
|
include mqueue/Make.defs
|
||||||
|
include math/Make.defs
|
||||||
include fixedmath/Make.defs
|
include fixedmath/Make.defs
|
||||||
include net/Make.defs
|
include net/Make.defs
|
||||||
include time/Make.defs
|
include time/Make.defs
|
||||||
|
|||||||
+32
-20
@@ -117,56 +117,56 @@ extern bool g_dbgenable;
|
|||||||
/* Defined in lib_streamsem.c */
|
/* Defined in lib_streamsem.c */
|
||||||
|
|
||||||
#if CONFIG_NFILE_STREAMS > 0
|
#if CONFIG_NFILE_STREAMS > 0
|
||||||
extern void stream_semtake(FAR struct streamlist *list);
|
void stream_semtake(FAR struct streamlist *list);
|
||||||
extern void stream_semgive(FAR struct streamlist *list);
|
void stream_semgive(FAR struct streamlist *list);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Defined in lib_libnoflush.c */
|
/* Defined in lib_libnoflush.c */
|
||||||
|
|
||||||
#ifdef CONFIG_STDIO_LINEBUFFER
|
#ifdef CONFIG_STDIO_LINEBUFFER
|
||||||
extern int lib_noflush(FAR struct lib_outstream_s *this);
|
int lib_noflush(FAR struct lib_outstream_s *this);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Defined in lib_libsprintf.c */
|
/* Defined in lib_libsprintf.c */
|
||||||
|
|
||||||
extern int lib_sprintf(FAR struct lib_outstream_s *obj,
|
int lib_sprintf(FAR struct lib_outstream_s *obj,
|
||||||
const char *fmt, ...);
|
const char *fmt, ...);
|
||||||
|
|
||||||
/* Defined lib_libvsprintf.c */
|
/* Defined lib_libvsprintf.c */
|
||||||
|
|
||||||
extern int lib_vsprintf(FAR struct lib_outstream_s *obj,
|
int lib_vsprintf(FAR struct lib_outstream_s *obj,
|
||||||
FAR const char *src, va_list ap);
|
FAR const char *src, va_list ap);
|
||||||
|
|
||||||
/* Defined lib_rawprintf.c */
|
/* Defined lib_rawprintf.c */
|
||||||
|
|
||||||
extern int lib_rawvprintf(const char *src, va_list ap);
|
int lib_rawvprintf(const char *src, va_list ap);
|
||||||
|
|
||||||
/* Defined lib_lowprintf.c */
|
/* Defined lib_lowprintf.c */
|
||||||
|
|
||||||
extern int lib_lowvprintf(const char *src, va_list ap);
|
int lib_lowvprintf(const char *src, va_list ap);
|
||||||
|
|
||||||
/* Defined in lib_dtoa.c */
|
/* Defined in lib_dtoa.c */
|
||||||
|
|
||||||
#ifdef CONFIG_LIBC_FLOATINGPOINT
|
#ifdef CONFIG_LIBC_FLOATINGPOINT
|
||||||
extern char *__dtoa(double d, int mode, int ndigits,
|
char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign,
|
||||||
int *decpt, int *sign, char **rve);
|
char **rve);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Defined in lib_libwrite.c */
|
/* Defined in lib_libwrite.c */
|
||||||
|
|
||||||
extern ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream);
|
ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream);
|
||||||
|
|
||||||
/* Defined in lib_libfread.c */
|
/* Defined in lib_libfread.c */
|
||||||
|
|
||||||
extern ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream);
|
ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream);
|
||||||
|
|
||||||
/* Defined in lib_libfflush.c */
|
/* Defined in lib_libfflush.c */
|
||||||
|
|
||||||
extern ssize_t lib_fflush(FAR FILE *stream, bool bforce);
|
ssize_t lib_fflush(FAR FILE *stream, bool bforce);
|
||||||
|
|
||||||
/* Defined in lib_rdflush.c */
|
/* Defined in lib_rdflush.c */
|
||||||
|
|
||||||
extern int lib_rdflush(FAR FILE *stream);
|
int lib_rdflush(FAR FILE *stream);
|
||||||
|
|
||||||
/* Defined in lib_wrflush.c */
|
/* Defined in lib_wrflush.c */
|
||||||
|
|
||||||
@@ -175,25 +175,37 @@ int lib_wrflush(FAR FILE *stream);
|
|||||||
/* Defined in lib_sem.c */
|
/* Defined in lib_sem.c */
|
||||||
|
|
||||||
#if CONFIG_STDIO_BUFFER_SIZE > 0
|
#if CONFIG_STDIO_BUFFER_SIZE > 0
|
||||||
extern void lib_sem_initialize(FAR struct file_struct *stream);
|
void lib_sem_initialize(FAR struct file_struct *stream);
|
||||||
extern void lib_take_semaphore(FAR struct file_struct *stream);
|
void lib_take_semaphore(FAR struct file_struct *stream);
|
||||||
extern void lib_give_semaphore(FAR struct file_struct *stream);
|
void lib_give_semaphore(FAR struct file_struct *stream);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Defined in lib_libgetbase.c */
|
/* Defined in lib_libgetbase.c */
|
||||||
|
|
||||||
extern int lib_getbase(const char *nptr, const char **endptr);
|
int lib_getbase(const char *nptr, const char **endptr);
|
||||||
|
|
||||||
/* Defined in lib_skipspace.c */
|
/* Defined in lib_skipspace.c */
|
||||||
|
|
||||||
extern void lib_skipspace(const char **pptr);
|
void lib_skipspace(const char **pptr);
|
||||||
|
|
||||||
/* Defined in lib_isbasedigit.c */
|
/* Defined in lib_isbasedigit.c */
|
||||||
|
|
||||||
extern bool lib_isbasedigit(int ch, int base, int *value);
|
bool lib_isbasedigit(int ch, int base, int *value);
|
||||||
|
|
||||||
/* Defined in lib_checkbase.c */
|
/* Defined in lib_checkbase.c */
|
||||||
|
|
||||||
extern int lib_checkbase(int base, const char **pptr);
|
int lib_checkbase(int base, const char **pptr);
|
||||||
|
|
||||||
|
/* Defined in lib_expi.c */
|
||||||
|
|
||||||
|
#ifdef CONFIG_LIBM
|
||||||
|
double lib_expi(size_t n);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Defined in lib_libsqrtapprox.c */
|
||||||
|
|
||||||
|
#ifdef CONFIG_LIBM
|
||||||
|
float lib_sqrtapprox(float x);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __LIB_LIB_INTERNAL_H */
|
#endif /* __LIB_LIB_INTERNAL_H */
|
||||||
|
|||||||
@@ -2,3 +2,25 @@
|
|||||||
# For a description of the syntax of this configuration file,
|
# For a description of the syntax of this configuration file,
|
||||||
# see misc/tools/kconfig-language.txt.
|
# see misc/tools/kconfig-language.txt.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
config LIBM
|
||||||
|
bool "Math library"
|
||||||
|
default n
|
||||||
|
depends on !ARCH_MATH_H
|
||||||
|
---help---
|
||||||
|
By default, no math library will be provided by NuttX. In this this case, it
|
||||||
|
is assumed that (1) no math library is required, or (2) you will be using the
|
||||||
|
math.h header file and the libm library provided by your toolchain.
|
||||||
|
|
||||||
|
This is may be a very good choice is possible because your toolchain may have
|
||||||
|
have a highly optimized version of libm.
|
||||||
|
|
||||||
|
Another possibility is that you have a custom, architecture-specific math
|
||||||
|
libary and that the corresponding math.h file resides at arch/<architecture>/include/math.h.
|
||||||
|
The option is selected via ARCH_MATH_H. If ARCH_MATH_H is selected,then the include/nuttx/math.h
|
||||||
|
header file will be copied to include/math.h where it can be used by your applications.
|
||||||
|
|
||||||
|
If ARCH_MATH_H is not defined, then this option can be selected to build a generic,
|
||||||
|
math library built into NuttX. This math library comes from the Rhombus OS and
|
||||||
|
was written by Nick Johnson. The Rhombus OS math library port was contributed by
|
||||||
|
Darcy Gong.
|
||||||
|
|||||||
+14
-1
@@ -33,17 +33,30 @@
|
|||||||
#
|
#
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
if ($(CONFIG_LIBM),y)
|
ifeq ($(CONFIG_LIBM),y)
|
||||||
|
|
||||||
# Add the floating point math C files to the build
|
# Add the floating point math C files to the build
|
||||||
|
|
||||||
|
CSRCS += lib_acosf.c lib_asinf.c lib_atan2f.c lib_atanf.c lib_ceilf.c lib_cosf.c
|
||||||
|
CSRCS += lib_coshf.c lib_expf.c lib_fabsf.c lib_floorf.c lib_fmodf.c lib_frexpf.c
|
||||||
|
CSRCS += lib_ldexpf.c lib_logf.c lib_log10f.c lib_log2f.c lib_modff.c lib_powf.c
|
||||||
|
CSRCS += lib_sinf.c lib_sinhf.c lib_sqrtf.c lib_tanf.c lib_tanhf.c
|
||||||
|
|
||||||
CSRCS += lib_acos.c lib_asin.c lib_atan.c lib_atan2.c lib_ceil.c lib_cos.c
|
CSRCS += lib_acos.c lib_asin.c lib_atan.c lib_atan2.c lib_ceil.c lib_cos.c
|
||||||
CSRCS += lib_cosh.c lib_exp.c lib_fabs.c lib_floor.c lib_fmod.c lib_frexp.c
|
CSRCS += lib_cosh.c lib_exp.c lib_fabs.c lib_floor.c lib_fmod.c lib_frexp.c
|
||||||
CRRCS += lib_ldexp.c lib_log.c lib_log10.c lib_log2.c lib_modf.c lib_pow.c
|
CRRCS += lib_ldexp.c lib_log.c lib_log10.c lib_log2.c lib_modf.c lib_pow.c
|
||||||
CSRCS += lib_sin.c lib_sinh.c lib_sqrt.c lib_tan.c lib_tanh.c
|
CSRCS += lib_sin.c lib_sinh.c lib_sqrt.c lib_tan.c lib_tanh.c
|
||||||
|
|
||||||
|
CSRCS += lib_acosl.c lib_asinl.c lib_atan2l.c lib_atanl.c lib_ceill.c lib_cosl.c
|
||||||
|
CSRCS += lib_coshl.c lib_expl.c lib_fabsl.c lib_floorl.c lib_fmodl.c lib_frexpl.c
|
||||||
|
CSRCS += lib_ldexpl.c lib_logl.c lib_log10l.c lib_log2l.c lib_modfl.c lib_powl.c
|
||||||
|
CSRCS += lib_sinl.c lib_sinhl.c lib_sqrtl.c lib_tanl.c lib_tanhl.c
|
||||||
|
|
||||||
|
CSRCS += lib_libexpi.c lib_libsqrtapprox.c
|
||||||
|
|
||||||
# Add the floating point math directory to the build
|
# Add the floating point math directory to the build
|
||||||
|
|
||||||
DEPPATH += --dep-path math
|
DEPPATH += --dep-path math
|
||||||
VPATH += :math
|
VPATH += :math
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
############################################################################
|
|
||||||
# nuttx/lib/math/Makefile
|
|
||||||
#
|
|
||||||
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
|
||||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
#
|
|
||||||
############################################################################
|
|
||||||
|
|
||||||
-include $(TOPDIR)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# NSH Library
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS =
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_MATHEXT_LIBRARY),y)
|
|
||||||
CSRCS += m_cos.c m_log2.c m_fmod.c m_sin.c m_fabs.c m_exp.c m_asin.c m_tan.c \
|
|
||||||
m_modf.c m_ldexp.c m_acos.c m_frexp.c m_atan.c m_log.c m_tanh.c m_ceil.c \
|
|
||||||
m_sinh.c m_sqrt.c m_pow.c m_cosh.c m_floor.c m_atan2.c m_log10.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
|
|
||||||
else
|
|
||||||
BIN = "$(APPDIR)/libapps$(LIBEXT)"
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
# Build targets
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: context .depend depend clean distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
@( for obj in $(OBJS) ; do \
|
|
||||||
$(call ARCHIVE, $(BIN), $${obj}); \
|
|
||||||
done ; )
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
context:
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) \
|
|
||||||
$(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@rm -f *.o *~ .*.swp .built
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
@rm -f Make.dep .depend
|
|
||||||
|
|
||||||
-include Make.dep
|
|
||||||
|
|
||||||
+28
-12
@@ -1,4 +1,14 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
|
* lib/math/lib_acos.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, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
|
* Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -12,19 +22,25 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
float acosf(float x) {
|
#include <nuttx/config.h>
|
||||||
return (M_PI_2 - asinf(x));
|
#include <nuttx/compiler.h>
|
||||||
}
|
|
||||||
|
|
||||||
double acos(double x) {
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_DOUBLE
|
||||||
|
double acos(double x)
|
||||||
|
{
|
||||||
return (M_PI_2 - asin(x));
|
return (M_PI_2 - asin(x));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
long double acosl(long double x) {
|
|
||||||
return (M_PI_2 - asinl(x));
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_acosf.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, 2010 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 <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
float acosf(float x)
|
||||||
|
{
|
||||||
|
return (M_PI_2 - asinf(x));
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_acos.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, 2010 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>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
long double acosl(long double x)
|
||||||
|
{
|
||||||
|
return (M_PI_2 - asinl(x));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+35
-54
@@ -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>
|
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -12,48 +22,42 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/compiler.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
|
||||||
float asinf(float x) {
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_DOUBLE
|
||||||
|
double asin(double x)
|
||||||
|
{
|
||||||
long double y, y_sin, y_cos;
|
long double y, y_sin, y_cos;
|
||||||
|
|
||||||
y = 0;
|
y = 0;
|
||||||
|
|
||||||
while (1) {
|
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_sin = sin(y);
|
||||||
y_cos = cos(y);
|
y_cos = cos(y);
|
||||||
|
|
||||||
if (y > M_PI_2 || y < -M_PI_2) {
|
if (y > M_PI_2 || y < -M_PI_2)
|
||||||
|
{
|
||||||
y = fmod(y, M_PI);
|
y = fmod(y, M_PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y_sin + DBL_EPSILON >= x && y_sin - DBL_EPSILON <= x) {
|
if (y_sin + DBL_EPSILON >= x && y_sin - DBL_EPSILON <= x)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,27 +66,4 @@ double asin(double x) {
|
|||||||
|
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
long double asinl(long double x) {
|
|
||||||
long double y, y_sin, y_cos;
|
|
||||||
|
|
||||||
y = 0;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
y_sin = sinl(y);
|
|
||||||
y_cos = cosl(y);
|
|
||||||
|
|
||||||
if (y > M_PI_2 || y < -M_PI_2) {
|
|
||||||
y = fmodl(y, M_PI);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y_sin + LDBL_EPSILON >= x && y_sin - LDBL_EPSILON <= x) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
y = y - (y_sin - x) / y_cos;
|
|
||||||
}
|
|
||||||
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_sinf.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
|
||||||
|
* 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 <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
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 + FLT_EPSILON >= x && y_sin - FLT_EPSILON <= x)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
y = y - (y_sin - x) / y_cos;
|
||||||
|
}
|
||||||
|
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_sinl.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
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
long double asinl(long double x)
|
||||||
|
{
|
||||||
|
long double y, y_sin, y_cos;
|
||||||
|
|
||||||
|
y = 0;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
y_sin = sinl(y);
|
||||||
|
y_cos = cosl(y);
|
||||||
|
|
||||||
|
if (y > M_PI_2 || y < -M_PI_2)
|
||||||
|
{
|
||||||
|
y = fmodl(y, M_PI);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y_sin + LDBL_EPSILON >= x && y_sin - LDBL_EPSILON <= x)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
y = y - (y_sin - x) / y_cos;
|
||||||
|
}
|
||||||
|
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+29
-13
@@ -1,5 +1,15 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
|
* lib/math/lib_atan.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, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -12,21 +22,27 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/compiler.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
float atanf(float x) {
|
/************************************************************************
|
||||||
return asinf(x / sqrtf(x * x + 1));
|
* Public Functions
|
||||||
}
|
************************************************************************/
|
||||||
|
|
||||||
double atan(double x) {
|
#if CONFIG_HAVE_DOUBLE
|
||||||
|
double atan(double x)
|
||||||
|
{
|
||||||
return asin(x / sqrt(x * x + 1));
|
return asin(x / sqrt(x * x + 1));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
long double atanl(long double x) {
|
|
||||||
return asinl(x / sqrtl(x * x + 1));
|
|
||||||
}
|
|
||||||
|
|||||||
+51
-85
@@ -1,5 +1,15 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
* Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
|
* lib/math/lib_atan2.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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -12,109 +22,65 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
float atan2f(float y, float x) {
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/compiler.h>
|
||||||
|
|
||||||
if (y == 0.0) {
|
#include <math.h>
|
||||||
if (x >= 0.0) {
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_DOUBLE
|
||||||
|
double atan2(double y, double x)
|
||||||
|
{
|
||||||
|
if (y == 0.0)
|
||||||
|
{
|
||||||
|
if (x >= 0.0)
|
||||||
|
{
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return M_PI;
|
return M_PI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (y > 0.0) {
|
else if (y > 0.0)
|
||||||
if (x == 0.0) {
|
{
|
||||||
|
if (x == 0.0)
|
||||||
|
{
|
||||||
return M_PI_2;
|
return M_PI_2;
|
||||||
}
|
}
|
||||||
else if (x > 0.0) {
|
else if (x > 0.0)
|
||||||
return atanf(y / x);
|
{
|
||||||
}
|
|
||||||
else {
|
|
||||||
return M_PI - atanf(y / x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (x == 0.0) {
|
|
||||||
return M_PI + M_PI_2;
|
|
||||||
}
|
|
||||||
else if (x > 0.0) {
|
|
||||||
return 2 * M_PI - atanf(y / x);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return M_PI + atanf(y / x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double atan2(double y, double x) {
|
|
||||||
|
|
||||||
if (y == 0.0) {
|
|
||||||
if (x >= 0.0) {
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return M_PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (y > 0.0) {
|
|
||||||
if (x == 0.0) {
|
|
||||||
return M_PI_2;
|
|
||||||
}
|
|
||||||
else if (x > 0.0) {
|
|
||||||
return atan(y / x);
|
return atan(y / x);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return M_PI - atan(y / x);
|
return M_PI - atan(y / x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if (x == 0.0) {
|
{
|
||||||
|
if (x == 0.0)
|
||||||
|
{
|
||||||
return M_PI + M_PI_2;
|
return M_PI + M_PI_2;
|
||||||
}
|
}
|
||||||
else if (x > 0.0) {
|
else if (x > 0.0)
|
||||||
|
{
|
||||||
return 2 * M_PI - atan(y / x);
|
return 2 * M_PI - atan(y / x);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return M_PI + atan(y / x);
|
return M_PI + atan(y / x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
long double atan2l(long double y, long double x) {
|
|
||||||
|
|
||||||
if (y == 0.0) {
|
|
||||||
if (x >= 0.0) {
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return M_PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (y > 0.0) {
|
|
||||||
if (x == 0.0) {
|
|
||||||
return M_PI_2;
|
|
||||||
}
|
|
||||||
else if (x > 0.0) {
|
|
||||||
return atanl(y / x);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return M_PI - atanl(y / x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (x == 0.0) {
|
|
||||||
return M_PI + M_PI_2;
|
|
||||||
}
|
|
||||||
else if (x > 0.0) {
|
|
||||||
return 2 * M_PI - atanl(y / x);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return M_PI + atanl(y / x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_atan2f.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
|
||||||
|
* 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 <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
float atan2f(float y, float x)
|
||||||
|
{
|
||||||
|
if (y == 0.0)
|
||||||
|
{
|
||||||
|
if (x >= 0.0)
|
||||||
|
{
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return M_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (y > 0.0)
|
||||||
|
{
|
||||||
|
if (x == 0.0)
|
||||||
|
{
|
||||||
|
return M_PI_2;
|
||||||
|
}
|
||||||
|
else if (x > 0.0)
|
||||||
|
{
|
||||||
|
return atanf(y / x);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return M_PI - atanf(y / x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (x == 0.0)
|
||||||
|
{
|
||||||
|
return M_PI + M_PI_2;
|
||||||
|
}
|
||||||
|
else if (x > 0.0)
|
||||||
|
{
|
||||||
|
return 2 * M_PI - atanf(y / x);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return M_PI + atanf(y / x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_atan2l.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
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
long double atan2l(long double y, long double x)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (y == 0.0)
|
||||||
|
{
|
||||||
|
if (x >= 0.0)
|
||||||
|
{
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return M_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (y > 0.0)
|
||||||
|
{
|
||||||
|
if (x == 0.0)
|
||||||
|
{
|
||||||
|
return M_PI_2;
|
||||||
|
}
|
||||||
|
else if (x > 0.0)
|
||||||
|
{
|
||||||
|
return atanl(y / x);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return M_PI - atanl(y / x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (x == 0.0)
|
||||||
|
{
|
||||||
|
return M_PI + M_PI_2;
|
||||||
|
}
|
||||||
|
else if (x > 0.0)
|
||||||
|
{
|
||||||
|
return 2 * M_PI - atanl(y / x);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return M_PI + atanl(y / x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_atanf.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, 2010 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 <math.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
float atanf(float x)
|
||||||
|
{
|
||||||
|
return asinf(x / sqrtf(x * x + 1));
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_atanl.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, 2010 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>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
long double atanl(long double x)
|
||||||
|
{
|
||||||
|
return asinl(x / sqrtl(x * x + 1));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+31
-16
@@ -1,4 +1,14 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
|
* lib/math/lib_ceil.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>
|
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -12,26 +22,31 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
float ceilf(float x) {
|
#include <nuttx/config.h>
|
||||||
modff(x, &x);
|
#include <nuttx/compiler.h>
|
||||||
if (x > 0.0) x += 1.0;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
double ceil(double x) {
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_DOUBLE
|
||||||
|
double ceil(double x)
|
||||||
|
{
|
||||||
modf(x, &x);
|
modf(x, &x);
|
||||||
if (x > 0.0) x += 1.0;
|
if (x > 0.0)
|
||||||
return x;
|
{
|
||||||
|
x += 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long double ceill(long double x) {
|
|
||||||
modfl(x, &x);
|
|
||||||
if (x > 0.0) x += 1.0;
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_ceilf.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
|
||||||
|
* 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 <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
float ceilf(float x)
|
||||||
|
{
|
||||||
|
modff(x, &x);
|
||||||
|
if (x > 0.0)
|
||||||
|
{
|
||||||
|
x += 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_ceil;.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
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
long double ceill(long double x)
|
||||||
|
{
|
||||||
|
modfl(x, &x);
|
||||||
|
if (x > 0.0)
|
||||||
|
{
|
||||||
|
x += 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+29
-14
@@ -1,5 +1,15 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
* Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
|
* lib/math/lib_cos.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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -12,20 +22,25 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <stdint.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
#include <apps/math.h>
|
************************************************************************/
|
||||||
|
|
||||||
float cosf(float x) {
|
#include <nuttx/config.h>
|
||||||
return sinf(x + M_PI_2);
|
#include <nuttx/compiler.h>
|
||||||
}
|
|
||||||
|
|
||||||
double cos(double x) {
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_DOUBLE
|
||||||
|
double cos(double x)
|
||||||
|
{
|
||||||
return sin(x + M_PI_2);
|
return sin(x + M_PI_2);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
long double cosl(long double x) {
|
|
||||||
return sinl(x + M_PI_2);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_cosf.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
|
||||||
|
* 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 <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
float cosf(float x)
|
||||||
|
{
|
||||||
|
return sinf(x + M_PI_2);
|
||||||
|
}
|
||||||
+29
-15
@@ -1,5 +1,15 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
* Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
|
* lib/math/lib_cosh.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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -12,22 +22,26 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
float coshf(float x) {
|
#include <nuttx/config.h>
|
||||||
x = expf(x);
|
#include <nuttx/compiler.h>
|
||||||
return ((x + (1.0 / x)) / 2.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
double cosh(double x) {
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_DOUBLE
|
||||||
|
double cosh(double x)
|
||||||
|
{
|
||||||
x = exp(x);
|
x = exp(x);
|
||||||
return ((x + (1.0 / x)) / 2.0);
|
return ((x + (1.0 / x)) / 2.0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
long double coshl(long double x) {
|
|
||||||
x = expl(x);
|
|
||||||
return ((x + (1.0 / x)) / 2.0);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_coshf.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
|
||||||
|
* 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 <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
float coshf(float x)
|
||||||
|
{
|
||||||
|
x = expf(x);
|
||||||
|
return ((x + (1.0 / x)) / 2.0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_coshl.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
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
long double coshl(long double x)
|
||||||
|
{
|
||||||
|
x = expl(x);
|
||||||
|
return ((x + (1.0 / x)) / 2.0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_cosl.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
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
long double cosl(long double x)
|
||||||
|
{
|
||||||
|
return sinl(x + M_PI_2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+54
-182
@@ -1,4 +1,14 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
|
* lib/math/lib_exp.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>
|
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -12,117 +22,28 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
#include <stdint.h>
|
************************************************************************/
|
||||||
#include <stdbool.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#define M_E2 (M_E * M_E)
|
#include <nuttx/config.h>
|
||||||
#define M_E4 (M_E2 * M_E2)
|
#include <nuttx/compiler.h>
|
||||||
#define M_E8 (M_E4 * M_E4)
|
|
||||||
#define M_E16 (M_E8 * M_E8)
|
|
||||||
#define M_E32 (M_E16 * M_E16)
|
|
||||||
#define M_E64 (M_E32 * M_E32)
|
|
||||||
#define M_E128 (M_E64 * M_E64)
|
|
||||||
#define M_E256 (M_E128 * M_E128)
|
|
||||||
#define M_E512 (M_E256 * M_E256)
|
|
||||||
#define M_E1024 (M_E512 * M_E512)
|
|
||||||
|
|
||||||
static double _expi_square_tbl[11] = {
|
#include <math.h>
|
||||||
M_E, // e^1
|
|
||||||
M_E2, // e^2
|
|
||||||
M_E4, // e^4
|
|
||||||
M_E8, // e^8
|
|
||||||
M_E16, // e^16
|
|
||||||
M_E32, // e^32
|
|
||||||
M_E64, // e^64
|
|
||||||
M_E128, // e^128
|
|
||||||
M_E256, // e^256
|
|
||||||
M_E512, // e^512
|
|
||||||
M_E1024, // e^1024
|
|
||||||
};
|
|
||||||
|
|
||||||
static double _expi(size_t n) {
|
#include "lib_internal.h"
|
||||||
size_t i;
|
|
||||||
double val;
|
|
||||||
|
|
||||||
if (n > 1024) {
|
#if CONFIG_HAVE_DOUBLE
|
||||||
return INFINITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
val = 1.0;
|
/************************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
for (i = 0; n; i++) {
|
static double _dbl_inv_fact[] =
|
||||||
if (n & (1 << i)) {
|
{
|
||||||
n &= ~(1 << i);
|
|
||||||
val *= _expi_square_tbl[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
static float _flt_inv_fact[] = {
|
|
||||||
1.0 / 1.0, // 1/0!
|
|
||||||
1.0 / 1.0, // 1/1!
|
|
||||||
1.0 / 2.0, // 1/2!
|
|
||||||
1.0 / 6.0, // 1/3!
|
|
||||||
1.0 / 24.0, // 1/4!
|
|
||||||
1.0 / 120.0, // 1/5!
|
|
||||||
1.0 / 720.0, // 1/6!
|
|
||||||
1.0 / 5040.0, // 1/7!
|
|
||||||
1.0 / 40320.0, // 1/8!
|
|
||||||
1.0 / 362880.0, // 1/9!
|
|
||||||
1.0 / 3628800.0, // 1/10!
|
|
||||||
};
|
|
||||||
|
|
||||||
float expf(float x) {
|
|
||||||
size_t int_part;
|
|
||||||
bool invert;
|
|
||||||
float value;
|
|
||||||
float x0;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (x == 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (x < 0) {
|
|
||||||
invert = true;
|
|
||||||
x = -x;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
invert = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* extract integer component */
|
|
||||||
int_part = (size_t) x;
|
|
||||||
|
|
||||||
/* set x to fractional component */
|
|
||||||
x -= (float) int_part;
|
|
||||||
|
|
||||||
/* perform Taylor series approximation with eleven terms */
|
|
||||||
value = 0.0;
|
|
||||||
x0 = 1.0;
|
|
||||||
for (i = 0; i < 10; i++) {
|
|
||||||
value += x0 * _flt_inv_fact[i];
|
|
||||||
x0 *= x;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* multiply by exp of the integer component */
|
|
||||||
value *= _expi(int_part);
|
|
||||||
|
|
||||||
if (invert) {
|
|
||||||
return (1.0 / value);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static double _dbl_inv_fact[] = {
|
|
||||||
1.0 / 1.0, // 1 / 0!
|
1.0 / 1.0, // 1 / 0!
|
||||||
1.0 / 1.0, // 1 / 1!
|
1.0 / 1.0, // 1 / 1!
|
||||||
1.0 / 2.0, // 1 / 2!
|
1.0 / 2.0, // 1 / 2!
|
||||||
@@ -144,110 +65,61 @@ static double _dbl_inv_fact[] = {
|
|||||||
1.0 / 6402373705728000.0, // 1 / 18!
|
1.0 / 6402373705728000.0, // 1 / 18!
|
||||||
};
|
};
|
||||||
|
|
||||||
double exp(double x) {
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
double exp(double x)
|
||||||
|
{
|
||||||
size_t int_part;
|
size_t int_part;
|
||||||
bool invert;
|
bool invert;
|
||||||
double value;
|
double value;
|
||||||
double x0;
|
double x0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (x == 0) {
|
if (x == 0)
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (x < 0) {
|
else if (x < 0)
|
||||||
|
{
|
||||||
invert = true;
|
invert = true;
|
||||||
x = -x;
|
x = -x;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
invert = false;
|
invert = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* extract integer component */
|
/* Extract integer component */
|
||||||
|
|
||||||
int_part = (size_t) x;
|
int_part = (size_t) x;
|
||||||
|
|
||||||
/* set x to fractional component */
|
/* Set x to fractional component */
|
||||||
|
|
||||||
x -= (double)int_part;
|
x -= (double)int_part;
|
||||||
|
|
||||||
/* perform Taylor series approximation with nineteen terms */
|
/* Perform Taylor series approximation with nineteen terms */
|
||||||
|
|
||||||
value = 0.0;
|
value = 0.0;
|
||||||
x0 = 1.0;
|
x0 = 1.0;
|
||||||
for (i = 0; i < 19; i++) {
|
for (i = 0; i < 19; i++)
|
||||||
|
{
|
||||||
value += x0 * _dbl_inv_fact[i];
|
value += x0 * _dbl_inv_fact[i];
|
||||||
x0 *= x;
|
x0 *= x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* multiply by exp of the integer component */
|
/* Multiply by exp of the integer component */
|
||||||
value *= _expi(int_part);
|
|
||||||
|
|
||||||
if (invert) {
|
value *= lib_expi(int_part);
|
||||||
|
|
||||||
|
if (invert)
|
||||||
|
{
|
||||||
return (1.0 / value);
|
return (1.0 / value);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
return value;
|
{
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static long double _ldbl_inv_fact[] = {
|
|
||||||
1.0 / 1.0, // 1 / 0!
|
|
||||||
1.0 / 1.0, // 1 / 1!
|
|
||||||
1.0 / 2.0, // 1 / 2!
|
|
||||||
1.0 / 6.0, // 1 / 3!
|
|
||||||
1.0 / 24.0, // 1 / 4!
|
|
||||||
1.0 / 120.0, // 1 / 5!
|
|
||||||
1.0 / 720.0, // 1 / 6!
|
|
||||||
1.0 / 5040.0, // 1 / 7!
|
|
||||||
1.0 / 40320.0, // 1 / 8!
|
|
||||||
1.0 / 362880.0, // 1 / 9!
|
|
||||||
1.0 / 3628800.0, // 1 / 10!
|
|
||||||
1.0 / 39916800.0, // 1 / 11!
|
|
||||||
1.0 / 479001600.0, // 1 / 12!
|
|
||||||
1.0 / 6227020800.0, // 1 / 13!
|
|
||||||
1.0 / 87178291200.0, // 1 / 14!
|
|
||||||
1.0 / 1307674368000.0, // 1 / 15!
|
|
||||||
1.0 / 20922789888000.0, // 1 / 16!
|
|
||||||
1.0 / 355687428096000.0, // 1 / 17!
|
|
||||||
1.0 / 6402373705728000.0, // 1 / 18!
|
|
||||||
};
|
|
||||||
|
|
||||||
long double expl(long double x) {
|
|
||||||
size_t int_part;
|
|
||||||
bool invert;
|
|
||||||
long double value;
|
|
||||||
long double x0;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (x == 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (x < 0) {
|
|
||||||
invert = true;
|
|
||||||
x = -x;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
invert = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* extract integer component */
|
|
||||||
int_part = (size_t) x;
|
|
||||||
|
|
||||||
/* set x to fractional component */
|
|
||||||
x -= (long double) int_part;
|
|
||||||
|
|
||||||
/* perform Taylor series approximation with nineteen terms */
|
|
||||||
value = 0.0;
|
|
||||||
x0 = 1.0;
|
|
||||||
for (i = 0; i < 19; i++) {
|
|
||||||
value += x0 * _ldbl_inv_fact[i];
|
|
||||||
x0 *= x;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* multiply by exp of the integer component */
|
|
||||||
value *= _expi(int_part);
|
|
||||||
|
|
||||||
if (invert) {
|
|
||||||
return (1.0 / value);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_expf.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
|
||||||
|
* 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 <sys/types.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "lib_internal.h"
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
static float _flt_inv_fact[] =
|
||||||
|
{
|
||||||
|
1.0 / 1.0, // 1/0!
|
||||||
|
1.0 / 1.0, // 1/1!
|
||||||
|
1.0 / 2.0, // 1/2!
|
||||||
|
1.0 / 6.0, // 1/3!
|
||||||
|
1.0 / 24.0, // 1/4!
|
||||||
|
1.0 / 120.0, // 1/5!
|
||||||
|
1.0 / 720.0, // 1/6!
|
||||||
|
1.0 / 5040.0, // 1/7!
|
||||||
|
1.0 / 40320.0, // 1/8!
|
||||||
|
1.0 / 362880.0, // 1/9!
|
||||||
|
1.0 / 3628800.0, // 1/10!
|
||||||
|
};
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
float expf(float x)
|
||||||
|
{
|
||||||
|
size_t int_part;
|
||||||
|
bool invert;
|
||||||
|
float value;
|
||||||
|
float x0;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (x == 0)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (x < 0)
|
||||||
|
{
|
||||||
|
invert = true;
|
||||||
|
x = -x;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
invert = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Extract integer component */
|
||||||
|
|
||||||
|
int_part = (size_t) x;
|
||||||
|
|
||||||
|
/* set x to fractional component */
|
||||||
|
|
||||||
|
x -= (float)int_part;
|
||||||
|
|
||||||
|
/* Perform Taylor series approximation with eleven terms */
|
||||||
|
|
||||||
|
value = 0.0;
|
||||||
|
x0 = 1.0;
|
||||||
|
for (i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
value += x0 * _flt_inv_fact[i];
|
||||||
|
x0 *= x;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Multiply by exp of the integer component */
|
||||||
|
|
||||||
|
value *= lib_expi(int_part);
|
||||||
|
|
||||||
|
if (invert)
|
||||||
|
{
|
||||||
|
return (1.0 / value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_expl.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
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "lib_internal.h"
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
static long double _ldbl_inv_fact[] =
|
||||||
|
{
|
||||||
|
1.0 / 1.0, // 1 / 0!
|
||||||
|
1.0 / 1.0, // 1 / 1!
|
||||||
|
1.0 / 2.0, // 1 / 2!
|
||||||
|
1.0 / 6.0, // 1 / 3!
|
||||||
|
1.0 / 24.0, // 1 / 4!
|
||||||
|
1.0 / 120.0, // 1 / 5!
|
||||||
|
1.0 / 720.0, // 1 / 6!
|
||||||
|
1.0 / 5040.0, // 1 / 7!
|
||||||
|
1.0 / 40320.0, // 1 / 8!
|
||||||
|
1.0 / 362880.0, // 1 / 9!
|
||||||
|
1.0 / 3628800.0, // 1 / 10!
|
||||||
|
1.0 / 39916800.0, // 1 / 11!
|
||||||
|
1.0 / 479001600.0, // 1 / 12!
|
||||||
|
1.0 / 6227020800.0, // 1 / 13!
|
||||||
|
1.0 / 87178291200.0, // 1 / 14!
|
||||||
|
1.0 / 1307674368000.0, // 1 / 15!
|
||||||
|
1.0 / 20922789888000.0, // 1 / 16!
|
||||||
|
1.0 / 355687428096000.0, // 1 / 17!
|
||||||
|
1.0 / 6402373705728000.0, // 1 / 18!
|
||||||
|
};
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
long double expl(long double x)
|
||||||
|
{
|
||||||
|
size_t int_part;
|
||||||
|
bool invert;
|
||||||
|
long double value;
|
||||||
|
long double x0;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (x == 0)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (x < 0)
|
||||||
|
{
|
||||||
|
invert = true;
|
||||||
|
x = -x;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
invert = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Extract integer component */
|
||||||
|
|
||||||
|
int_part = (size_t) x;
|
||||||
|
|
||||||
|
/* Set x to fractional component */
|
||||||
|
|
||||||
|
x -= (long double)int_part;
|
||||||
|
|
||||||
|
/* Perform Taylor series approximation with nineteen terms */
|
||||||
|
|
||||||
|
value = 0.0;
|
||||||
|
x0 = 1.0;
|
||||||
|
for (i = 0; i < 19; i++)
|
||||||
|
{
|
||||||
|
value += x0 * _ldbl_inv_fact[i];
|
||||||
|
x0 *= x;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Multiply by exp of the integer component */
|
||||||
|
|
||||||
|
value *= lib_expi(int_part);
|
||||||
|
|
||||||
|
if (invert)
|
||||||
|
{
|
||||||
|
return (1.0 / value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+29
-13
@@ -1,4 +1,14 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
|
* lib/math/lib_fabs.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, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
|
* Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -12,19 +22,25 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
float fabsf(float x) {
|
#include <nuttx/config.h>
|
||||||
return ((x < 0) ? -x : x);
|
#include <nuttx/compiler.h>
|
||||||
}
|
|
||||||
|
#include <math.h>
|
||||||
double fabs(double x) {
|
|
||||||
return ((x < 0) ? -x : x);
|
/************************************************************************
|
||||||
}
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
long double fabsl(long double x) {
|
|
||||||
|
#if CONFIG_HAVE_DOUBLE
|
||||||
|
double fabs(double x)
|
||||||
|
{
|
||||||
return ((x < 0) ? -x : x);
|
return ((x < 0) ? -x : x);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_fabsf.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, 2010 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 <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
float fabsf(float x)
|
||||||
|
{
|
||||||
|
return ((x < 0) ? -x : x);
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_fabsl.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, 2010 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>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
long double fabsl(long double x)
|
||||||
|
{
|
||||||
|
return ((x < 0) ? -x : x);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+31
-16
@@ -1,4 +1,14 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
|
* lib/math/lib_floor.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>
|
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -12,26 +22,31 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
float floorf(float x) {
|
#include <nuttx/config.h>
|
||||||
modff(x, &x);
|
#include <nuttx/compiler.h>
|
||||||
if (x < 0.0) x -= 1.0;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
double floor(double x) {
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_DOUBLE
|
||||||
|
double floor(double x)
|
||||||
|
{
|
||||||
modf(x, &x);
|
modf(x, &x);
|
||||||
if (x < 0.0) x -= 1.0;
|
if (x < 0.0)
|
||||||
return x;
|
{
|
||||||
|
x -= 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long double floorl(long double x) {
|
|
||||||
modfl(x, &x);
|
|
||||||
if (x < 0.0) x -= 1.0;
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_floorf.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
|
||||||
|
* 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 <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
float floorf(float x)
|
||||||
|
{
|
||||||
|
modff(x, &x);
|
||||||
|
if (x < 0.0)
|
||||||
|
{
|
||||||
|
x -= 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_floorl.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
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
long double floorl(long double x)
|
||||||
|
{
|
||||||
|
modfl(x, &x);
|
||||||
|
if (x < 0.0)
|
||||||
|
{
|
||||||
|
x -= 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+25
-40
@@ -1,4 +1,14 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
|
* lib/math/lib_fmod.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>
|
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -12,39 +22,25 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
/* If GCC/CLang builtins are available, use them */
|
#include <nuttx/config.h>
|
||||||
#ifdef __GNUC__
|
#include <nuttx/compiler.h>
|
||||||
|
|
||||||
float fmodf(float x, float div) {
|
#include <math.h>
|
||||||
return __builtin_fmodf(x, div);
|
|
||||||
}
|
|
||||||
|
|
||||||
double fmod(double x, double div) {
|
/************************************************************************
|
||||||
return __builtin_fmod(x, div);
|
* Public Functions
|
||||||
}
|
************************************************************************/
|
||||||
|
|
||||||
long double fmodl(long double x, long double div) {
|
#if CONFIG_HAVE_DOUBLE
|
||||||
return __builtin_fmodl(x, div);
|
double fmod(double x, double div)
|
||||||
}
|
{
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
float fmodf(float x, float div) {
|
|
||||||
float n0;
|
|
||||||
|
|
||||||
x /= div;
|
|
||||||
x = modff(x, &n0);
|
|
||||||
x *= div;
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
double fmod(double x, double div) {
|
|
||||||
double n0;
|
double n0;
|
||||||
|
|
||||||
x /= div;
|
x /= div;
|
||||||
@@ -53,15 +49,4 @@ double fmod(double x, double div) {
|
|||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
long double fmodl(long double x, long double div) {
|
|
||||||
long double n0;
|
|
||||||
|
|
||||||
x /= div;
|
|
||||||
x = modfl(x, &n0);
|
|
||||||
x *= div;
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_fmodf.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
|
||||||
|
* 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 <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
float fmodf(float x, float div)
|
||||||
|
{
|
||||||
|
float n0;
|
||||||
|
|
||||||
|
x /= div;
|
||||||
|
x = modff(x, &n0);
|
||||||
|
x *= div;
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_fmodl.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
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
long double fmodl(long double x, long double div)
|
||||||
|
{
|
||||||
|
long double n0;
|
||||||
|
|
||||||
|
x /= div;
|
||||||
|
x = modfl(x, &n0);
|
||||||
|
x *= div;
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+31
-18
@@ -1,4 +1,14 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
|
* lib/math/lib_frexp.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>
|
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -12,23 +22,26 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
float frexpf(float x, int *exp) {
|
#include <nuttx/config.h>
|
||||||
*exp = (int) ceilf(log2f(x));
|
#include <nuttx/compiler.h>
|
||||||
return x / ldexpf(1.0, *exp);
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_DOUBLE
|
||||||
|
double frexp(double x, int *exponent)
|
||||||
|
{
|
||||||
|
*exponent = (int)ceil(log2(x));
|
||||||
|
return x / ldexp(1.0, *exponent);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
double frexp(double x, int *exp) {
|
|
||||||
*exp = (int) ceil(log2(x));
|
|
||||||
return x / ldexp(1.0, *exp);
|
|
||||||
}
|
|
||||||
|
|
||||||
long double frexpl(long double x, int *exp) {
|
|
||||||
*exp = (int) ceill(log2(x));
|
|
||||||
return x / ldexpl(1.0, *exp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_frexpf.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
|
||||||
|
* 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 <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
float frexpf(float x, int *exponent)
|
||||||
|
{
|
||||||
|
*exponent = (int)ceilf(log2f(x));
|
||||||
|
return x / ldexpf(1.0, *exponent);
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* lib/math/lib_frexpl.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
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_LONG_DOUBLE
|
||||||
|
long double frexpl(long double x, int *exponent)
|
||||||
|
{
|
||||||
|
*exponent = (int)ceill(log2(x));
|
||||||
|
return x / ldexpl(1.0, *exponent);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+28
-13
@@ -1,4 +1,14 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
|
* lib/math/lib_ldexp.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>
|
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -12,20 +22,25 @@
|
|||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
#include <apps/math.h>
|
/************************************************************************
|
||||||
#include <float.h>
|
* Included Files
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
float ldexpf(float x, int n) {
|
#include <nuttx/config.h>
|
||||||
return (x * powf(2.0, (float) n));
|
#include <nuttx/compiler.h>
|
||||||
}
|
|
||||||
|
|
||||||
double ldexp(double x, int n) {
|
#include <math.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_HAVE_DOUBLE
|
||||||
|
double ldexp(double x, int n)
|
||||||
|
{
|
||||||
return (x * pow(2.0, (double)n));
|
return (x * pow(2.0, (double)n));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
long double ldexpl(long double x, int n) {
|
|
||||||
return (x * powl(2.0, (long double) n));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user