Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 1 | #include <fenv.h> |
nsz | 9560b6b | 2012-03-13 19:51:14 +0100 | [diff] [blame] | 2 | #include <math.h> |
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 3 | |
nsz | 91c28f6 | 2012-03-20 22:49:19 +0100 | [diff] [blame] | 4 | float nearbyintf(float x) |
5 | { | ||||
6 | #ifdef FE_INEXACT | ||||
Szabolcs Nagy | 033a9d6 | 2012-11-13 13:34:45 +0100 | [diff] [blame] | 7 | #pragma STDC FENV_ACCESS ON |
nsz | 91c28f6 | 2012-03-20 22:49:19 +0100 | [diff] [blame] | 8 | int e; |
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 9 | |
nsz | 91c28f6 | 2012-03-20 22:49:19 +0100 | [diff] [blame] | 10 | e = fetestexcept(FE_INEXACT); |
11 | #endif | ||||
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 12 | x = rintf(x); |
nsz | 91c28f6 | 2012-03-20 22:49:19 +0100 | [diff] [blame] | 13 | #ifdef FE_INEXACT |
14 | if (!e) | ||||
15 | feclearexcept(FE_INEXACT); | ||||
16 | #endif | ||||
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 17 | return x; |
18 | } |