We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bacb52a commit fb161aaCopy full SHA for fb161aa
1 file changed
lib/libm/nearbyintf.c
@@ -0,0 +1,21 @@
1
+// adapted from the rintf() function from musl-1.1.16
2
+
3
+#include "libm.h"
4
5
+float nearbyintf(float x)
6
+{
7
+ union {float f; uint32_t i;} u = {x};
8
+ int e = u.i>>23 & 0xff;
9
+ int s = u.i>>31;
10
+ float_t y;
11
12
+ if (e >= 0x7f+23)
13
+ return x;
14
+ if (s)
15
+ y = x - 0x1p23f + 0x1p23f;
16
+ else
17
+ y = x + 0x1p23f - 0x1p23f;
18
+ if (y == 0)
19
+ return s ? -0.0f : 0.0f;
20
+ return y;
21
+}
0 commit comments