Esempio n. 1
0
/* wrapper remainder */
double
__remainder (double x, double y)
{
  if (((__builtin_expect (y == 0.0, 0) && ! __isnan (x))
       || (__builtin_expect (__isinf_ns (x), 0) && ! __isnan (y)))
      && _LIB_VERSION != _IEEE_)
    return __kernel_standard (x, y, 28); /* remainder domain */

  return __ieee754_remainder (x, y);
}
Esempio n. 2
0
/* wrapper pow */
double
__pow (double x, double y)
{
  double z = __ieee754_pow (x, y);
  if (__builtin_expect (!__finite (z), 0))
    {
      if (_LIB_VERSION != _IEEE_)
	{
	  if (__isnan (x))
	    {
	      if (y == 0.0)
		/* pow(NaN,0.0) */
		return __kernel_standard (x, y, 42);
	    }
	  else if (__finite (x) && __finite (y))
	    {
	      if (__isnan (z))
		/* pow neg**non-int */
		return __kernel_standard (x, y, 24);
	      else if (x == 0.0 && y < 0.0)
		{
		  if (signbit (x) && signbit (z))
		    /* pow(-0.0,negative) */
		    return __kernel_standard (x, y, 23);
		  else
		    /* pow(+0.0,negative) */
		    return __kernel_standard (x, y, 43);
		}
	      else
		/* pow overflow */
		return __kernel_standard (x, y, 21);
	    }
	}
    }
  else if (__builtin_expect (z == 0.0, 0) && __finite (x) && __finite (y)
	   && _LIB_VERSION != _IEEE_)
    {
      if (x == 0.0)
	{
	  if (y == 0.0)
	    /* pow(0.0,0.0) */
	    return __kernel_standard (x, y, 20);
	}
      else
	/* pow underflow */
	return __kernel_standard (x, y, 22);
    }

  return z;
}
Esempio n. 3
0
int main(void) {
  double NaN = 0.0 / 0.0;
  double Inf = 1.0 / 0.0;
  double negInf = -1.0 / 0.0;

  double x = 2.0;
  double y = -8.5;

  double a = 5.1;
  double b = -3.0;
  double c = fmod(a, b);
  assert(fabs(c - 2.1) < 1e-8);

  if (!__isnan(y)) {
    assert(__isnan(fmod(Inf, y)));
    assert(__isnan(fmod(negInf, y)));
  }

  if (!__isnan(x)) {
    assert(__isnan(fmod(x, 0.0)));
    assert(__isnan(fmod(x, -0.0)));
  }

  
  if (!__isnan(x) && !__isinf(x)) {
    assert(fmod(x, Inf) == x);
    assert(fmod(x, negInf) == x);
  }
 
  if (!__isnan(y) && !__iszero(y)) {
    assert(fmod(0.0, y) == 0.0);
    assert(fmod(-0.0, y) == -0.0);
    int isNeg = __signbit(fmod(-0.0, y));
    assert(isNeg);
  }
 
  assert(__isnan(fmod(NaN, y)));
  assert(__isnan(fmod(x, NaN)));

  return 0;
}
Esempio n. 4
0
__complex__ double
__ccos (__complex__ double x)
{
  __complex__ double res;

  if (!isfinite (__real__ x) || __isnan (__imag__ x))
    {
      if (__real__ x == 0.0 || __imag__ x == 0.0)
	{
	  __real__ res = __nan ("");
	  __imag__ res = 0.0;

#ifdef FE_INVALID
	  if (__isinf (__real__ x))
	    feraiseexcept (FE_INVALID);
#endif
	}
      else if (__isinf (__imag__ x))
	{
	  __real__ res = HUGE_VAL;
	  __imag__ res = __nan ("");

#ifdef FE_INVALID
	  if (__isinf (__real__ x))
	    feraiseexcept (FE_INVALID);
#endif
	}
      else
	{
	  __real__ res = __nan ("");
	  __imag__ res = __nan ("");

#ifdef FE_INVALID
	  if (isfinite (__imag__ x))
	    feraiseexcept (FE_INVALID);
#endif
	}
    }
  else
    {
      __complex__ double y;

      __real__ y = -__imag__ x;
      __imag__ y = __real__ x;

      res = __ccosh (y);
    }

  return res;
}
Esempio n. 5
0
unsigned int write_grid_image(GRID_TYPE *output_image, GRID_TYPE fill, size_t grid_cols, size_t grid_rows,
        accum_type *grid_accum, weight_type *grid_weights,
        int maximum_weight_mode, weight_type weight_sum_min) {
  accum_type chanf;
  unsigned int i;
  unsigned int valid_count = 0;
  size_t grid_size = grid_cols * grid_rows;

  if (weight_sum_min <= 0.0) {
    weight_sum_min = EPSILON;
  }

  for (i=0; i < grid_size;
       i++, grid_accum++, grid_weights++, output_image++) {
    // Calculate the elliptical weighted average value for each cell (float -> not-float needs rounding)
    // The fill value for the weight and accumulation arrays is static at NaN
    if (*grid_weights < weight_sum_min || __isnan(*grid_accum)) {
      chanf = (accum_type)NPY_NANF;
    } else if (maximum_weight_mode) {
      // keep the current value
      chanf = *grid_accum;
    } else if (*grid_accum >= 0.0) {
      chanf = *grid_accum / *grid_weights + get_rounding(output_image);
    } else {
      chanf = *grid_accum / *grid_weights - get_rounding(output_image);
    }

    if (__isnan(chanf)) {
      *output_image = (GRID_TYPE)fill;
    } else {
      valid_count++;
      write_grid_pixel(output_image, chanf);
    }
  }

  return valid_count;
}
Esempio n. 6
0
int main(void) {
  double NaN = 0.0 / 0.0;
  double Inf = 1.0 / 0.0;
  double negInf = -1.0 / 0.0;

  double val = __VERIFIER_nondet_double();

  if (!__isnan(val) && !__isinf(val) && !__iszero(val)) {
    double rval = round(val);
    assert(rval == floor(val) || rval == ceil(val));
  }

  assert(round(0.0) == 0.0);
  assert(round(-0.0) == -0.0);
  int isNeg = __signbit(round(-0.0));
  assert(isNeg);

  assert(round(Inf) == Inf);
  assert(round(negInf) == negInf);

  assert(__isnan(round(NaN)));

  return 0;
}
Esempio n. 7
0
int main()
{
  double a = __VERIFIER_nondet_double();
  __VERIFIER_assume(!__isnan(a));
  __VERIFIER_assume(!__isinf(a));
  __VERIFIER_assume(a != 0.0);

  double plus_zero = 0.0;
  double plus_zero_mod = fmod(plus_zero, a);
  _Bool plus_zero_mod_sign = __signbit(plus_zero);
  __VERIFIER_assert((plus_zero_mod == 0.0) && !plus_zero_mod_sign);

  double minus_zero = -0.0;
  double minus_zero_mod = fmod(minus_zero, a);
  _Bool minus_zero_mod_sign = signbit(minus_zero);
  __VERIFIER_assert((minus_zero_mod == 0.0) && minus_zero_mod_sign);

  return 0;
}
Esempio n. 8
0
int
__printf_fphex (FILE *fp,
		const struct printf_info *info,
		const void *const *args)
{
  /* The floating-point value to output.  */
  union
    {
      union ieee754_double dbl;
      long double ldbl;
    }
  fpnum;

  /* Locale-dependent representation of decimal point.	*/
  const char *decimal;
  wchar_t decimalwc;

  /* "NaN" or "Inf" for the special cases.  */
  const char *special = NULL;
  const wchar_t *wspecial = NULL;

  /* Buffer for the generated number string for the mantissa.  The
     maximal size for the mantissa is 128 bits.  */
  char numbuf[32];
  char *numstr;
  char *numend;
  wchar_t wnumbuf[32];
  wchar_t *wnumstr;
  wchar_t *wnumend;
  int negative;

  /* The maximal exponent of two in decimal notation has 5 digits.  */
  char expbuf[5];
  char *expstr;
  wchar_t wexpbuf[5];
  wchar_t *wexpstr;
  int expnegative;
  int exponent;

  /* Non-zero is mantissa is zero.  */
  int zero_mantissa;

  /* The leading digit before the decimal point.  */
  char leading;

  /* Precision.  */
  int precision = info->prec;

  /* Width.  */
  int width = info->width;

  /* Number of characters written.  */
  int done = 0;

  /* Nonzero if this is output on a wide character stream.  */
#if __OPTION_POSIX_C_LANG_WIDE_CHAR
  int wide = info->wide;
#else
  /* This should never be called on a wide-oriented stream when
     OPTION_POSIX_C_LANG_WIDE_CHAR is disabled, but the compiler can't
     be trusted to figure that out.  */
  const int wide = 0;
#endif


  /* Figure out the decimal point character.  */
#if __OPTION_EGLIBC_LOCALE_CODE
  if (info->extra == 0)
    {
      decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
      decimalwc = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC);
    }
  else
    {
      decimal = _NL_CURRENT (LC_MONETARY, MON_DECIMAL_POINT);
      decimalwc = _NL_CURRENT_WORD (LC_MONETARY,
				    _NL_MONETARY_DECIMAL_POINT_WC);
    }
  /* The decimal point character must never be zero.  */
  assert (*decimal != '\0' && decimalwc != L'\0');
