diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-12-07 16:00:56 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-12-07 16:00:56 +0000 |
commit | 756aa6b90920d0087ad708c3ad10e091be79e46e (patch) | |
tree | c29f3db20b8275cd22e7c4d36c3d722f2fdf6277 /nuttx/libc/math/lib_roundf.c | |
parent | 4c98d2e73211a2bde3530c9f1f369efa0d0745e1 (diff) | |
download | px4-firmware-756aa6b90920d0087ad708c3ad10e091be79e46e.tar.gz px4-firmware-756aa6b90920d0087ad708c3ad10e091be79e46e.tar.bz2 px4-firmware-756aa6b90920d0087ad708c3ad10e091be79e46e.zip |
Patches from Petteri Aimonen + stdbool and rand() changes for Freddie Chopin
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5415 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/libc/math/lib_roundf.c')
-rw-r--r-- | nuttx/libc/math/lib_roundf.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/nuttx/libc/math/lib_roundf.c b/nuttx/libc/math/lib_roundf.c new file mode 100644 index 000000000..145cf3df6 --- /dev/null +++ b/nuttx/libc/math/lib_roundf.c @@ -0,0 +1,38 @@ +/************************************************************************ + * lib/math/lib_roundf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * (C) 2012 Petteri Aimonen <jpa@nx.mail.kapsi.fi> + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/compiler.h> + +#include <math.h> + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float roundf(float x) +{ + float f = modff(x, &x); + if (x <= 0.0f && f <= -0.5f) + { + x -= 1.0f; + } + + if (x >= 0.0f && f >= 0.5f) + { + x += 1.0f; + } + + return x; +} |