source: azure_iot_hub/trunk/musl-1.1.18/src/math/lrint.c@ 389

Last change on this file since 389 was 389, checked in by coas-nagasima, 5 years ago

ビルドが通るよう更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 1.1 KB
Line 
1#include <limits.h>
2#include <fenv.h>
3#include "libm.h"
4
5/*
6If the result cannot be represented (overflow, nan), then
7lrint raises the invalid exception.
8
9Otherwise if the input was not an integer then the inexact
10exception is raised.
11
12C99 is a bit vague about whether inexact exception is
13allowed to be raised when invalid is raised.
14(F.9 explicitly allows spurious inexact exceptions, F.9.6.5
15does not make it clear if that rule applies to lrint, but
16IEEE 754r 7.8 seems to forbid spurious inexact exception in
17the ineger conversion functions)
18
19So we try to make sure that no spurious inexact exception is
20raised in case of an overflow.
21
22If the bit size of long > precision of double, then there
23cannot be inexact rounding in case the result overflows,
24otherwise LONG_MAX and LONG_MIN can be represented exactly
25as a double.
26*/
27
28#if LONG_MAX < 1U<<53 && defined(FE_INEXACT)
29long lrint(double x)
30{
31 #pragma STDC FENV_ACCESS ON
32 int e;
33
34 e = fetestexcept(FE_INEXACT);
35 x = rint(x);
36 if (!e && (x > LONG_MAX || x < LONG_MIN))
37 feclearexcept(FE_INEXACT);
38 /* conversion */
39 return x;
40}
41#else
42long lrint(double x)
43{
44 return rint(x);
45}
46#endif
Note: See TracBrowser for help on using the repository browser.