From f0c90a39caa8567a23c66f45421a75696d3c1600 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 28 Jun 2014 10:14:29 -0600 Subject: [PATCH] Change double_t to double in rint. Add rintf and rintl while we are at it --- include/nuttx/math.h | 4 +- libc/math.csv | 148 +++++++++++++++++++++--------------------- libc/math/Make.defs | 9 ++- libc/math/lib_rint.c | 22 ++++--- libc/math/lib_rintf.c | 139 +++++++++++++++++++++++++++++++++++++++ libc/math/lib_rintl.c | 139 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 373 insertions(+), 88 deletions(-) create mode 100644 libc/math/lib_rintf.c create mode 100644 libc/math/lib_rintl.c diff --git a/include/nuttx/math.h b/include/nuttx/math.h index d7945ec95e..c97c525fda 100644 --- a/include/nuttx/math.h +++ b/include/nuttx/math.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/math.h * - * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2012, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -152,7 +152,7 @@ long double roundl(long double x); float rintf(float x); /* Not implemented */ #if CONFIG_HAVE_DOUBLE -double_t rint(double_t x); +double rint(double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE long double rintl(long double x); /* Not implemented */ diff --git a/libc/math.csv b/libc/math.csv index 88b7fc272b..90b0ce3e0a 100644 --- a/libc/math.csv +++ b/libc/math.csv @@ -1,73 +1,75 @@ -"acos","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"acosf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"acosl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"asin","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"asinf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"asinl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"atan","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"atan2","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double",double" -"atan2f","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float",float" -"atan2l","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double","long double" -"atanf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"atanl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"ceil","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"ceilf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"ceill","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"cos","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"cosf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"cosh","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"coshf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"coshl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"cosl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"exp","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"expf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"expl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"fabs","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"fabsf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"fabsl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"floor","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"floorf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"floorl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"fmod","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double","double" -"fmodf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float","float" -"fmodl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double","long double" -"frexp","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double","int *" -"frexpf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float","int *" -"frexpl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double",int *" -"ldexp","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double",int" -"ldexpf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float",int" -"ldexpl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double","int" -"log","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"log10","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"log10f","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"log10l","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"log2","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"log2f","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"log2l","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"logf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"logl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"modf","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double","double *" -"modff","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float","float *" -"modfl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double","long double *" -"pow","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double","double" -"powf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float","float" -"powl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double","long double" -"rint","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double_t","double_t" -"round","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"roundf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"roundl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"sin","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"sinf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"sinh","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"sinhf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"sinhl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"sinl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"sqrt","math.hdefined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","","" -"sqrtf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"sqrtl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"tan","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"tanf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"tanh","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" -"tanhf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" -"tanhl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" -"tanl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"acos","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"acosf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"acosl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"asin","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"asinf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"asinl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"atan","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"atan2","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double",double" +"atan2f","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float",float" +"atan2l","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double","long double" +"atanf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"atanl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"ceil","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"ceilf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"ceill","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"cos","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"cosf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"cosh","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"coshf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"coshl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"cosl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"exp","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"expf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"expl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"fabs","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"fabsf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"fabsl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"floor","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"floorf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"floorl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"fmod","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double","double" +"fmodf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float","float" +"fmodl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double","long double" +"frexp","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double","int *" +"frexpf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float","int *" +"frexpl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double",int *" +"ldexp","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double",int" +"ldexpf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float",int" +"ldexpl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double","int" +"log","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"log10","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"log10f","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"log10l","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"log2","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"log2f","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"log2l","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"logf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"logl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"modf","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double","double *" +"modff","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float","float *" +"modfl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double","long double *" +"pow","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double","double" +"powf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float","float" +"powl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double","long double" +"rint","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"rintf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"rintl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"round","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"roundf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"roundl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"sin","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"sinf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"sinh","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"sinhf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"sinhl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"sinl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"sqrt","math.hdefined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","","" +"sqrtf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"sqrtl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"tan","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"tanf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"tanh","math.h","defined(CONFIG_HAVE_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","double","double" +"tanhf","math.h","defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH)","float","float" +"tanhl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" +"tanl","math.h","defined(CONFIG_HAVE_LONG_DOUBLE) && (defined(CONFIG_LIBM) || defined(CONFIG_ARCH_MATH))","long double","long double" diff --git a/libc/math/Make.defs b/libc/math/Make.defs index e4c75b45dc..768ea8d6f0 100644 --- a/libc/math/Make.defs +++ b/libc/math/Make.defs @@ -40,17 +40,20 @@ ifeq ($(CONFIG_LIBM),y) 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_roundf.c lib_sinf.c lib_sinhf.c lib_sqrtf.c lib_tanf.c lib_tanhf.c +CSRCS += lib_rintf.c lib_roundf.c lib_sinf.c lib_sinhf.c lib_sqrtf.c lib_tanf.c +CSRCS += lib_tanhf.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_ldexp.c lib_log.c lib_log10.c lib_log2.c lib_modf.c lib_pow.c -CSRCS += lib_rint.c lib_round.c lib_sin.c lib_sinh.c lib_sqrt.c lib_tan.c lib_tanh.c +CSRCS += lib_rint.c lib_round.c lib_sin.c lib_sinh.c lib_sqrt.c lib_tan.c +CSRCS += 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_roundl.c lib_sinl.c lib_sinhl.c lib_sqrtl.c lib_tanl.c lib_tanhl.c +CSRCS += lib_rintl.c lib_roundl.c lib_sinl.c lib_sinhl.c lib_sqrtl.c lib_tanl.c +CSRCS += lib_tanhl.c CSRCS += lib_libexpi.c lib_libsqrtapprox.c diff --git a/libc/math/lib_rint.c b/libc/math/lib_rint.c index 677d9a6cd4..7454cc7394 100644 --- a/libc/math/lib_rint.c +++ b/libc/math/lib_rint.c @@ -1,7 +1,7 @@ /************************************************************ * libc/fixedmath/lib_rint.c * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2011, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -75,9 +75,11 @@ * Private Variables ************************************************************/ -double_t rint(double_t x) +double rint(double x) { - double_t ret; + long linteger; + double fremainder; + double ret; /* If the current rounding mode rounds toward negative * infinity, rint() is identical to floor(). If the current @@ -100,8 +102,8 @@ double_t rint(double_t x) * |rint(x)-x|=1/2, then rint(x) is even. */ - long dwinteger = (long)x; - double_t fremainder = x - (double_t)dwinteger; + linteger = (long)x; + fremainder = x - (double)linteger; if (x < 0.0) { @@ -109,11 +111,11 @@ double_t rint(double_t x) if (fremainder == -0.5) { - dwinteger = ((dwinteger+1)&~1); + linteger = ((linteger+1)&~1); } else if (fremainder < -0.5) { - dwinteger--; + linteger--; } } else @@ -122,15 +124,15 @@ double_t rint(double_t x) if (fremainder == 0.5) { - dwinteger = ((dwinteger+1)&~1); + linteger = ((linteger+1)&~1); } else if (fremainder > 0.5) { - dwinteger++; + linteger++; } } - ret = (double_t)dwinteger; + ret = (double)linteger; #endif return ret; diff --git a/libc/math/lib_rintf.c b/libc/math/lib_rintf.c new file mode 100644 index 0000000000..62096a279b --- /dev/null +++ b/libc/math/lib_rintf.c @@ -0,0 +1,139 @@ +/************************************************************ + * libc/fixedmath/lib_rintf.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +#include +#include +#include + +/************************************************************ + * Definitions + ************************************************************/ + +/************************************************************ + * Private Type Declarations + ************************************************************/ + +/************************************************************ + * Private Function Prototypes + ************************************************************/ + +/********************************************************** + * Global Constant Data + **********************************************************/ + +/************************************************************ + * Global Variables + ************************************************************/ + +/********************************************************** + * Private Constant Data + **********************************************************/ + +/************************************************************ + * Private Variables + ************************************************************/ + +float rintf(float x) +{ + long linteger; + float fremainder; + float ret; + + /* If the current rounding mode rounds toward negative + * infinity, rintf() is identical to floorf(). If the current + * rounding mode rounds toward positive infinity, rintf() is + * identical to ceilf(). + */ + +#if defined(CONFIG_FP_ROUND_POSITIVE) && CONFIG_FP_ROUNDING_POSITIVE != 0 + + ret = ceilf(x); + +#elif defined(CONFIG_FP_ROUND_NEGATIVE) && CONFIG_FP_ROUNDING_NEGATIVE != 0 + + ret = floorf(x); + +#else + + /* In the default rounding mode (round to nearest), rint(x) is the + * integer nearest x with the additional stipulation that if + * |rint(x)-x|=1/2, then rint(x) is even. + */ + + linteger = (long)x; + fremainder = x - (float)linteger; + + if (x < 0.0) + { + /* fremainder should be in range 0 .. -1 */ + + if (fremainder == -0.5) + { + linteger = ((linteger+1)&~1); + } + else if (fremainder < -0.5) + { + linteger--; + } + } + else + { + /* fremainder should be in range 0 .. 1 */ + + if (fremainder == 0.5) + { + linteger = ((linteger+1)&~1); + } + else if (fremainder > 0.5) + { + linteger++; + } + } + + ret = (float)linteger; +#endif + + return ret; +} diff --git a/libc/math/lib_rintl.c b/libc/math/lib_rintl.c new file mode 100644 index 0000000000..1c9087241b --- /dev/null +++ b/libc/math/lib_rintl.c @@ -0,0 +1,139 @@ +/************************************************************ + * libc/fixedmath/lib_rint.c + * + * Copyright (C) 2007, 2011, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +#include +#include +#include + +/************************************************************ + * Definitions + ************************************************************/ + +/************************************************************ + * Private Type Declarations + ************************************************************/ + +/************************************************************ + * Private Function Prototypes + ************************************************************/ + +/********************************************************** + * Global Constant Data + **********************************************************/ + +/************************************************************ + * Global Variables + ************************************************************/ + +/********************************************************** + * Private Constant Data + **********************************************************/ + +/************************************************************ + * Private Variables + ************************************************************/ + +long double rintl(long double x) +{ + int64_t llinteger; + long double fremainder; + long double ret; + + /* If the current rounding mode rounds toward negative + * infinity, rint() is identical to floor(). If the current + * rounding mode rounds toward positive infinity, rint() is + * identical to ceil(). + */ + +#if defined(CONFIG_FP_ROUND_POSITIVE) && CONFIG_FP_ROUNDING_POSITIVE != 0 + + ret = ceil(x); + +#elif defined(CONFIG_FP_ROUND_NEGATIVE) && CONFIG_FP_ROUNDING_NEGATIVE != 0 + + ret = floor(x); + +#else + + /* In the default rounding mode (round to nearest), rint(x) is the + * integer nearest x with the additional stipulation that if + * |rint(x)-x|=1/2, then rint(x) is even. + */ + + llinteger = (int64_t)x; + fremainder = x - (long double)llinteger; + + if (x < 0.0) + { + /* fremainder should be in range 0 .. -1 */ + + if (fremainder == -0.5) + { + llinteger = ((llinteger+1)&~1); + } + else if (fremainder < -0.5) + { + llinteger--; + } + } + else + { + /* fremainder should be in range 0 .. 1 */ + + if (fremainder == 0.5) + { + llinteger = ((llinteger+1)&~1); + } + else if (fremainder > 0.5) + { + llinteger++; + } + } + + ret = (long double)llinteger; +#endif + + return ret; +}