Back to index

glibc  2.9
Functions | Variables
s_lrintl.c File Reference
#include <math.h>
#include "math_private.h"

Go to the source code of this file.

Functions

long int __lrintl (long double x)

Variables

static const long double two63 [2]

Function Documentation

long int __lrintl ( long double  x)

Definition at line 34 of file s_lrintl.c.

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

  GET_LDOUBLE_WORDS (se, i0, i1, x);

  sx = (se >> 15) & 1;
  j0 = (se & 0x7fff) - 0x3fff;

  if (j0 < 31)
    {
      w = two63[sx] + x;
      t = w - two63[sx];
      GET_LDOUBLE_WORDS (se, i0, i1, t);
      j0 = (se & 0x7fff) - 0x3fff;

      result = (j0 < 0 ? 0 : i0 >> (31 - j0));
    }
  else if (j0 < (int32_t) (8 * sizeof (long int)) - 1)
    {
      if (j0 >= 63)
       result = ((long int) i0 << (j0 - 31)) | (i1 << (j0 - 63));
      else
       {
         w = two63[sx] + x;
         t = w - two63[sx];
         GET_LDOUBLE_WORDS (se, i0, i1, t);
         j0 = (se & 0x7fff) - 0x3fff;

         if (j0 == 31)
           result = (long int) i0;
         else
           result = ((long int) i0 << (j0 - 31)) | (i1 >> (63 - j0));
       }
    }
  else
    {
      /* The number is too large.  It is left implementation defined
        what happens.  */
      return (long int) x;
    }

  return sx ? -result : result;
}

Here is the call graph for this function:


Variable Documentation

const long double two63[2] [static]
Initial value:
{
  9.223372036854775808000000e+18, 
 -9.223372036854775808000000e+18  
}

Definition at line 26 of file s_lrintl.c.