diff --git a/include/cxx/cmath b/include/cxx/cmath index c43b4c59e5..d505db758e 100644 --- a/include/cxx/cmath +++ b/include/cxx/cmath @@ -51,6 +51,10 @@ namespace std { + using ::float32; + using ::double_t; + using ::float64; + #ifdef CONFIG_HAVE_FLOAT using ::acosf; using ::asinf; diff --git a/include/cxx/cstddef b/include/cxx/cstddef index 5c2ca53ed1..c341a12fca 100644 --- a/include/cxx/cstddef +++ b/include/cxx/cstddef @@ -53,14 +53,6 @@ namespace std { // Standard types - using ::float32; -#ifndef CONFIG_HAVE_DOUBLE - using ::double_t; - using ::float64; -#else - using ::double_t; - using ::float64; -#endif using ::mode_t; using ::size_t; using ::ssize_t; diff --git a/include/nuttx/lib/math.h b/include/nuttx/lib/math.h index 9623d3d590..8b4403b518 100644 --- a/include/nuttx/lib/math.h +++ b/include/nuttx/lib/math.h @@ -124,6 +124,21 @@ #define M_PI_F ((float)M_PI) #define M_PI_2_F ((float)M_PI_2) +/**************************************************************************** + * Type Declarations + ****************************************************************************/ + +/* Floating point types */ + +typedef float float32; +#ifndef CONFIG_HAVE_DOUBLE +typedef float double_t; +typedef float float64; +#else +typedef double double_t; +typedef double float64; +#endif + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/include/sys/types.h b/include/sys/types.h index 1785d776af..902d30def8 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -1,7 +1,8 @@ /**************************************************************************** * include/sys/types.h * - * Copyright (C) 2007-2009, 2011-2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2012, 2014-2015 Gregory Nutt. + * All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -104,17 +105,6 @@ #ifndef __ASSEMBLY__ -/* Floating point types */ - -typedef float float32; -#ifndef CONFIG_HAVE_DOUBLE -typedef float double_t; -typedef float float64; -#else -typedef double double_t; -typedef double float64; -#endif - /* Misc. scalar types */ /* mode_t is an integer type used for file attributes. mode_t needs @@ -165,8 +155,8 @@ typedef uint16_t ino_t; typedef uint16_t nlink_t; -/* pid_t is used for process IDs and process group IDs. It must be signed because - * negative PID values are used to represent invalid PIDs. +/* pid_t is used for process IDs and process group IDs. It must be signed + * because negative PID values are used to represent invalid PIDs. */ typedef int16_t pid_t; @@ -177,9 +167,9 @@ typedef int16_t pid_t; typedef int16_t id_t; -/* Unix requires a key of type key_t defined in file sys/types.h for requesting - * resources such as shared memory segments, message queues and semaphores. A key - * is simply an integer of type key_t +/* Unix requires a key of type key_t defined in file sys/types.h for + * requesting resources such as shared memory segments, message queues and + * semaphores. A key is simply an integer of type key_t */ typedef int16_t key_t; diff --git a/libs/libc/stdio/legacy_dtoa.c b/libs/libc/stdio/legacy_dtoa.c index ba668d4717..7e28d35ac3 100644 --- a/libs/libc/stdio/legacy_dtoa.c +++ b/libs/libc/stdio/legacy_dtoa.c @@ -45,6 +45,7 @@ #include +#include #include #include @@ -132,7 +133,8 @@ typedef struct bigint_s bigint_t; * Options: * * 1. Allocate on stack. g_freelist is rather large, however.. around 275 - * bytes (it could be shrunk a little by using stdint types instead of int. + * bytes (it could be shrunk a little by using stdint types instead of + * int. * 2. Semaphore protect the global variables and handle interrupt level * calls as a special case (perhaps refusing them? Or having a duplicate * set of variables, one for tasks and one for interrupt usage) @@ -236,6 +238,7 @@ static FAR bigint_t *multadd(FAR bigint_t *b, int m, int a) bfree(b); b = b1; } + b->x[wds++] = a; b->wds = wds; } @@ -478,11 +481,11 @@ static FAR bigint_t *pow5mult(FAR bigint_t *b, int k) FAR bigint_t *b1; FAR bigint_t *p5; FAR bigint_t *p51; + int i; static int p05[3] = { 5, 25, 125 }; - int i; if ((i = k & 3) != 0) { @@ -631,14 +634,14 @@ static int cmp(FAR bigint_t *a, FAR bigint_t *b) #ifdef CONFIG_DEBUG_LIB if (i > 1 && a->x[i - 1] == 0) - { - lerr("ERROR: cmp called with a->x[a->wds-1] == 0\n"); - } + { + lerr("ERROR: cmp called with a->x[a->wds-1] == 0\n"); + } if (j > 1 && b->x[j - 1] == 0) - { - lerr("ERROR: cmp called with b->x[b->wds-1] == 0\n"); - } + { + lerr("ERROR: cmp called with b->x[b->wds-1] == 0\n"); + } #endif if (i -= j) @@ -827,21 +830,23 @@ static FAR bigint_t *d2b(double_t d, int *e, int *bits) if ((y = WORD1(d)) != 0) { if ((k = lo0bits(&y)) != 0) - if (k >= 16) - { - x[0] = y | ((z << (32 - k)) & 0xffff); - x[1] = z >> (k - 16) & 0xffff; - x[2] = z >> k; - i = 2; - } - else - { - x[0] = y & 0xffff; - x[1] = (y >> 16) | ((z << (16 - k)) & 0xffff); - x[2] = z >> k & 0xffff; - x[3] = z >> (k + 16); - i = 3; - } + { + if (k >= 16) + { + x[0] = y | ((z << (32 - k)) & 0xffff); + x[1] = z >> (k - 16) & 0xffff; + x[2] = z >> k; + i = 2; + } + else + { + x[0] = y & 0xffff; + x[1] = (y >> 16) | ((z << (16 - k)) & 0xffff); + x[2] = z >> k & 0xffff; + x[3] = z >> (k + 16); + i = 3; + } + } else { x[0] = y & 0xffff; @@ -859,6 +864,7 @@ static FAR bigint_t *d2b(double_t d, int *e, int *bits) lerr("ERROR: Zero passed to d2b\n"); } #endif + k = lo0bits(&z); if (k >= 16) { @@ -1550,6 +1556,7 @@ fast_failed: d += ds; } #endif + *st++ = '0' + (int)l; if (i == ilim) { @@ -1760,8 +1767,8 @@ one_digit: mhi = lshift(mhi, m2); } - /* Compute mlo -- check for special case that d is a normalized power of - * 2. + /* Compute mlo -- check for special case that d is a normalized power + * of 2. */ mlo = mhi; @@ -1776,7 +1783,7 @@ one_digit: { dig = quorem(b, s) + '0'; - /* Do we yet have the shortest decimal string that will round to d? */ + /* Have we yet the shortest decimal string that will round to d? */ j = cmp(b, mlo); delta = diff(s, mhi); @@ -1799,6 +1806,7 @@ one_digit: goto ret; } #endif + if (j < 0 || (j == 0 && !mode #ifndef CONFIG_DTOA_ROUND_BIASED && ((WORD1(d) & 1) == 0) diff --git a/libs/libc/stdio/legacy_libvsprintf.c b/libs/libc/stdio/legacy_libvsprintf.c index a2474cf6b8..3e176f4213 100644 --- a/libs/libc/stdio/legacy_libvsprintf.c +++ b/libs/libc/stdio/legacy_libvsprintf.c @@ -39,7 +39,7 @@ #include -#include +#include #include #include #include @@ -100,7 +100,7 @@ * string data cannot be accessed by simply de-referencing the format string * pointer. This might be in the case in Harvard architectures where string * data might be stored in instruction space or if string data were stored - * on some media like EEPROM or external serial FLASH. In all of these cases, + * on some media like EEPROM or external serial FLASH. In all of these cases, * string data has to be accessed indirectly using the architecture-supplied * up_romgetc(). The following mechanisms attempt to make these different * access methods indistinguishable in the following code. @@ -177,11 +177,14 @@ static int getlusize(uint8_t fmt, FAR uint16_t flags, unsigned long ln); /* Unsigned long long int to ASCII conversions */ #if defined(CONFIG_HAVE_LONG_LONG) && defined(CONFIG_LIBC_LONG_LONG) -static void llutodec(FAR struct lib_outstream_s *obj, unsigned long long lln); -static void llutohex(FAR struct lib_outstream_s *obj, unsigned long long lln, - uint8_t a); -static void llutooct(FAR struct lib_outstream_s *obj, unsigned long long lln); -static void llutobin(FAR struct lib_outstream_s *obj, unsigned long long lln); +static void llutodec(FAR struct lib_outstream_s *obj, + unsigned long long lln); +static void llutohex(FAR struct lib_outstream_s *obj, + unsigned long long lln, uint8_t a); +static void llutooct(FAR struct lib_outstream_s *obj, + unsigned long long lln); +static void llutobin(FAR struct lib_outstream_s *obj, + unsigned long long lln); static void llutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, uint16_t flags, unsigned long long lln); static void llfixup(uint8_t fmt, FAR uint16_t *flags, FAR long long *lln); @@ -220,12 +223,12 @@ static const char g_nullstring[] = "(null)"; static void ptohex(FAR struct lib_outstream_s *obj, uint16_t flags, FAR void *p) { + uint8_t bits; union { uint32_t dw; FAR void *p; } u; - uint8_t bits; /* Check for alternate form */ @@ -1210,22 +1213,22 @@ int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const IPTR char *src, if (FMT_CHAR != '%') { - /* Output the character */ + /* Output the character */ - obj->put(obj, FMT_CHAR); + obj->put(obj, FMT_CHAR); - /* Flush the buffer if a newline is encountered */ + /* Flush the buffer if a newline is encountered */ - if (FMT_CHAR == '\n') - { - /* Should return an error on a failure to flush */ + if (FMT_CHAR == '\n') + { + /* Should return an error on a failure to flush */ - obj->flush(obj); - } + obj->flush(obj); + } - /* Process the next character in the format */ + /* Process the next character in the format */ - continue; + continue; } /* We have found a format specifier. Move past it. */ @@ -1263,6 +1266,7 @@ int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const IPTR char *src, { justify = FMT_RJUST0; } + #if 0 /* Center justification. */ diff --git a/libs/libc/stdio/lib_dtoa_engine.h b/libs/libc/stdio/lib_dtoa_engine.h index 1a4c6588c6..6b9c34e5bf 100644 --- a/libs/libc/stdio/lib_dtoa_engine.h +++ b/libs/libc/stdio/lib_dtoa_engine.h @@ -40,12 +40,10 @@ * Included Files ****************************************************************************/ -#include +#include #include #include -#include - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ diff --git a/libs/libc/stdio/lib_libvscanf.c b/libs/libc/stdio/lib_libvscanf.c index 99dc147bcb..7ddbb7686e 100644 --- a/libs/libc/stdio/lib_libvscanf.c +++ b/libs/libc/stdio/lib_libvscanf.c @@ -41,9 +41,7 @@ #include -#include - -#include +#include #include #include #include diff --git a/libs/libc/stdlib/lib_srand.c b/libs/libc/stdlib/lib_srand.c index 9f758f9391..afc8af039a 100644 --- a/libs/libc/stdlib/lib_srand.c +++ b/libs/libc/stdlib/lib_srand.c @@ -39,7 +39,7 @@ #include -#include +#include #include #include @@ -120,9 +120,9 @@ static inline unsigned long fgenerate1(void) { unsigned long randint; - /* First order congruential generator. One may be added to the result of the - * generated value to avoid the value zero. This would be fatal for the - * first order random number generator. + /* First order congruential generator. One may be added to the result of + * the generated value to avoid the value zero. This would be fatal for + * the first order random number generator. */ randint = (RND1_CONSTK * g_randint1) % RND1_CONSTP; @@ -158,8 +158,8 @@ static inline unsigned long fgenerate2(void) g_randint2 = g_randint1; g_randint1 = randint; - /* We cannot permit both values to become zero. That would be fatal for the - * second order random number generator. + /* We cannot permit both values to become zero. That would be fatal for + * the second order random number generator. */ if (g_randint2 == 0 && g_randint1 == 0) @@ -200,8 +200,8 @@ static inline unsigned long fgenerate3(void) g_randint2 = g_randint1; g_randint1 = randint; - /* We cannot permit all three values to become zero. That would be fatal for the - * third order random number generator. + /* We cannot permit all three values to become zero. That would be fatal + * for the third order random number generator. */ if (g_randint3 == 0 && g_randint2 == 0 && g_randint1 == 0)