#else
  decimal = ".";
  decimalwc = L'.';
#endif


  /* Fetch the argument value.	*/
#ifndef __NO_LONG_DOUBLE_MATH
  if (info->is_long_double && sizeof (long double) > sizeof (double))
    {
      fpnum.ldbl = *(const long double *) args[0];

      /* Check for special values: not a number or infinity.  */
      if (__isnanl (fpnum.ldbl))
	{
	  if (isupper (info->spec))
	    {
	      special = "NAN";
	      wspecial = L"NAN";
	    }
	  else
	    {
	      special = "nan";
	      wspecial = L"nan";
	    }
	}
      else
	{
	  if (__isinfl (fpnum.ldbl))
	    {
	      if (isupper (info->spec))
		{
		  special = "INF";
		  wspecial = L"INF";
		}
	      else
		{
		  special = "inf";
		  wspecial = L"inf";
		}
	    }
	}
      negative = signbit (fpnum.ldbl);
    }
  else
#endif	/* no long double */
    {
      fpnum.dbl.d = *(const double *) args[0];

      /* Check for special values: not a number or infinity.  */
      if (__isnan (fpnum.dbl.d))
	{
	  negative = fpnum.dbl.ieee.negative != 0;
	  if (isupper (info->spec))
	    {
	      special = "NAN";
	      wspecial = L"NAN";
	    }
	  else
	    {
	      special = "nan";
	      wspecial = L"nan";
	    }
	}
      else
	{
	  int res = __isinf (fpnum.dbl.d);
	  if (res)
	    {
	      if (isupper (info->spec))
		{
		  special = "INF";
		  wspecial = L"INF";
		}
	      else
		{
		  special = "inf";
		  wspecial = L"inf";
		}
	      negative = res < 0;
	    }
	  else
	    negative = signbit (fpnum.dbl.d);
	}
    }

  if (special)
    {
      int width = info->width;

      if (negative || info->showsign || info->space)
	--width;
      width -= 3;

      if (!info->left && width > 0)
	PADN (' ', width);

      if (negative)
	outchar ('-');
      else if (info->showsign)
	outchar ('+');
      else if (info->space)
	outchar (' ');

      PRINT (special, wspecial, 3);

      if (info->left && width > 0)
	PADN (' ', width);

      return done;
    }

  if (info->is_long_double == 0 || sizeof (double) == sizeof (long double))
    {
      /* We have 52 bits of mantissa plus one implicit digit.  Since
	 52 bits are representable without rest using hexadecimal
	 digits we use only the implicit digits for the number before
	 the decimal point.  */
      unsigned long long int num;

      num = (((unsigned long long int) fpnum.dbl.ieee.mantissa0) << 32
	     | fpnum.dbl.ieee.mantissa1);

      zero_mantissa = num == 0;

      if (sizeof (unsigned long int) > 6)
	{
	  wnumstr = _itowa_word (num, wnumbuf + (sizeof wnumbuf) / sizeof (wchar_t), 16,
				 info->spec == 'A');
	  numstr = _itoa_word (num, numbuf + sizeof numbuf, 16,
			       info->spec == 'A');
	}
      else
	{
	  wnumstr = _itowa (num, wnumbuf + sizeof wnumbuf / sizeof (wchar_t), 16,
			    info->spec == 'A');
	  numstr = _itoa (num, numbuf + sizeof numbuf, 16,
			  info->spec == 'A');
	}

      /* Fill with zeroes.  */
      while (wnumstr > wnumbuf + (sizeof wnumbuf - 52) / sizeof (wchar_t))
	{
	  *--wnumstr = L'0';
	  *--numstr = '0';
	}

      leading = fpnum.dbl.ieee.exponent == 0 ? '0' : '1';

      exponent = fpnum.dbl.ieee.exponent;

      if (exponent == 0)
	{
	  if (zero_mantissa)
	    expnegative = 0;
	  else
	    {
	      /* This is a denormalized number.  */
	      expnegative = 1;
	      exponent = IEEE754_DOUBLE_BIAS - 1;
	    }
	}
      else if (exponent >= IEEE754_DOUBLE_BIAS)
	{
	  expnegative = 0;
	  exponent -= IEEE754_DOUBLE_BIAS;
	}
      else
	{
	  expnegative = 1;
	  exponent = -(exponent - IEEE754_DOUBLE_BIAS);
	}
    }
#ifdef PRINT_FPHEX_LONG_DOUBLE
  else
    PRINT_FPHEX_LONG_DOUBLE;
