summaryrefslogtreecommitdiff
path: root/nuttx/lib/lib_rint.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-02-28 13:42:19 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-02-28 13:42:19 +0000
commitcbade4e74a17aa881e8031b6785657d7166dd819 (patch)
tree2e5a62c23ceef9959d6951854be6cb6ad3aafdef /nuttx/lib/lib_rint.c
parentecfc958f561da896a1ea1b08c2ceb4db25cc58b1 (diff)
downloadpx4-nuttx-cbade4e74a17aa881e8031b6785657d7166dd819.tar.gz
px4-nuttx-cbade4e74a17aa881e8031b6785657d7166dd819.tar.bz2
px4-nuttx-cbade4e74a17aa881e8031b6785657d7166dd819.zip
Fix link problems
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@24 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib/lib_rint.c')
-rw-r--r--nuttx/lib/lib_rint.c86
1 files changed, 49 insertions, 37 deletions
diff --git a/nuttx/lib/lib_rint.c b/nuttx/lib/lib_rint.c
index 632c6632d..a0f7dbd4f 100644
--- a/nuttx/lib/lib_rint.c
+++ b/nuttx/lib/lib_rint.c
@@ -41,6 +41,7 @@
* Included Files
************************************************************/
+#include <nuttx/config.h>
#include <sys/types.h>
#include <stdlib.h>
@@ -74,50 +75,61 @@
double_t rint(double_t x)
{
- double_t retValue;
+ double_t 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(FP_ROUND_POSITIVE)) && (FP_ROUNDING_POSITIVE != 0))
- retValue = ceil(x);
+ /* 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().
+ */
-#elif ((defined(FP_ROUND_NEGATIVE)) && (FP_ROUNDING_NEGATIVE != 0))
- retValue = floor(x);
+#if defined(CONFIG_FP_ROUND_POSITIVE) && CONFIG_FP_ROUNDING_POSITIVE != 0
-#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. */
-
- long dwInteger = (long)x;
- double_t fRemainder = x - (double_t)dwInteger;
+ ret = ceil(x);
- if (x < 0.0) {
+#elif defined(CONFIG_FP_ROUND_NEGATIVE) && CONFIG_FP_ROUNDING_NEGATIVE != 0
- /* fRemainder should be in range 0 .. -1 */
- if (fRemainder == -0.5)
- dwInteger = ((dwInteger+1)&~1);
- else if (fRemainder < -0.5) {
- dwInteger--;
+ ret = floor(x);
- } /* end if */
- } /* end if */
- else {
-
- /* fRemainder should be in range 0 .. 1 */
- if (fRemainder == 0.5)
- dwInteger = ((dwInteger+1)&~1);
- else if (fRemainder > 0.5) {
- dwInteger++;
-
- } /* end if */
- } /* end else */
+#else
- retValue = (double_t)dwInteger;
+ /* 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.
+ */
+
+ long dwinteger = (long)x;
+ double_t fremainder = x - (double_t)dwinteger;
+
+ if (x < 0.0)
+ {
+ /* fremainder should be in range 0 .. -1 */
+
+ if (fremainder == -0.5)
+ {
+ dwinteger = ((dwinteger+1)&~1);
+ }
+ else if (fremainder < -0.5)
+ {
+ dwinteger--;
+ }
+ }
+ else
+ {
+ /* fremainder should be in range 0 .. 1 */
+
+ if (fremainder == 0.5)
+ {
+ dwinteger = ((dwinteger+1)&~1);
+ }
+ else if (fremainder > 0.5)
+ {
+ dwinteger++;
+ }
+ }
+
+ ret = (double_t)dwinteger;
#endif
- return retValue;
+ return ret;
}