Back to index

glibc  2.9
Functions | Variables
s_llrint.c File Reference
#include <math.h>
#include "math_private.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

long long int __llrint (double x)

Variables

static const double two52 [2]

Function Documentation

long long int __llrint ( double  x)

Definition at line 34 of file s_llrint.c.

{
  int32_t j0;
  u_int32_t i1, i0;
  long long int result;
  volatile double w;
  double t;
  int sx;

  EXTRACT_WORDS (i0, i1, x);
  j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
  sx = i0 >> 31;
  i0 &= 0xfffff;
  i0 |= 0x100000;

  if (j0 < 20)
    {
      w = two52[sx] + x;
      t = w - two52[sx];
      EXTRACT_WORDS (i0, i1, t);
      j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
      i0 &= 0xfffff;
      i0 |= 0x100000;

      result = (j0 < 0 ? 0 : i0 >> (20 - j0));
    }
  else if (j0 < (int32_t) (8 * sizeof (long long int)) - 1)
    {
      if (j0 >= 52)
       result = (((long long int) i0 << 32) | 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 long int) i0;
         else
           result = ((long long int) i0 << (j0 - 20)) | (i1 >> (52 - j0));
       }
    }
  else
    {
      /* The number is too large.  It is left implementation defined
        what happens.  */
      return (long long int) x;
    }

  return sx ? -result : result;
}

Here is the call graph for this function:


Variable Documentation

const double two52[2] [static]
Initial value:
{
  4.50359962737049600000e+15, 
 -4.50359962737049600000e+15, 
}

Definition at line 26 of file s_llrint.c.