#endif

  /* Look for trailing zeroes.  */
  if (! zero_mantissa)
    {
      wnumend = &wnumbuf[sizeof wnumbuf / sizeof wnumbuf[0]];
      numend = &numbuf[sizeof numbuf / sizeof numbuf[0]];
      while (wnumend[-1] == L'0')
	{
	  --wnumend;
	  --numend;
	}

      bool do_round_away = false;

      if (precision != -1 && precision < numend - numstr)
	{
	  char last_digit = precision > 0 ? numstr[precision - 1] : leading;
	  char next_digit = numstr[precision];
	  int last_digit_value = (last_digit >= 'A' && last_digit <= 'F'
				  ? last_digit - 'A' + 10
				  : (last_digit >= 'a' && last_digit <= 'f'
				     ? last_digit - 'a' + 10
				     : last_digit - '0'));
	  int next_digit_value = (next_digit >= 'A' && next_digit <= 'F'
				  ? next_digit - 'A' + 10
				  : (next_digit >= 'a' && next_digit <= 'f'
				     ? next_digit - 'a' + 10
				     : next_digit - '0'));
	  bool more_bits = ((next_digit_value & 7) != 0
			    || precision + 1 < numend - numstr);
	  int rounding_mode = get_rounding_mode ();
	  do_round_away = round_away (negative, last_digit_value & 1,
				      next_digit_value >= 8, more_bits,
				      rounding_mode);
	}

      if (precision == -1)
	precision = numend - numstr;
      else if (do_round_away)
	{
	  /* Round up.  */
	  int cnt = precision;
	  while (--cnt >= 0)
	    {
	      char ch = numstr[cnt];
	      /* We assume that the digits and the letters are ordered
		 like in ASCII.  This is true for the rest of GNU, too.  */
	      if (ch == '9')
		{
		  wnumstr[cnt] = (wchar_t) info->spec;
		  numstr[cnt] = info->spec;	/* This is tricky,
						   think about it!  */
		  break;
		}
	      else if (tolower (ch) < 'f')
		{
		  ++numstr[cnt];
		  ++wnumstr[cnt];
		  break;
		}
	      else
		{
		  numstr[cnt] = '0';
		  wnumstr[cnt] = L'0';
		}
	    }
	  if (cnt < 0)
	    {
	      /* The mantissa so far was fff...f  Now increment the
		 leading digit.  Here it is again possible that we
		 get an overflow.  */
	      if (leading == '9')
		leading = info->spec;
	      else if (tolower (leading) < 'f')
		++leading;
	      else
		{
		  leading = '1';
		  if (expnegative)
		    {
		      exponent -= 4;
		      if (exponent <= 0)
			{
			  exponent = -exponent;
			  expnegative = 0;
			}
		    }
		  else
		    exponent += 4;
		}
	    }
	}
    }
  else
    {
      if (precision == -1)
	precision = 0;
      numend = numstr;
      wnumend = wnumstr;
    }

  /* Now we can compute the exponent string.  */
  expstr = _itoa_word (exponent, expbuf + sizeof expbuf, 10, 0);
  wexpstr = _itowa_word (exponent,
			 wexpbuf + sizeof wexpbuf / sizeof (wchar_t), 10, 0);

  /* Now we have all information to compute the size.  */
  width -= ((negative || info->showsign || info->space)
	    /* Sign.  */
	    + 2    + 1 + 0 + precision + 1 + 1
	    /* 0x    h   .   hhh         P   ExpoSign.  */
	    + ((expbuf + sizeof expbuf) - expstr));
	    /* Exponent.  */

  /* Count the decimal point.
     A special case when the mantissa or the precision is zero and the `#'
     is not given.  In this case we must not print the decimal point.  */
  if (precision > 0 || info->alt)
    width -= wide ? 1 : strlen (decimal);

  if (!info->left && info->pad != '0' && width > 0)
    PADN (' ', width);

  if (negative)
    outchar ('-');
  else if (info->showsign)
    outchar ('+');
  else if (info->space)
    outchar (' ');

  outchar ('0');
  if ('X' - 'A' == 'x' - 'a')
    outchar (info->spec + ('x' - 'a'));
  else
    outchar (info->spec == 'A' ? 'X' : 'x');

  if (!info->left && info->pad == '0' && width > 0)
    PADN ('0', width);

  outchar (leading);

  if (precision > 0 || info->alt)
    {
      const wchar_t *wtmp = &decimalwc;
      PRINT (decimal, wtmp, wide ? 1 : strlen (decimal));
    }

  if (precision > 0)
    {
      ssize_t tofill = precision - (numend - numstr);
      PRINT (numstr, wnumstr, MIN (numend - numstr, precision));
      if (tofill > 0)
	PADN ('0', tofill);
    }

  if ('P' - 'A' == 'p' - 'a')
    outchar (info->spec + ('p' - 'a'));
  else
    outchar (info->spec == 'A' ? 'P' : 'p');

  outchar (expnegative ? '-' : '+');

  PRINT (expstr, wexpstr, (expbuf + sizeof expbuf) - expstr);

  if (info->left && info->pad != '0' && width > 0)
    PADN (info->pad, width);

  return done;
}
Esempio n. 9
0
double
fmin (double _x, double _y)
{
  return ((islessequal(_x, _y) || __isnan (_y)) ? _x : _y );
}
Esempio n. 10
0
int
__printf_size (FILE *fp, const struct printf_info *info,
	       const void *const *args)
{
  /* Units for the both formats.  */
#define BINARY_UNITS	" kmgtpezy"
#define DECIMAL_UNITS	" KMGTPEZY"
  static const char units[2][sizeof (BINARY_UNITS)] =
  {
    BINARY_UNITS,	/* For binary format.  */
    DECIMAL_UNITS	/* For decimal format.  */
  };
  const char *tag = units[isupper (info->spec) != 0];
  int divisor = isupper (info->spec) ? 1000 : 1024;

  /* The floating-point value to output.  */
  union
    {
      union ieee754_double dbl;
      union ieee854_long_double ldbl;
    }
  fpnum;
  const void *ptr = &fpnum;

  int fpnum_sign = 0;

  /* "NaN" or "Inf" for the special cases.  */
  const char *special = NULL;
  const wchar_t *wspecial = NULL;

  struct printf_info fp_info;
  int done = 0;
#if __OPTION_POSIX_C_LANG_WIDE_CHAR
  int wide = info->wide;
#else
  /* This should never be called on a wide-oriented stream when
     OPTION_POSIX_C_LANG_WIDE_CHAR is disabled, but the compiler can't
     be trusted to figure that out.  */
  const int wide = 0;
#endif
  int res;

  /* Fetch the argument value.	*/
#ifndef __NO_LONG_DOUBLE_MATH
  if (info->is_long_double && sizeof (long double) > sizeof (double))
    {
      fpnum.ldbl.d = *(const long double *) args[0];

      /* Check for special values: not a number or infinity.  */
      if (__isnanl (fpnum.ldbl.d))
	{
	  special = "nan";
	  wspecial = L"nan";
	  // fpnum_sign = 0;	Already zero
	}
      else if ((res = __isinfl (fpnum.ldbl.d)))
	{
	  fpnum_sign = res;
	  special = "inf";
	  wspecial = L"inf";
	}
      else
	while (fpnum.ldbl.d >= divisor && tag[1] != '\0')
	  {
	    fpnum.ldbl.d /= divisor;
	    ++tag;
	  }
    }
  else
#endif	/* no long double */
    {
      fpnum.dbl.d = *(const double *) args[0];

      /* Check for special values: not a number or infinity.  */
      if (__isnan (fpnum.dbl.d))
	{
	  special = "nan";
	  wspecial = L"nan";
	  // fpnum_sign = 0;	Already zero
	}
      else if ((res = __isinf (fpnum.dbl.d)))
	{
	  fpnum_sign = res;
	  special = "inf";
	  wspecial = L"inf";
	}
      else
	while (fpnum.dbl.d >= divisor && tag[1] != '\0')
	  {
	    fpnum.dbl.d /= divisor;
	    ++tag;
	  }
    }

  if (special)
    {
      int width = info->prec > info->width ? info->prec : info->width;

      if (fpnum_sign < 0 || info->showsign || info->space)
	--width;
      width -= 3;

      if (!info->left && width > 0)
	PADN (' ', width);

      if (fpnum_sign < 0)
	outchar ('-');
      else if (info->showsign)
	outchar ('+');
      else if (info->space)
	outchar (' ');

      PRINT (special, wspecial, 3);

      if (info->left && width > 0)
	PADN (' ', width);

      return done;
    }

  /* Prepare to print the number.  We want to use `__printf_fp' so we
     have to prepare a `printf_info' structure.  */
  fp_info = *info;
  fp_info.spec = 'f';
  fp_info.prec = info->prec < 0 ? 3 : info->prec;
  fp_info.wide = wide;

  if (fp_info.left && fp_info.pad == L' ')
    {
      /* We must do the padding ourself since the unit character must
	 be placed before the padding spaces.  */
      fp_info.width = 0;

      done = __printf_fp (fp, &fp_info, &ptr);
      if (done > 0)
	{
	  outchar (*tag);
	  if (info->width > done)
	    PADN (' ', info->width - done);
	}
    }
  else
    {
      /* We can let __printf_fp do all the printing and just add our
	 unit character afterwards.  */
      fp_info.width = info->width - 1;

      done = __printf_fp (fp, &fp_info, &ptr);
      if (done > 0)
	outchar (*tag);
    }

  return done;
}
Esempio n. 11
0
int check_nan_gauge(const int i, const int mu) {
  su3 * um;
  
  um = &g_gauge_field[i][mu];
  if(__isnan((*um).c00.re)|| __isnan((*um).c00.im) || __isnan((*um).c01.re) || __isnan((*um).c01.im) ||
     __isnan((*um).c02.re) || __isnan((*um).c02.im) || __isnan((*um).c10.re) || __isnan((*um).c10.im) ||
     __isnan((*um).c11.re) || __isnan((*um).c11.im) || __isnan((*um).c12.re) || __isnan((*um).c12.im) ||
     __isnan((*um).c20.re) || __isnan((*um).c20.im) || __isnan((*um).c21.re) || __isnan((*um).c21.im) ||
     __isnan((*um).c22.re) || __isnan((*um).c22.im)) {
    return(i);
  }
  return(-1);
}
Esempio n. 12
0
int check_nan() {
  int i, mu;
  su3 * um;
  
  um = &g_gauge_field[0][0];
  for(i = 0; i < VOLUMEPLUSRAND; i++) {
    for(mu = 0; mu < 4; mu++) {
      if(__isnan((*um).c00.re)|| __isnan((*um).c00.im) || __isnan((*um).c01.re) || __isnan((*um).c01.im) ||
	 __isnan((*um).c02.re) || __isnan((*um).c02.im) || __isnan((*um).c10.re) || __isnan((*um).c10.im) ||
	 __isnan((*um).c11.re) || __isnan((*um).c11.im) || __isnan((*um).c12.re) || __isnan((*um).c12.im) ||
	 __isnan((*um).c20.re) || __isnan((*um).c20.im) || __isnan((*um).c21.re) || __isnan((*um).c21.im) ||
	 __isnan((*um).c22.re) || __isnan((*um).c22.im)) {
	return(i);
      }
      um++;
    }
  }
  return(-1);
}
int
attribute_hidden
__isnanl (double x)
{
  return __isnan (x);
}
Esempio n. 14
0
double
fmax (double _x, double _y)
{
   return ( isgreaterequal (_x, _y)|| __isnan (_y) ?  _x : _y );
}
__MATH_FUNCTIONS_DBL_PTX3_DECL__ int __isnanl(/* we do not support long double yet, hence double */double a)
{
  return __isnan((double)a);
}
Esempio n. 16
0
int
printf_size (FILE *fp, const struct printf_info *info, const void *const *args)
{
  /* Units for the both formats.  */
#define BINARY_UNITS	" kmgtpezy"
#define DECIMAL_UNITS	" KMGTPEZY"
  static const char units[2][sizeof (BINARY_UNITS)] =
  {
    BINARY_UNITS,	/* For binary format.  */
    DECIMAL_UNITS	/* For decimal format.  */
  };
  const char *tag = units[isupper (info->spec) != 0];
  int divisor = isupper (info->spec) ? 1000 : 1024;

  /* The floating-point value to output.  */
  union
    {
      union ieee754_double dbl;
      union ieee854_long_double ldbl;
    }
  fpnum;
  const void *ptr = &fpnum;

  int negative = 0;

  /* "NaN" or "Inf" for the special cases.  */
  const char *special = NULL;
  const wchar_t *wspecial = NULL;

  struct printf_info fp_info;
  int done = 0;
  int wide = info->wide;


  /* Fetch the argument value.	*/
#ifndef __NO_LONG_DOUBLE_MATH
  if (info->is_long_double && sizeof (long double) > sizeof (double))
    {
      fpnum.ldbl.d = *(const long double *) args[0];

      /* Check for special values: not a number or infinity.  */
      if (__isnanl (fpnum.ldbl.d))
	{
	  special = "nan";
	  wspecial = L"nan";
	  negative = 0;
	}
      else if (__isinfl (fpnum.ldbl.d))
	{
	  special = "inf";
	  wspecial = L"inf";

	  negative = fpnum.ldbl.d < 0;
	}
      else
	while (fpnum.ldbl.d >= divisor && tag[1] != '\0')
	  {
	    fpnum.ldbl.d /= divisor;
	    ++tag;
	  }
    }
  else
#endif	/* no long double */
    {
      fpnum.dbl.d = *(const double *) args[0];

      /* Check for special values: not a number or infinity.  */
      if (__isnan (fpnum.dbl.d))
	{
	  special = "nan";
	  wspecial = L"nan";
	  negative = 0;
	}
      else if (__isinf (fpnum.dbl.d))
	{
	  special = "inf";
	  wspecial = L"inf";

	  negative = fpnum.dbl.d < 0;
	}
      else
	while (fpnum.dbl.d >= divisor && tag[1] != '\0')
	  {
	    fpnum.dbl.d /= divisor;
	    ++tag;
	  }
    }

  if (special)
    {
      int width = info->prec > width ? info->prec : info->width;

      if (negative || info->showsign || info->space)
	--width;
      width -= 3;

      if (!info->left && width > 0)
	PADN (' ', width);

      if (negative)
	outchar ('-');
      else if (info->showsign)
	outchar ('+');
      else if (info->space)
	outchar (' ');

      PRINT (special, wspecial, 3);

      if (info->left && width > 0)
	PADN (' ', width);

      return done;
    }

  /* Prepare to print the number.  We want to use `__printf_fp' so we
     have to prepare a `printf_info' structure.  */
  fp_info.spec = 'f';
  fp_info.prec = info->prec < 0 ? 3 : info->prec;
  fp_info.is_long_double = info->is_long_double;
  fp_info.is_short = info->is_short;
  fp_info.is_long = info->is_long;
  fp_info.alt = info->alt;
  fp_info.space = info->space;
  fp_info.left = info->left;
  fp_info.showsign = info->showsign;
  fp_info.group = info->group;
  fp_info.extra = info->extra;
  fp_info.pad = info->pad;
  fp_info.wide = wide;

  if (fp_info.left && fp_info.pad == L' ')
    {
      /* We must do the padding ourself since the unit character must
	 be placed before the padding spaces.  */
      fp_info.width = 0;

      done = __printf_fp (fp, &fp_info, &ptr);
      if (done > 0)
	{
	  outchar (*tag);
	  if (info->width > done)
	    PADN (' ', info->width - done);
	}
    }
  else
    {
      /* We can let __printf_fp do all the printing and just add our
	 unit character afterwards.  */
      fp_info.width = info->width - 1;

      done = __printf_fp (fp, &fp_info, &ptr);
      if (done > 0)
	outchar (*tag);
    }

  return done;
}
Esempio n. 17
0
Err mathlib_isnan(UInt16 refnum, double x, Int16 *result) {
#pragma unused(refnum)
	*result = __isnan(x);
	return mlErrNone;
}
Esempio n. 18
0
int main(void)
{
int i, nerrors, k, ianswer, ntests;
double (*fun1) (double);
double (*fun2) (double, double);
int (*fun3) (double);
double e;
union {double d;char c[8];} u, v;
struct oneargument test1[] =
{
  {"atan", atan, &ONE, &PIO4, 0},
  {"sin", sin, &PIO2, &ONE, 0},
#if 0
  {"cos", cos, &PIO4, &SQRTH, 0},
  {"sin", sin, 32767., 1.8750655394138942394239E-1, 0},
  {"cos", cos, 32767., 9.8226335176928229845654E-1, 0},
  {"tan", tan, 32767., 1.9089234430221485740826E-1, 0},
  {"sin", sin, 8388607., 9.9234509376961249835628E-1, 0},
  {"cos", cos, 8388607., -1.2349580912475928183718E-1, 0},
  {"tan", tan, 8388607., -8.0354556223613614748329E0, 0},
  /*
  {"sin", sin, 2147483647., -7.2491655514455639054829E-1, 0},
  {"cos", cos, 2147483647., -6.8883669187794383467976E-1, 0},
  {"tan", tan, 2147483647., 1.0523779637351339136698E0, 0},
  */
  {"cos", cos, &PIO2, 6.1232339957367574e-17, 1},
  {"sin", sin, &PIO4, &SQRTH, 1},
#endif
  {"acos", acos, &nan, &nan, 0},
  {"acos", acos, &ONE, &ZERO, 0},
  {"acos", acos, &TWO, &nan, 0},
  {"acos", acos, &MTWO, &nan, 0},
  {"asin", asin, &nan, &nan, 0},
  {"asin", asin, &ZERO, &ZERO, 0},
  {"asin", asin, &MZERO, &MZERO, 0},
  {"asin", asin, &TWO, &nan, 0},
  {"asin", asin, &MTWO, &nan, 0},
  {"atan", atan, &nan, &nan, 0},
  {"atan", atan, &ZERO, &ZERO, 0},
  {"atan", atan, &MZERO, &MZERO, 0},
  {"atan", atan, &INF, &PIO2, 0},
  {"atan", atan, &MINF, &MPIO2, 0},
  {"cos", cos, &nan, &nan, 0},
  {"cos", cos, &ZERO, &ONE, 0},
  {"cos", cos, &MZERO, &ONE, 0},
  {"cos", cos, &INF, &nan, 0},
  {"cos", cos, &MINF, &nan, 0},
  {"sin", sin, &nan, &nan, 0},
  {"sin", sin, &MZERO, &MZERO, 0},
  {"sin", sin, &ZERO, &ZERO, 0},
  {"sin", sin, &INF, &nan, 0},
  {"sin", sin, &MINF, &nan, 0},
  {"tan", tan, &nan, &nan, 0},
  {"tan", tan, &ZERO, &ZERO, 0},
  {"tan", tan, &MZERO, &MZERO, 0},
  {"tan", tan, &INF, &nan, 0},
  {"tan", tan, &MINF, &nan, 0},
  {"acosh", acosh, &nan, &nan, 0},
  {"acosh", acosh, &ONE, &ZERO, 0},
  {"acosh", acosh, &INF, &INF, 0},
  {"acosh", acosh, &HALF, &nan, 0},
  {"acosh", acosh, &MONE, &nan, 0},
  {"asinh", asinh, &nan, &nan, 0},
  {"asinh", asinh, &ZERO, &ZERO, 0},
  {"asinh", asinh, &MZERO, &MZERO, 0},
  {"asinh", asinh, &INF, &INF, 0},
  {"asinh", asinh, &MINF, &MINF, 0},
  {"atanh", atanh, &nan, &nan, 0},
  {"atanh", atanh, &ZERO, &ZERO, 0},
  {"atanh", atanh, &MZERO, &MZERO, 0},
  {"atanh", atanh, &ONE, &INF, 0},
  {"atanh", atanh, &MONE, &MINF, 0},
  {"atanh", atanh, &TWO, &nan, 0},
  {"atanh", atanh, &MTWO, &nan, 0},
  {"cosh", cosh, &nan, &nan, 0},
  {"cosh", cosh, &ZERO, &ONE, 0},
  {"cosh", cosh, &MZERO, &ONE, 0},
  {"cosh", cosh, &INF, &INF, 0},
  {"cosh", cosh, &MINF, &INF, 0},
  {"sinh", sinh, &nan, &nan, 0},
  {"sinh", sinh, &ZERO, &ZERO, 0},
  {"sinh", sinh, &MZERO, &MZERO, 0},
  {"sinh", sinh, &INF, &INF, 0},
  {"sinh", sinh, &MINF, &MINF, 0},
  {"tanh", tanh, &nan, &nan, 0},
  {"tanh", tanh, &ZERO, &ZERO, 0},
  {"tanh", tanh, &MZERO, &MZERO, 0},
  {"tanh", tanh, &INF, &ONE, 0},
  {"tanh", tanh, &MINF, &MONE, 0},
  {"exp", exp, &nan, &nan, 0},
  {"exp", exp, &ZERO, &ONE, 0},
  {"exp", exp, &MZERO, &ONE, 0},
  {"exp", exp, &INF, &INF, 0},
  {"exp", exp, &MINF, &ZERO, 0},
#if 0
  {"exp2", exp2, &nan, &nan, 0},
  {"exp2", exp2, &ZERO, &ONE, 0},
  {"exp2", exp2, &MZERO, &ONE, 0},
  {"exp2", exp2, &INF, &INF, 0},
  {"exp2", exp2, &MINF, &ZERO, 0},
#endif
  {"expm1", expm1, &nan, &nan, 0},
  {"expm1", expm1, &ZERO, &ZERO, 0},
  {"expm1", expm1, &MZERO, &MZERO, 0},
  {"expm1", expm1, &INF, &INF, 0},
  {"expm1", expm1, &MINF, &MONE, 0},
  {"log", log, &nan, &nan, 0},
  {"log", log, &ZERO, &MINF, 0},
  {"log", log, &MZERO, &MINF, 0},
  {"log", log, &ONE, &ZERO, 0},
  {"log", log, &MONE, &nan, 0},
  {"log", log, &INF, &INF, 0},
  {"log10", log10, &nan, &nan, 0},
  {"log10", log10, &ZERO, &MINF, 0},
  {"log10", log10, &MZERO, &MINF, 0},
  {"log10", log10, &ONE, &ZERO, 0},
  {"log10", log10, &MONE, &nan, 0},
  {"log10", log10, &INF, &INF, 0},
  {"log1p", log1p, &nan, &nan, 0},
  {"log1p", log1p, &ZERO, &ZERO, 0},
  {"log1p", log1p, &MZERO, &MZERO, 0},
  {"log1p", log1p, &MONE, &MINF, 0},
  {"log1p", log1p, &MTWO, &nan, 0},
  {"log1p", log1p, &INF, &INF, 0},
#if 0
  {"log2", log2, &nan, &nan, 0},
  {"log2", log2, &ZERO, &MINF, 0},
  {"log2", log2, &MZERO, &MINF, 0},
  {"log2", log2, &MONE, &nan, 0},
  {"log2", log2, &INF, &INF, 0},
#endif
  /*  {"fabs", fabs, nan, nan, 0}, */
  {"fabs", fabs, &ONE, &ONE, 0},
  {"fabs", fabs, &MONE, &ONE, 0},
  {"fabs", fabs, &ZERO, &ZERO, 0},
  {"fabs", fabs, &MZERO, &ZERO, 0},
  {"fabs", fabs, &INF, &INF, 0},
  {"fabs", fabs, &MINF, &INF, 0},
  {"cbrt", cbrt, &nan, &nan, 0},
  {"cbrt", cbrt, &ZERO, &ZERO, 0},
  {"cbrt", cbrt, &MZERO, &MZERO, 0},
  {"cbrt", cbrt, &INF, &INF, 0},
  {"cbrt", cbrt, &MINF, &MINF, 0},
/* Get these from cprob.shar */
  {"erf", erf, &nan, &nan, 0},
  {"erf", erf, &ZERO, &ZERO, 0},
  {"erf", erf, &MZERO, &MZERO, 0},
  {"erf", erf, &INF, &ONE, 0},
  {"erf", erf, &MINF, &MONE, 0},
  {"erfc", erfc, &nan, &nan, 0},
  {"erfc", erfc, &INF, &ZERO, 0},
  {"erfc", erfc, &MINF, &TWO, 0},
#if 0 /* our gamma() is just an alias of lgamma(), like in BSD */
  {"gamma", gamma, &nan, &nan, 0},
  {"gamma", gamma, &INF, &INF, 0},
  {"gamma", gamma, &MONE, &nan, 0},
  {"gamma", gamma, &ZERO, &nan, 0},
  {"gamma", gamma, &MINF, &nan, 0},
#endif
  {"lgamma", lgamma, &nan, &nan, 0},
  {"lgamma", lgamma, &INF, &INF, 0},
  {"lgamma", lgamma, &MONE, &INF, 0},
  {"lgamma", lgamma, &ZERO, &INF, 0},
  {"lgamma", lgamma, &MINF, &INF, 0},

  {"ceil", ceil, &nan, &nan, 0},
  {"ceil", ceil, &ZERO, &ZERO, 0},
  {"ceil", ceil, &MZERO, &MZERO, 0},
  {"ceil", ceil, &INF, &INF, 0},
  {"ceil", ceil, &MINF, &MINF, 0},
  {"floor", floor, &nan, &nan, 0},
  {"floor", floor, &ZERO, &ZERO, 0},
  {"floor", floor, &MZERO, &MZERO, 0},
  {"floor", floor, &INF, &INF, 0},
  {"floor", floor, &MINF, &MINF, 0},
  {"null", NULL, &ZERO, &ZERO, 0},
};

struct twoarguments test2[] =
{
  {"atan2", atan2, &ZERO, &ONE, &ZERO, 0},
  {"atan2", atan2, &MZERO, &ONE, &MZERO, 0},
  {"atan2", atan2, &ZERO, &ZERO, &ZERO, 0},
  {"atan2", atan2, &MZERO, &ZERO, &MZERO, 0},
  {"atan2", atan2, &ZERO, &MONE, &pi, 0},
  {"atan2", atan2, &MZERO, &MONE, &MPI, 0},
  {"atan2", atan2, &ZERO, &MZERO, &pi, 0},
  {"atan2", atan2, &MZERO, &MZERO, &MPI, 0},
  {"atan2", atan2, &ONE, &ZERO, &PIO2, 0},
  {"atan2", atan2, &ONE, &MZERO, &PIO2, 0},
  {"atan2", atan2, &MONE, &ZERO, &MPIO2, 0},
  {"atan2", atan2, &MONE, &MZERO, &MPIO2, 0},
  {"atan2", atan2, &ONE, &INF, &ZERO, 0},
  {"atan2", atan2, &MONE, &INF, &MZERO, 0},
  {"atan2", atan2, &INF, &ONE, &PIO2, 0},
  {"atan2", atan2, &INF, &MONE, &PIO2, 0},
  {"atan2", atan2, &MINF, &ONE, &MPIO2, 0},
  {"atan2", atan2, &MINF, &MONE, &MPIO2, 0},
  {"atan2", atan2, &ONE, &MINF, &pi, 0},
  {"atan2", atan2, &MONE, &MINF, &MPI, 0},
  {"atan2", atan2, &INF, &INF, &PIO4, 0},
  {"atan2", atan2, &MINF, &INF, &MPIO4, 0},
  {"atan2", atan2, &INF, &MINF, &THPIO4, 0},
  {"atan2", atan2, &MINF, &MINF, &MTHPIO4, 0},
  {"atan2", atan2, &ONE, &ONE, &PIO4, 0},
  {"atan2", atan2, &nan, &ONE, &nan, 0},
  {"atan2", atan2, &ONE, &nan, &nan, 0},
  {"atan2", atan2, &nan, &nan, &nan, 0},
  {"pow", pow, &ONE, &ZERO, &ONE, 0},
  {"pow", pow, &ONE, &MZERO, &ONE, 0},
  {"pow", pow, &MONE, &ZERO, &ONE, 0},
  {"pow", pow, &MONE, &MZERO, &ONE, 0},
  {"pow", pow, &INF, &ZERO, &ONE, 0},
  {"pow", pow, &INF, &MZERO, &ONE, 0},
  {"pow", pow, &nan, &ZERO, &ONE, 0},
  {"pow", pow, &nan, &MZERO, &ONE, 0},
  {"pow", pow, &TWO, &INF, &INF, 0},
  {"pow", pow, &MTWO, &INF, &INF, 0},
  {"pow", pow, &HALF, &INF, &ZERO, 0},
  {"pow", pow, &MHALF, &INF, &ZERO, 0},
  {"pow", pow, &TWO, &MINF, &ZERO, 0},
  {"pow", pow, &MTWO, &MINF, &ZERO, 0},
  {"pow", pow, &HALF, &MINF, &INF, 0},
  {"pow", pow, &MHALF, &MINF, &INF, 0},
  {"pow", pow, &INF, &HALF, &INF, 0},
  {"pow", pow, &INF, &TWO, &INF, 0},
  {"pow", pow, &INF, &MHALF, &ZERO, 0},
  {"pow", pow, &INF, &MTWO, &ZERO, 0},
  {"pow", pow, &MINF, &THREE, &MINF, 0},
  {"pow", pow, &MINF, &TWO, &INF, 0},
  {"pow", pow, &MINF, &MTHREE, &MZERO, 0},
  {"pow", pow, &MINF, &MTWO, &ZERO, 0},
  {"pow", pow, &nan, &ONE, &nan, 0},
  {"pow", pow, &ONE, &nan, &nan, 0},
  {"pow", pow, &nan, &nan, &nan, 0},
  {"pow", pow, &ONE, &INF, &nan, 0},
  {"pow", pow, &MONE, &INF, &nan, 0},
  {"pow", pow, &ONE, &MINF, &nan, 0},
  {"pow", pow, &MONE, &MINF, &nan, 0},
  {"pow", pow, &MTWO, &HALF, &nan, 0},
  {"pow", pow, &ZERO, &MTHREE, &INF, 0},
  {"pow", pow, &MZERO, &MTHREE, &MINF, 0},
  {"pow", pow, &ZERO, &MHALF, &INF, 0},
  {"pow", pow, &MZERO, &MHALF, &INF, 0},
  {"pow", pow, &ZERO, &THREE, &ZERO, 0},
  {"pow", pow, &MZERO, &THREE, &MZERO, 0},
  {"pow", pow, &ZERO, &HALF, &ZERO, 0},
  {"pow", pow, &MZERO, &HALF, &ZERO, 0},
  {"null", NULL, &ZERO, &ZERO, &ZERO, 0},
};

struct intans test3[] =
{
  {"isfinite", __isfinite, &ZERO, 1},
  {"isfinite", __isfinite, &INF, 0},
  {"isfinite", __isfinite, &MINF, 0},
  {"isnan", __isnan, &nan, 1},
  {"isnan", __isnan, &INF, 0},
  {"isnan", __isnan, &ZERO, 0},
  {"isnan", __isnan, &MZERO, 0},
  {"signbit", __signbit, &MZERO, 1},
  {"signbit", __signbit, &MONE, 1},
  {"signbit", __signbit, &ZERO, 0},
  {"signbit", __signbit, &ONE, 0},
  {"signbit", __signbit, &MINF, 1},
  {"signbit", __signbit, &INF, 0},
  {"null", NULL, &ZERO, 0},
};

  /* We test the IEEE conformance of fdlibm. */
  _LIB_VERSION = _IEEE_;

    /* This masks off fpu exceptions on i386.  */
  _setfpu(0x137f);
  _control87(PC_53, MCW_PC);
        
  nerrors = 0;
  ntests = 0;
  i = 0;
  for (;;)
    {
      fun1 = test1[i].func;
      if (fun1 == NULL)
	break;
      x1 = *(test1[i].arg1);
      y = (*(fun1)) (x1);
      answer = *(test1[i].answer);
      if (test1[i].thresh == 0)
	{
	  v.d = answer;
	  u.d = y;
	  if (memcmp(u.c, v.c, 8) != 0)
	    {
	      if( __isnan(v.d) && __isnan(u.d) )
		goto nxttest1;
	      goto wrongone;
	    }
	  else
	    goto nxttest1;
	}
      if (y != answer)
	{
	  e = y - answer;
	  if (answer != 0.0)
	    e = e / answer;
	  if (e < 0)
	    e = -e;
	  if (e > test1[i].thresh * MACHEP)
	    {
wrongone:
	      printf ("%s (%.16e) = %.16e\n    should be %.16e\n",
		      test1[i].name, x1, y, answer);
	      nerrors += 1;
	    }
	}
nxttest1:
      ntests += 1;
      i += 1;
    }

  i = 0;
  for (;;)
    {
      fun2 = test2[i].func;
      if (fun2 == NULL)
	break;
      x1 = *(test2[i].arg1);
      x2 = *(test2[i].arg2);
      y = (*(fun2)) (x1, x2);
      answer = *(test2[i].answer);
      if (test2[i].thresh == 0)
	{
	  v.d = answer;
	  u.d = y;
	  if (memcmp(u.c, v.c, 8) != 0)
	    {
	      if( __isnan(v.d) && __isnan(u.d) )
		goto nxttest2;
#if 0
	      if( isnan(v.d) )
		pvec(v.d);
	      if( isnan(u.d) )
		pvec(u.d);
#endif
	    goto wrongtwo;
	    }
	  else
	    goto nxttest2;
	}
      if (y != answer)
	{
	  e = y - answer;
	  if (answer != 0.0)
	    e = e / answer;
	  if (e < 0)
	    e = -e;
	  if (e > test2[i].thresh * MACHEP)
	    {
wrongtwo:
	      printf ("%s (%.16e, %.16e) = %.16e\n    should be %.16e\n",
		      test2[i].name, x1, x2, y, answer);
	      nerrors += 1;
	    }
	}
nxttest2:
      ntests += 1;
      i += 1;
    }


  i = 0;
  for (;;)
    {
      fun3 = test3[i].func;
      if (fun3 == NULL)
	break;
      x1 = *(test3[i].arg1);
      k = (*(fun3)) (x1);
      ianswer = test3[i].ianswer;
      if (k != ianswer)
	{
	  printf ("%s(%.16e) = %d\n should be %d\n",
		  test3[i].name, x1, k, ianswer);
	  nerrors += 1;
	}
      ntests += 1;
      i += 1;
    }

  printf ("testvect: %d errors in %d tests\n", nerrors, ntests);
#undef isnan(x)
  printf ("isnan(NAN): %d\n", isnan(NAN));
  exit (0);
}
Esempio n. 19
0
/**
	Qnormalisation Method: function that implements the ben Bolstad Method
	quantile Normalization of High density Oliglonucleotide Array Data
	@input : data matrix (each column is an experiment, each row a gene or data)
	@output: data matrix with the results
	@nrows: number of genes or rows in the matrix
	@ncolumns: number of experiments in the matrix
	@returns >0 if everything was fine <0 if there was an error
**/
int Qnormalization(double **input, double **output, int nrows, int ncolumns)
{
	int i,j,k,n;
	double average;
	double** ordered;
	int** indexes;

	//initialize auxiliar array to not modify the input array
	ordered=(double **)malloc(nrows*sizeof(double*));
	for (i=0; i<nrows;i++){
		ordered[i]=(double *)malloc(ncolumns*(sizeof(double)));
	}
	//auxiliar array to store the indexes
	indexes=(int **)malloc(nrows*sizeof(int*));
	for (i=0; i<nrows;i++){
		indexes[i]=(int *)malloc(ncolumns*(sizeof(int)));
	}

	//copy the values 
	for (i=0; i<nrows;i++){	
		for (j=0; j<ncolumns;j++){
			ordered[i][j]=input[i][j];	
			//UNIFY NAN CONSTANT 
			if ((!__finite(input[i][j]))||(__isnan(input[i][j])))
				ordered[i][j]=HUGE_VAL;
		}
		
	}

	//initialize the indexes array
	for (i=0; i<nrows;i++){
		for (j=0; j<ncolumns;j++){
			indexes[i][j]=j;
		}
	}
	
	
	//order each data column
	for (i=0; i<nrows; i++){
		//Quicksort 
		QsortC(ordered[i],0,ncolumns-1,indexes[i]);
	//	bubbleSort(ordered[i], ncolumns, indexes[i]);
	}

	
	//APPLY QNORMALISATION
	//Take the means across rows of Xsort and assign this mean to each element in the row to get X0sort
    //. Get Xnormalized by rearranging each column of X0 sort to have the same ordering as original X	
	//calculate the average of each j elem
	for (j=0; j<ncolumns; j++){
		average=HUGE_VAL;
		n=0;
		for (i=0; i<nrows;i++){
			if ((__finite(ordered[i][j]))&&(!__isnan(ordered[i][j]))){
				if ((!__finite(average))||(__isnan(average))){
					average=0;
				}
				average+=ordered[i][j];
				n++;
			}
		}
		if ((__finite(average))&&(!__isnan(average))){
			average/=n;
		}
		for (i=0; i<nrows;i++){
			if ((__finite(ordered[i][j]))&&(!__isnan(ordered[i][j])))
				ordered[i][j]=average;
		}
	}
	
	//reorder each data column
	for (i=0; i<nrows;i++){
		for (j=0; j<ncolumns;j++){
			k=indexes[i][j];
			output[i][k]=ordered[i][j];
		}
	}

	return 1;
}
Esempio n. 20
0
int compute_ewa(size_t chan_count, int maximum_weight_mode,
        size_t swath_cols, size_t swath_rows, size_t grid_cols, size_t grid_rows, CR_TYPE *uimg, CR_TYPE *vimg,
        IMAGE_TYPE **images, IMAGE_TYPE img_fill, accum_type **grid_accums, weight_type **grid_weights, ewa_weight *ewaw, ewa_parameters *ewap) {
  // This was originally copied from a cython C file for 32-bit float inputs (that explains some of the weird parens and other syntax
  int got_point;
  unsigned int row;
  unsigned int col;
  ewa_parameters *this_ewap;
  int iu1;
  int iu2;
  int iv1;
  int iv2;
  int iu;
  int iv;
  CR_TYPE u0;
  CR_TYPE v0;
  weight_type ddq;
  weight_type dq;
  weight_type q;
  weight_type u;
  weight_type v;
  weight_type a2up1;
  weight_type au2;
  weight_type bu;
  weight_type weight;

  // Test: This is how the original fornav did its calculations
//  double u0;
//  double v0;
//  double ddq;
//  double dq;
//  double q;
//  double u;
//  double v;
//  double a2up1;
//  double au2;
//  double bu;
//  double weight;
//  double qfactor;

  int iw;
  IMAGE_TYPE this_val;
  unsigned int swath_offset;
  unsigned int grid_offset;
  size_t chan;

  got_point = 0;
  for (row = 0, swath_offset=0; row < swath_rows; row+=1) {
    for (col = 0, this_ewap = ewap; col < swath_cols; col++, this_ewap++, swath_offset++) {
      u0 = uimg[swath_offset];
      v0 = vimg[swath_offset];

      if (u0 < 0.0 || v0 < 0.0 || __isnan(u0) || npy_isnan(v0)) {
        continue;
      }

      iu1 = ((int)(u0 - this_ewap->u_del));
      iu2 = ((int)(u0 + this_ewap->u_del));
      iv1 = ((int)(v0 - this_ewap->v_del));
      iv2 = ((int)(v0 + this_ewap->v_del));

      if (iu1 < 0) {
        iu1 = 0;
      }
      if (iu2 >= grid_cols) {
        iu2 = (grid_cols - 1);
      }
      if (iv1 < 0) {
        iv1 = 0;
      }
      if (iv2 >= grid_rows) {
        iv2 = (grid_rows - 1);
      }

      if (iu1 < grid_cols && iu2 >= 0 && iv1 < grid_rows && iv2 >= 0) {
        got_point = 1;
        ddq = 2.0 * this_ewap->a;

        u = (iu1 - u0);
        a2up1 = (this_ewap->a * ((2.0 * u) + 1.0));
        bu = this_ewap->b * u;
        au2 = this_ewap->a * u * u;

        for (iv = iv1; iv <= iv2; iv++) {
          v = (iv - v0);
          dq = (a2up1 + (this_ewap->b * v));
          q = ((((this_ewap->c * v) + bu) * v) + au2);
          for (iu = iu1; iu <= iu2; iu++) {
            if ((q >= 0.0) && (q < this_ewap->f)) {
              iw = ((int)(q * ewaw->qfactor));
              if (iw >= ewaw->count) {
                iw = (ewaw->count - 1);
              }
              weight = (ewaw->wtab[iw]);
              grid_offset = ((iv * grid_cols) + iu);

              for (chan = 0; chan < chan_count; chan+=1) {
                this_val = ((images[chan])[swath_offset]);
                if (maximum_weight_mode) {
                  if (weight > grid_weights[chan][grid_offset]) {
                    ((grid_weights[chan])[grid_offset]) = weight;
                    if ((this_val == img_fill) || (__isnan(this_val))) {
                      ((grid_accums[chan])[grid_offset]) = (accum_type)NPY_NANF;
                    } else {
                      ((grid_accums[chan])[grid_offset]) = (accum_type)this_val;
                    }
                  }
                } else {
                  if ((this_val != img_fill) && !(__isnan(this_val))) {
                    ((grid_weights[chan])[grid_offset]) += weight;
                    ((grid_accums[chan])[grid_offset]) += (accum_type)this_val * weight;
                  }
                }
              }
            }
            q += dq;
            dq += ddq;
          }
        }
      }
    }
  }

  /* function exit code */
  return got_point;
}