source: azure_iot_hub/trunk/musl-1.1.18/src/math/rint.c@ 388

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

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 489 bytes
Line 
1#include <float.h>
2#include <math.h>
3#include <stdint.h>
4
5#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
6#define EPS DBL_EPSILON
7#elif FLT_EVAL_METHOD==2
8#define EPS LDBL_EPSILON
9#endif
10static const double_t toint = 1/EPS;
11
12double rint(double x)
13{
14 union {double f; uint64_t i;} u = {x};
15 int e = u.i>>52 & 0x7ff;
16 int s = u.i>>63;
17 double_t y;
18
19 if (e >= 0x3ff+52)
20 return x;
21 if (s)
22 y = x - toint + toint;
23 else
24 y = x + toint - toint;
25 if (y == 0)
26 return s ? -0.0 : 0;
27 return y;
28}
Note: See TracBrowser for help on using the repository browser.