Back to index

glibc  2.9
Functions
erand48_r.c File Reference
#include <ieee754.h>
#include <stdlib.h>
#include <limits.h>

Go to the source code of this file.

Functions

int __erand48_r (xsubi, struct drand48_data *buffer, double *result)

Function Documentation

int __erand48_r ( xsubi  ,
struct drand48_data *  buffer,
double *  result 
)

Definition at line 26 of file erand48_r.c.

{
  union ieee754_double temp;

  /* Compute next state.  */
  if (__drand48_iterate (xsubi, buffer) < 0)
    return -1;

  /* Construct a positive double with the 48 random bits distributed over
     its fractional part so the resulting FP number is [0.0,1.0).  */

  temp.ieee.negative = 0;
  temp.ieee.exponent = IEEE754_DOUBLE_BIAS;
  temp.ieee.mantissa0 = (xsubi[2] << 4) | (xsubi[1] >> 12);
  temp.ieee.mantissa1 = ((xsubi[1] & 0xfff) << 20) | (xsubi[0] << 4);

  /* Please note the lower 4 bits of mantissa1 are always 0.  */
  *result = temp.d - 1.0;

  return 0;
}

Here is the call graph for this function: