1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include <features.h>
- #undef __USE_EXTERN_INLINES
- #include <math.h>
- #include "math_private.h"
- static const double two52[2] =
- {
- 4.50359962737049600000e+15,
- -4.50359962737049600000e+15,
- };
- long int
- lrint (double x)
- {
- int32_t j0;
- u_int32_t i0,i1;
- volatile double w;
- double t;
- long int result;
- int sx;
- EXTRACT_WORDS (i0, i1, x);
- j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
- sx = i0 >> 31;
- i0 &= 0xfffff;
- i0 |= 0x100000;
- if (j0 < 20)
- {
- if (j0 < -1)
- return 0;
- else
- {
- w = two52[sx] + x;
- t = w - two52[sx];
- EXTRACT_WORDS (i0, i1, t);
- j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
- i0 &= 0xfffff;
- i0 |= 0x100000;
- result = i0 >> (20 - j0);
- }
- }
- else if (j0 < (int32_t) (8 * sizeof (long int)) - 1)
- {
- if (j0 >= 52)
- result = ((long int) i0 << (j0 - 20)) | (i1 << (j0 - 52));
- else
- {
- w = two52[sx] + x;
- t = w - two52[sx];
- EXTRACT_WORDS (i0, i1, t);
- j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
- i0 &= 0xfffff;
- i0 |= 0x100000;
- if (j0 == 20)
- result = (long int) i0;
- else
- result = ((long int) i0 << (j0 - 20)) | (i1 >> (52 - j0));
- }
- }
- else
- {
-
- return (long int) x;
- }
- return sx ? -result : result;
- }
- libm_hidden_def(lrint)
|