this repo has no description
1
2/*
3 * rint.c
4 *
5 * by Ian Ollmann
6 *
7 * Copyright (c) 2007, Apple Inc. All rights Reserved.
8 *
9 * C99 implementation of rint.
10 */
11
12#include <math.h>
13#include <stdint.h>
14
15double rint( double x )
16{
17 union{ double d; uint64_t u;}u = {x};
18 uint64_t absux = u.u & 0x7fffffffffffffffULL;
19
20 //special case code for large int, Inf, NaN, 0
21 if( absux - 1LL >= 0x4330000000000000ULL - 1LL )
22 return x;
23
24 u.u = (u.u & 0x8000000000000000ULL) | 0x4330000000000000ULL; //copysign( 0x1.0p23f, x )
25
26 x += u.d;
27 x -= u.d;
28
29 return x;
30}