aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/i386/gen/flt_rounds.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/i386/gen/flt_rounds.c')
-rw-r--r--lib/libc/i386/gen/flt_rounds.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/libc/i386/gen/flt_rounds.c b/lib/libc/i386/gen/flt_rounds.c
new file mode 100644
index 000000000000..cebd8e1eb098
--- /dev/null
+++ b/lib/libc/i386/gen/flt_rounds.c
@@ -0,0 +1,22 @@
+/*
+ * Written by J.T. Conklin, Apr 10, 1995
+ * Public domain.
+ */
+
+#include <float.h>
+
+static const int map[] = {
+ 1, /* round to nearest */
+ 3, /* round to zero */
+ 2, /* round to negative infinity */
+ 0 /* round to positive infinity */
+};
+
+int
+__flt_rounds(void)
+{
+ int x;
+
+ __asm("fnstcw %0" : "=m" (x));
+ return (map[(x >> 10) & 0x03]);
+}