Back to index

nagios-plugins  1.4.16
Defines | Functions | Variables
floor.c File Reference
#include <config.h>
#include <math.h>
#include <float.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define FUNC   floor
#define DOUBLE   double
#define MANT_DIG   DBL_MANT_DIG
#define L_(literal)   literal

Functions

DOUBLE FUNC (DOUBLE x)

Variables

static const DOUBLE TWO_MANT_DIG

Define Documentation

#define DOUBLE   double

Definition at line 33 of file floor.c.

#define FUNC   floor

Definition at line 32 of file floor.c.

#define L_ (   literal)    literal

Definition at line 35 of file floor.c.

#define MANT_DIG   DBL_MANT_DIG

Definition at line 34 of file floor.c.


Function Documentation

DOUBLE FUNC ( DOUBLE  x)

Definition at line 55 of file floor.c.

{
  /* The use of 'volatile' guarantees that excess precision bits are dropped
     at each addition step and before the following comparison at the caller's
     site.  It is necessary on x86 systems where double-floats are not IEEE
     compliant by default, to avoid that the results become platform and compiler
     option dependent.  'volatile' is a portable alternative to gcc's
     -ffloat-store option.  */
  volatile DOUBLE y = x;
  volatile DOUBLE z = y;

  if (z > L_(0.0))
    {
      /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1.  */
      if (z < TWO_MANT_DIG)
        {
          /* Round to the next integer (nearest or up or down, doesn't matter).  */
          z += TWO_MANT_DIG;
          z -= TWO_MANT_DIG;
          /* Enforce rounding down.  */
          if (z > y)
            z -= L_(1.0);
        }
    }
  else if (z < L_(0.0))
    {
      /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1.  */
      if (z > - TWO_MANT_DIG)
        {
          /* Round to the next integer (nearest or up or down, doesn't matter).  */
          z -= TWO_MANT_DIG;
          z += TWO_MANT_DIG;
          /* Enforce rounding down.  */
          if (z > y)
            z -= L_(1.0);
        }
    }
  return z;
}

Variable Documentation

Initial value:
  
  (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
  * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
  * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
  * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
  * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5))

Definition at line 44 of file floor.c.