Exemplo n.º 1
0
//----------------------------------------------------------------------------------------------------------------------
long double Function::Dms(long double arg, bool invert)
{
    long double m = 0, s = 0, res;
    long double koeff = 0.6;

    if(invert)
        koeff = 1;

    //45.1348

    m = modfl(arg, &arg);
    m *= koeff * 100;
    s = modfl(m, &m);

    if(s > 0.9999)
    {
        s = 0;
        m++;
    }

    s *= koeff;
    if(invert)
        res = arg + m / 60 + s / 36;
    else
        res = arg + (m + s) / 100;
    return res;
}
Exemplo n.º 2
0
void mjd_to_utcl(long double mjd, int *nyear, int *nmonth, int *nday,
                 int *nhour, int *nminute, long double *nsecond)
{
    long double A, B, C, D, E, G, F, I;
    long double days, month, year;

    long double jd = mjd + 2400001.0L;

    F = modfl(jd, &I);
    A = truncl((I - 1867216.25L) / 36524.25L);

    B = (I > 2299160.0L) ? I + 1 + A - truncl(A / 4.0L) : I;
    C = B + 1524.0L;
    D = truncl((C - 122.1L) / 365.25L);
    E = truncl(365.25L * D);
    G = truncl((C - E) / 30.6001L);

    days = C - E + F - truncl(30.6001L * G);
    month = (G < 13.0L) ? G - 1 : G - 13.0L;
    year = (month > 2.5L) ? D - 4716.0L : D - 4715.0L;

    *nyear = (int) year;
    *nmonth = (int) month;
    *nday = (int) days;

    days_to_hmsl(days - (int) days, nhour, nminute, nsecond);

    return;
}
Exemplo n.º 3
0
void test_modf()
{
    static_assert((std::is_same<decltype(modf((double)0, (double*)0)), double>::value), "");
    static_assert((std::is_same<decltype(modff(0, (float*)0)), float>::value), "");
    static_assert((std::is_same<decltype(modfl(0, (long double*)0)), long double>::value), "");
    double i;
    assert(modf(1., &i) == 0);
}
Exemplo n.º 4
0
char *floattohexfloat(long double value, char *buffer) {
  /* Convert an float value in an hexadecimal string stored in the given pointer;
   ******************************************************************************/
 
  if (buffer == NULL) {
    /** Given an NULL pointer as argument **/
    buffer=calloc(128,sizeof(char)) ;
  }
 
  #ifdef HAVE_MALLOC_USABLE_SIZE
 
  if (malloc_usable_size(buffer) < 128)  {
    if ( realloc(buffer,128) == NULL) {
      errno=EINVAL ;	
      return NULL ;
    }
   
  }
 
  #endif
 
  long double int_part=0.0 ;
  long double float_part=0.0 ;
  _Bool is_negativ = false ;
  if (value < 0) {
    value=fabs(value) ;
    is_negativ=true ;
  }
 
  float_part=modfl(value,&int_part) ; /** modulo float */
 
  /** variables for splitting in integer and float part */
  char *int_part_str_hex=malloc(128) ;
  char *float_part_str_hex=malloc(128) ;
  memset(int_part_str_hex,'\0',128) ;
  memset(float_part_str_hex,'\0',128) ;
 
  /** Perform splitting in integer and float part */
  inttohex((long long) int_part,int_part_str_hex) ;
  __inttohexfloatpart(float_part,float_part_str_hex,127) ;

  /** result binar string variable (pointer given as argument) */
  memset(buffer,'\0',128) ;
 
  if ((is_negativ) && (int_part_str_hex[0] != '-')) {
    /** Case value to convert in binfloat string is negativ */
    strcpy(buffer,"-") ;
  }
 
  /** Assemble final binar string */
  strcat(buffer,int_part_str_hex) ;
  strcat(buffer,".") ;
  strcat(buffer,float_part_str_hex) ;
 
  return buffer ;
}
Exemplo n.º 5
0
void days_to_hmsl(long double days, int *nhour, int *nminute, long double *nsecond)
{
    long double hour, minute;
    long double hours, minutes, seconds;

    hours = days * 24.0L;
    hours = modfl(hours, &hour);

    minutes = hours * 60.0L;
    minutes = modfl(minutes, &minute);

    seconds = minutes * 60.0L;

    *nhour = (int)hour;
    *nminute = (int)minute;
    *nsecond = seconds;

    return;
}
Exemplo n.º 6
0
long double ceill(long double x)
{
  modfl(x, &x);
  if (x > 0.0)
    {
      x += 1.0;
    }

  return x;
}
Exemplo n.º 7
0
long double floorl(long double x)
{
  modfl(x, &x);
  if (x < 0.0)
    {
      x -= 1.0;
    }

  return x;
}
Exemplo n.º 8
0
int main(int argc, char *argv[]) {
  float       intpartf;
  double      intpart;
  long double intpartl;

  float       fracf = modff(100.0f, &intpartf);
  double      frac  = modf( 100.0 , &intpart );
  long double fracl = modfl(100.0l, &intpartl);

  printf("integer parts: %f, %f, %Lf.\n", intpartf, intpart, intpartl);

  return 0;
}
Exemplo n.º 9
0
long double exp10l(long double x)
{
    static const long double p10[] = {
        1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10,
        1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1,
        1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
        1e10, 1e11, 1e12, 1e13, 1e14, 1e15
    };
    long double n, y = modfl(x, &n);
    if (fabsl(n) < 16) {
        if (!y) return p10[(int)n+15];
        y = exp2l(3.32192809488736234787031942948939L * y);
        return y * p10[(int)n+15];
    }
    return powl(10.0, x);
}
Exemplo n.º 10
0
void __inttobinfloatpart(long double value, char *buffer, int precision) {
  /* Set the float part value in an binary string stored in the given pointer ;
   ***************************************************************************/
 
  /** temporary final result container variable used for computing */
  char *bin_str_saved=malloc(96) ;
  memset(bin_str_saved,'\0',96) ;
 
  int c=0 ;
  if (value < 0) {
    /** value needed for computing */
    value=fabs(value) ;
  }
  while (c < precision) {
    /** loop for computing until precision is reach */
   
    long double res_int ;
    long double res_float ;
   
    res_float=modfl(value * 2.0,&res_int) ; /** modulo float */
   
   
    if ( res_int  == 0) {
      strcat(bin_str_saved,"0") ; /** getting the binary string component as the integer to add to float part */
    }
    else if ( res_int  == 1 ) {
      strcat(bin_str_saved,"1") ; /** getting the binary string component as the integer to add to float part */
    }
    else {
      return ;
    }
   
    if ( res_float == 0.0 ) {
      break ; /** reach end of binary float string computing */
    }
   
    value=res_float ;
   
    c++ ;
  }
 
  c=sprintf(buffer,"%s",bin_str_saved) ;
  buffer[c]='\0' ;
  free(bin_str_saved) ;
}
Exemplo n.º 11
0
long double exp10l(long double x)
{
	static const long double p10[] = {
		1e-15L, 1e-14L, 1e-13L, 1e-12L, 1e-11L, 1e-10L,
		1e-9L, 1e-8L, 1e-7L, 1e-6L, 1e-5L, 1e-4L, 1e-3L, 1e-2L, 1e-1L,
		1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
		1e10, 1e11, 1e12, 1e13, 1e14, 1e15
	};
	long double n, y = modfl(x, &n);
	union ldshape u = {n};
	/* fabsl(n) < 16 without raising invalid on nan */
	if ((u.i.se & 0x7fff) < 0x3fff+4) {
		if (!y) return p10[(int)n+15];
		y = exp2l(3.32192809488736234787031942948939L * y);
		return y * p10[(int)n+15];
	}
	return powl(10.0, x);
}
Exemplo n.º 12
0
static char *
print_float_round (snv_long_double fract, int *exp, char *start, char *end,
		   char ch, int *signp)
{
  snv_long_double tmp;
  if (fract)
    (void) modfl (fract * 10, &tmp);
  else
    tmp = ch - '0';

  if (tmp > 4)
    for (;; --end)
      {
	if (*end == '.')
	  --end;
	if (end == start)
	  {
	    if (exp) /* e/E; increment exponent */
	      ++end, ++*exp;

	    *end = '1';
	    break;
	  }
	if (++*end <= '9')
	  break;
	*end = '0';
      }

  /* ``"%.3f", (double)-0.0004'' gives you a negative 0. */
  else if (*signp == '-')
    for (;; --end)
      {
	if (*end == '.')
	  --end;
	if (*end != '0')
	  break;
	if (end == start)
	  *signp = 0;
      }
  return (start);
}
Exemplo n.º 13
0
void inttohexfloatpart(long double float_to_hex,char *hex_str,int precision) {
  /* Set the float part value in an hexadecimal string stored in the given pointer ;
   *********************************************************************************/
  
  /** temporary final result container variable used for computing */
  char *hex_str_saved=malloc(96) ;
  memset(hex_str_saved,'\0',96) ;
  
  int c=0 ;
  if (float_to_hex < 0) {
    /** value needed for computing */
    float_to_hex=fabs(float_to_hex) ;
  }
  
  while (c < (precision)) {
    /** loop for computing until precision is reach */
    char *to_hex=malloc(32) ;
    memset(to_hex,'\0',32) ;
    
    long double res_int ;
    long double res_float ;
    
    res_float = modfl(float_to_hex * 16.0,&res_int) ; /** modulo float */
    
    inttohex((long long) res_int,to_hex) ; /** getting the hexadecimal string of the integer to add to float part */
    strcat(hex_str_saved,to_hex) ;          

    if ( res_float == 0.0 ) {
      break ; /** reach end of hexadecimal string computing */
    }
    
    float_to_hex=res_float ; /** updating value */
    c++ ;
  }
  
  snprintf(hex_str,(size_t) precision,"%s",hex_str_saved) ;
  free(hex_str_saved) ;
  hex_str[++c]='\0' ;
}
Exemplo n.º 14
0
void __inttooctfloatpart(long double value, char *buffer, int precision) {
  /* Set the float part value in an octal string stored in the given pointer ;
   ***************************************************************************/
 
  /** temporary final result container variable used for computing */
  char *oct_str_saved=malloc(96) ;
  memset(oct_str_saved,'\0',96) ;

  int c=0 ;
  if (value < 0) {
    /** value needed for computing */
    value=fabs(value) ;
  }
  while (c < (precision)) {
    /** loop for computing until precision is reach */
   
    char *to_oct=malloc(48) ;
    memset(to_oct,'\0',48) ;
   
    long double res_int ;
    long double res_float ;
   
    res_float=modfl(value* 8.0,&res_int) ; /** modulo float */
   
    inttooct(res_int,to_oct) ;  /** getting the octal string of the integer to add to float part */
   
    strcat(oct_str_saved,to_oct) ;
    if ( res_float == 0.0 ) {
      break ; /** reach end of octal string computing */
    }
   
    value=res_float ; /** updating value */
    c++ ;
  }
 
  sprintf(buffer,"%s",oct_str_saved) ;
  free(oct_str_saved) ;
 
}
Exemplo n.º 15
0
void floattohexfloat(long double int_to_hex,char *hex_str) {
  /* Convert an float value in an hexadecimal string stored in the given pointer;
   ******************************************************************************/
  long double int_part=0.0 ;
  long double float_part=0.0 ;
  _Bool is_negativ = false ;
  if (int_to_hex < 0) {
    int_to_hex=fabs(int_to_hex) ;
    is_negativ=true ;
  }
  
  float_part=modfl(int_to_hex,&int_part) ; /** modulo float */
  
  /** variables for splitting in integer and float part */
  char *int_part_str_hex=malloc(129) ;
  char *float_part_str_hex=malloc(129) ;
  memset(int_part_str_hex,'\0',129) ;
  memset(float_part_str_hex,'\0',129) ;
  
  /** Perform splitting in integer and float part */
  inttohex((long long) int_part,int_part_str_hex) ;
  inttohexfloatpart(float_part,float_part_str_hex,128) ;

  /** result binar string variable (pointer given as argument) */
  memset(hex_str,'\0',129) ;
  
  if ((is_negativ) && (int_part_str_hex[0] != '-')) {
    /** Case value to convert in binfloat string is negativ */
    strcpy(hex_str,"-") ;
  }
  
  /** Assemble final binar string */
  strcat(hex_str,int_part_str_hex) ;
  strcat(hex_str,".") ;
  strcat(hex_str,float_part_str_hex) ;
  
}
Exemplo n.º 16
0
ATF_TC_BODY(fpclassify_long_double, tc)
{
	long double d0, d1, d2, f, ip;
	int e, i;

	d0 = LDBL_MIN;
	ATF_REQUIRE_EQ(fpclassify(d0), FP_NORMAL);
	f = frexpl(d0, &e);
	ATF_REQUIRE_EQ(e, LDBL_MIN_EXP);
	ATF_REQUIRE_EQ(f, 0.5);
	d1 = d0;

	/* shift a "1" bit through the mantissa (skip the implicit bit) */
	for (i = 1; i < LDBL_MANT_DIG; i++) {
		d1 /= 2;
		ATF_REQUIRE_EQ(fpclassify(d1), FP_SUBNORMAL);
		ATF_REQUIRE(d1 > 0 && d1 < d0);

		d2 = ldexpl(d0, -i);
		ATF_REQUIRE_EQ(d2, d1);

		d2 = modfl(d1, &ip);
		ATF_REQUIRE_EQ(d2, d1);
		ATF_REQUIRE_EQ(ip, 0);

		f = frexpl(d1, &e);
		ATF_REQUIRE_EQ(e, LDBL_MIN_EXP - i);
		ATF_REQUIRE_EQ(f, 0.5);
	}

	d1 /= 2;
	ATF_REQUIRE_EQ(fpclassify(d1), FP_ZERO);
	f = frexpl(d1, &e);
	ATF_REQUIRE_EQ(e, 0);
	ATF_REQUIRE_EQ(f, 0);
}
Exemplo n.º 17
0
void
domathl (void)
{
#ifndef NO_LONG_DOUBLE
  long double f1;
  long double f2;

  int i1;

  f1 = acosl(0.0);
  fprintf( stdout, "acosl          : %Lf\n", f1);

  f1 = acoshl(0.0);
  fprintf( stdout, "acoshl         : %Lf\n", f1);

  f1 = asinl(1.0);
  fprintf( stdout, "asinl          : %Lf\n", f1);

  f1 = asinhl(1.0);
  fprintf( stdout, "asinhl         : %Lf\n", f1);

  f1 = atanl(M_PI_4);
  fprintf( stdout, "atanl          : %Lf\n", f1);

  f1 = atan2l(2.3, 2.3);
  fprintf( stdout, "atan2l         : %Lf\n", f1);

  f1 = atanhl(1.0);
  fprintf( stdout, "atanhl         : %Lf\n", f1);

  f1 = cbrtl(27.0);
  fprintf( stdout, "cbrtl          : %Lf\n", f1);

  f1 = ceill(3.5);
  fprintf( stdout, "ceill          : %Lf\n", f1);

  f1 = copysignl(3.5, -2.5);
  fprintf( stdout, "copysignl      : %Lf\n", f1);

  f1 = cosl(M_PI_2);
  fprintf( stdout, "cosl           : %Lf\n", f1);

  f1 = coshl(M_PI_2);
  fprintf( stdout, "coshl          : %Lf\n", f1);

  f1 = erfl(42.0);
  fprintf( stdout, "erfl           : %Lf\n", f1);

  f1 = erfcl(42.0);
  fprintf( stdout, "erfcl          : %Lf\n", f1);

  f1 = expl(0.42);
  fprintf( stdout, "expl           : %Lf\n", f1);

  f1 = exp2l(0.42);
  fprintf( stdout, "exp2l          : %Lf\n", f1);

  f1 = expm1l(0.00042);
  fprintf( stdout, "expm1l         : %Lf\n", f1);

  f1 = fabsl(-1.123);
  fprintf( stdout, "fabsl          : %Lf\n", f1);

  f1 = fdiml(1.123, 2.123);
  fprintf( stdout, "fdiml          : %Lf\n", f1);

  f1 = floorl(0.5);
  fprintf( stdout, "floorl         : %Lf\n", f1);
  f1 = floorl(-0.5);
  fprintf( stdout, "floorl         : %Lf\n", f1);

  f1 = fmal(2.1, 2.2, 3.01);
  fprintf( stdout, "fmal           : %Lf\n", f1);

  f1 = fmaxl(-0.42, 0.42);
  fprintf( stdout, "fmaxl          : %Lf\n", f1);

  f1 = fminl(-0.42, 0.42);
  fprintf( stdout, "fminl          : %Lf\n", f1);

  f1 = fmodl(42.0, 3.0);
  fprintf( stdout, "fmodl          : %Lf\n", f1);

  /* no type-specific variant */
  i1 = fpclassify(1.0);
  fprintf( stdout, "fpclassify     : %d\n", i1);

  f1 = frexpl(42.0, &i1);
  fprintf( stdout, "frexpl         : %Lf\n", f1);

  f1 = hypotl(42.0, 42.0);
  fprintf( stdout, "hypotl         : %Lf\n", f1);

  i1 = ilogbl(42.0);
  fprintf( stdout, "ilogbl         : %d\n", i1);

  /* no type-specific variant */
  i1 = isfinite(3.0);
  fprintf( stdout, "isfinite       : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreater(3.0, 3.1);
  fprintf( stdout, "isgreater      : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreaterequal(3.0, 3.1);
  fprintf( stdout, "isgreaterequal : %d\n", i1);

  /* no type-specific variant */
  i1 = isinf(3.0);
  fprintf( stdout, "isinf          : %d\n", i1);

  /* no type-specific variant */
  i1 = isless(3.0, 3.1);
  fprintf( stdout, "isless         : %d\n", i1);

  /* no type-specific variant */
  i1 = islessequal(3.0, 3.1);
  fprintf( stdout, "islessequal    : %d\n", i1);

  /* no type-specific variant */
  i1 = islessgreater(3.0, 3.1);
  fprintf( stdout, "islessgreater  : %d\n", i1);

  /* no type-specific variant */
  i1 = isnan(0.0);
  fprintf( stdout, "isnan          : %d\n", i1);

  /* no type-specific variant */
  i1 = isnormal(3.0);
  fprintf( stdout, "isnormal       : %d\n", i1);

  /* no type-specific variant */
  f1 = isunordered(1.0, 2.0);
  fprintf( stdout, "isunordered    : %d\n", i1);

  f1 = j0l(1.2);
  fprintf( stdout, "j0l            : %Lf\n", f1);

  f1 = j1l(1.2);
  fprintf( stdout, "j1l            : %Lf\n", f1);

  f1 = jnl(2,1.2);
  fprintf( stdout, "jnl            : %Lf\n", f1);

  f1 = ldexpl(1.2,3);
  fprintf( stdout, "ldexpl         : %Lf\n", f1);

  f1 = lgammal(42.0);
  fprintf( stdout, "lgammal        : %Lf\n", f1);

  f1 = llrintl(-0.5);
  fprintf( stdout, "llrintl        : %Lf\n", f1);
  f1 = llrintl(0.5);
  fprintf( stdout, "llrintl        : %Lf\n", f1);

  f1 = llroundl(-0.5);
  fprintf( stdout, "lroundl        : %Lf\n", f1);
  f1 = llroundl(0.5);
  fprintf( stdout, "lroundl        : %Lf\n", f1);

  f1 = logl(42.0);
  fprintf( stdout, "logl           : %Lf\n", f1);

  f1 = log10l(42.0);
  fprintf( stdout, "log10l         : %Lf\n", f1);

  f1 = log1pl(42.0);
  fprintf( stdout, "log1pl         : %Lf\n", f1);

  f1 = log2l(42.0);
  fprintf( stdout, "log2l          : %Lf\n", f1);

  f1 = logbl(42.0);
  fprintf( stdout, "logbl          : %Lf\n", f1);

  f1 = lrintl(-0.5);
  fprintf( stdout, "lrintl         : %Lf\n", f1);
  f1 = lrintl(0.5);
  fprintf( stdout, "lrintl         : %Lf\n", f1);

  f1 = lroundl(-0.5);
  fprintf( stdout, "lroundl        : %Lf\n", f1);
  f1 = lroundl(0.5);
  fprintf( stdout, "lroundl        : %Lf\n", f1);

  f1 = modfl(42.0,&f2);
  fprintf( stdout, "lmodfl         : %Lf\n", f1);

  f1 = nanl("");
  fprintf( stdout, "nanl           : %Lf\n", f1);

  f1 = nearbyintl(1.5);
  fprintf( stdout, "nearbyintl     : %Lf\n", f1);

  f1 = nextafterl(1.5,2.0);
  fprintf( stdout, "nextafterl     : %Lf\n", f1);

  f1 = powl(3.01, 2.0);
  fprintf( stdout, "powl           : %Lf\n", f1);

  f1 = remainderl(3.01,2.0);
  fprintf( stdout, "remainderl     : %Lf\n", f1);

  f1 = remquol(29.0,3.0,&i1);
  fprintf( stdout, "remquol        : %Lf\n", f1);

  f1 = rintl(0.5);
  fprintf( stdout, "rintl          : %Lf\n", f1);
  f1 = rintl(-0.5);
  fprintf( stdout, "rintl          : %Lf\n", f1);

  f1 = roundl(0.5);
  fprintf( stdout, "roundl         : %Lf\n", f1);
  f1 = roundl(-0.5);
  fprintf( stdout, "roundl         : %Lf\n", f1);

  f1 = scalblnl(1.2,3);
  fprintf( stdout, "scalblnl       : %Lf\n", f1);

  f1 = scalbnl(1.2,3);
  fprintf( stdout, "scalbnl        : %Lf\n", f1);

  /* no type-specific variant */
  i1 = signbit(1.0);
  fprintf( stdout, "signbit        : %i\n", i1);

  f1 = sinl(M_PI_4);
  fprintf( stdout, "sinl           : %Lf\n", f1);

  f1 = sinhl(M_PI_4);
  fprintf( stdout, "sinhl          : %Lf\n", f1);

  f1 = sqrtl(9.0);
  fprintf( stdout, "sqrtl          : %Lf\n", f1);

  f1 = tanl(M_PI_4);
  fprintf( stdout, "tanl           : %Lf\n", f1);

  f1 = tanhl(M_PI_4);
  fprintf( stdout, "tanhl          : %Lf\n", f1);

  f1 = tgammal(2.1);
  fprintf( stdout, "tgammal        : %Lf\n", f1);

  f1 = truncl(3.5);
  fprintf( stdout, "truncl         : %Lf\n", f1);

  f1 = y0l(1.2);
  fprintf( stdout, "y0l            : %Lf\n", f1);

  f1 = y1l(1.2);
  fprintf( stdout, "y1l            : %Lf\n", f1);

  f1 = ynl(3,1.2);
  fprintf( stdout, "ynl            : %Lf\n", f1);
#endif
}
Exemplo n.º 18
0
static int
do_test (void)
{
  int result = 0;

#ifndef NO_LONG_DOUBLE
  {
    long double x = 0x100000001ll + (long double) 0.5;
    long double q;
    long double r;

    r = modfl (x, &q);
    if (q != (long double) 0x100000001ll || r != 0.5)
      {
	printf ("modfl (%Lg, ...) failed\n", x);
	result = 1;
      }
  }

  {
    long double x;
    long double m;
    long double r;
    int e;
    int i;

# if LDBL_MANT_DIG == 64
    m = 0xf.fffffffffffffffp-4L;
# elif LDBL_MANT_DIG == 106
    /* This has to match the mantissa of LDBL_MAX which actually does have a
       missing bit in the middle.  */
    m = 0x1.fffffffffffff7ffffffffffff8p-1L;
# elif LDBL_MANT_DIG == 113
    m = 0x1.ffffffffffffffffffffffffffffp-1L;
# else
#  error "Please adjust"
# endif

    for (i = LDBL_MAX_EXP, x = LDBL_MAX; i >= LDBL_MIN_EXP; --i, x /= 2.0L)
      {
	printf ("2^%d: ", i);

	r = frexpl (x, &e);
	if (r != m)
	  {
	    printf ("mantissa incorrect: %.20La\n", r);
	    result = 1;
	    continue;
	  }
	if (e != i)
	  {
	    printf ("exponent wrong %d (%.20Lg)\n", e, x);
	    result = 1;
	    continue;
	  }
	puts ("ok");
      }

    for (i = LDBL_MIN_EXP, x = LDBL_MIN; i >= LDBL_MIN_EXP - LDBL_MANT_DIG + 1;
	 --i, x /= 2.0L)
      {
        printf ("2^%d: ", i);

        r = frexpl (x, &e);
        if (r != 0.5L)
          {
            printf ("mantissa incorrect: %.20La\n", r);
            result = 1;
            continue;
          }
        if (e != i)
          {
            printf ("exponent wrong %d (%.20Lg)\n", e, x);
            result = 1;
            continue;
          }
        puts ("ok");
      }

  }

# if 0
  {
    int e;
    long double r = frexpl (LDBL_MIN * LDBL_EPSILON, &e);

    if (r != 0.5)
      {
	printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): mantissa wrong: %Lg\n",
		r);
	result = 1;
      }
    else if (e != -16444)
      {
	printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): exponent wrong: %d\n",
		e);
	result = 1;
      }
  }
# endif
#endif

  {
    double x = 0x100000001ll + (double) 0.5;
    double q;
    double r;

    r = modf (x, &q);
    if (q != (double) 0x100000001ll || r != 0.5)
      {
	printf ("modf (%g, ...) failed\n", x);
	result = 1;
      }
  }

  {
    union ieee754_float v1;
    union ieee754_float v2;
    float f;

    v1.f = f = FLT_MIN;
    if (fpclassify (f) != FP_NORMAL)
      {
	printf ("fpclassify (FLT_MIN) failed: %d\n", fpclassify (f));
	result = 1;
      }
    f = nextafterf (f, FLT_MIN / 2.0f);
    if (fpclassify (f) != FP_SUBNORMAL)
      {
	printf ("fpclassify (FLT_MIN-epsilon) failed: %d\n", fpclassify (f));
	result = 1;
      }
    v2.f = f = nextafterf (f, FLT_MIN);
    if (fpclassify (f) != FP_NORMAL)
      {
	printf ("fpclassify (FLT_MIN-epsilon+epsilon) failed: %d\n",
		fpclassify (f));
	result = 1;
      }

    if (v1.ieee.mantissa != v2.ieee.mantissa)
      {
	printf ("FLT_MIN: mantissa differs: %8x vs %8x\n",
		v1.ieee.mantissa, v2.ieee.mantissa);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("FLT_MIN: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("FLT_MIN: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    v1.f = f = -FLT_MIN;
    if (fpclassify (f) != FP_NORMAL)
      {
	printf ("fpclassify (-FLT_MIN) failed: %d\n", fpclassify (f));
	result = 1;
      }
    f = nextafterf (f, -FLT_MIN / 2.0f);
    if (fpclassify (f) != FP_SUBNORMAL)
      {
	printf ("fpclassify (-FLT_MIN-epsilon) failed: %d\n", fpclassify (f));
	result = 1;
      }
    v2.f = f = nextafterf (f, -FLT_MIN);
    if (fpclassify (f) != FP_NORMAL)
      {
	printf ("fpclassify (-FLT_MIN-epsilon+epsilon) failed: %d\n",
		fpclassify (f));
	result = 1;
      }

    if (v1.ieee.mantissa != v2.ieee.mantissa)
      {
	printf ("-FLT_MIN: mantissa differs: %8x vs %8x\n",
		v1.ieee.mantissa, v2.ieee.mantissa);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("-FLT_MIN: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("-FLT_MIN: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    f = FLT_MAX;
    if (fpclassify (f) != FP_NORMAL)
      {
	printf ("fpclassify (FLT_MAX) failed: %d\n", fpclassify (f));
	result = 1;
      }
    f = nextafterf (f, INFINITY);
    if (fpclassify (f) != FP_INFINITE)
      {
	printf ("fpclassify (FLT_MAX+epsilon) failed: %d\n", fpclassify (f));
	result = 1;
      }

    f = -FLT_MAX;
    if (fpclassify (f) != FP_NORMAL)
      {
	printf ("fpclassify (-FLT_MAX) failed: %d\n", fpclassify (f));
	result = 1;
      }
    f = nextafterf (f, -INFINITY);
    if (fpclassify (f) != FP_INFINITE)
      {
	printf ("fpclassify (-FLT_MAX-epsilon) failed: %d\n", fpclassify (f));
	result = 1;
      }

    v1.f = f = 0.0625;
    f = nextafterf (f, 0.0);
    v2.f = f = nextafterf (f, 1.0);

    if (v1.ieee.mantissa != v2.ieee.mantissa)
      {
	printf ("0.0625f down: mantissa differs: %8x vs %8x\n",
		v1.ieee.mantissa, v2.ieee.mantissa);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("0.0625f down: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("0.0625f down: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    v1.f = f = 0.0625;
    f = nextafterf (f, 1.0);
    v2.f = f = nextafterf (f, 0.0);

    if (v1.ieee.mantissa != v2.ieee.mantissa)
      {
	printf ("0.0625f up: mantissa differs: %8x vs %8x\n",
		v1.ieee.mantissa, v2.ieee.mantissa);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("0.0625f up: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("0.0625f up: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    v1.f = f = -0.0625;
    f = nextafterf (f, 0.0);
    v2.f = f = nextafterf (f, -1.0);

    if (v1.ieee.mantissa != v2.ieee.mantissa)
      {
	printf ("-0.0625f up: mantissa differs: %8x vs %8x\n",
		v1.ieee.mantissa, v2.ieee.mantissa);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("-0.0625f up: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("-0.0625f up: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    v1.f = f = -0.0625;
    f = nextafterf (f, -1.0);
    v2.f = f = nextafterf (f, 0.0);

    if (v1.ieee.mantissa != v2.ieee.mantissa)
      {
	printf ("-0.0625f down: mantissa differs: %8x vs %8x\n",
		v1.ieee.mantissa, v2.ieee.mantissa);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("-0.0625f down: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("-0.0625f down: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    v1.f = f = 0.0f;
    f = nextafterf (f, 1.0);
    v2.f = nextafterf (f, -1.0);

    if (v1.ieee.mantissa != v2.ieee.mantissa)
      {
	printf ("0.0f up: mantissa differs: %8x vs %8x\n",
		v1.ieee.mantissa, v2.ieee.mantissa);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("0.0f up: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (0 != v2.ieee.negative)
      {
	printf ("0.0f up: negative differs: 0 vs %d\n",
		v2.ieee.negative);
	result = 1;
      }

    v1.f = f = 0.0f;
    f = nextafterf (f, -1.0);
    v2.f = nextafterf (f, 1.0);

    if (v1.ieee.mantissa != v2.ieee.mantissa)
      {
	printf ("0.0f down: mantissa differs: %8x vs %8x\n",
		v1.ieee.mantissa, v2.ieee.mantissa);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("0.0f down: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (1 != v2.ieee.negative)
      {
	printf ("0.0f down: negative differs: 1 vs %d\n",
		v2.ieee.negative);
	result = 1;
      }

    if (nextafterf (0.0f, INFINITY) != nextafterf (0.0f, 1.0f)
        || nextafterf (-0.0f, INFINITY) != nextafterf (-0.0f, 1.0f)
        || nextafterf (0.0f, -INFINITY) != nextafterf (0.0f, -1.0f)
        || nextafterf (-0.0f, -INFINITY) != nextafterf (-0.0f, -1.0f))
      {
	printf ("nextafterf (+-0, +-Inf) != nextafterf (+-0, +-1)\n");
	result = 1;
      }

    if (nexttowardf (0.0f, INFINITY) != nexttowardf (0.0f, 1.0f)
        || nexttowardf (-0.0f, INFINITY) != nexttowardf (-0.0f, 1.0f)
        || nexttowardf (0.0f, -INFINITY) != nexttowardf (0.0f, -1.0f)
        || nexttowardf (-0.0f, -INFINITY) != nexttowardf (-0.0f, -1.0f))
      {
	printf ("nexttowardf (+-0, +-Inf) != nexttowardf (+-0, +-1)\n");
	result = 1;
      }
  }

  {
    union ieee754_double v1;
    union ieee754_double v2;
    double d;

    v1.d = d = DBL_MIN;
    if (fpclassify (d) != FP_NORMAL)
      {
	printf ("fpclassify (DBL_MIN) failed: %d\n", fpclassify (d));
	result = 1;
      }
    d = nextafter (d, DBL_MIN / 2.0);
    if (fpclassify (d) != FP_SUBNORMAL)
      {
	printf ("fpclassify (DBL_MIN-epsilon) failed: %d\n", fpclassify (d));
	result = 1;
      }
    v2.d = d = nextafter (d, DBL_MIN);
    if (fpclassify (d) != FP_NORMAL)
      {
	printf ("fpclassify (DBL_MIN-epsilon+epsilon) failed: %d\n",
		fpclassify (d));
	result = 1;
      }

    if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
      {
	printf ("DBL_MIN: mantissa0 differs: %8x vs %8x\n",
		v1.ieee.mantissa0, v2.ieee.mantissa0);
	result = 1;
      }
    if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
      {
	printf ("DBL_MIN: mantissa1 differs: %8x vs %8x\n",
		v1.ieee.mantissa1, v2.ieee.mantissa1);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("DBL_MIN: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("DBL_MIN: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    v1.d = d = -DBL_MIN;
    if (fpclassify (d) != FP_NORMAL)
      {
	printf ("fpclassify (-DBL_MIN) failed: %d\n", fpclassify (d));
	result = 1;
      }
    d = nextafter (d, -DBL_MIN / 2.0);
    if (fpclassify (d) != FP_SUBNORMAL)
      {
	printf ("fpclassify (-DBL_MIN-epsilon) failed: %d\n", fpclassify (d));
	result = 1;
      }
    v2.d = d = nextafter (d, -DBL_MIN);
    if (fpclassify (d) != FP_NORMAL)
      {
	printf ("fpclassify (-DBL_MIN-epsilon+epsilon) failed: %d\n",
		fpclassify (d));
	result = 1;
      }

    if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
      {
	printf ("-DBL_MIN: mantissa0 differs: %8x vs %8x\n",
		v1.ieee.mantissa0, v2.ieee.mantissa0);
	result = 1;
      }
    if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
      {
	printf ("-DBL_MIN: mantissa1 differs: %8x vs %8x\n",
		v1.ieee.mantissa1, v2.ieee.mantissa1);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("-DBL_MIN: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("-DBL_MIN: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    d = DBL_MAX;
    if (fpclassify (d) != FP_NORMAL)
      {
	printf ("fpclassify (DBL_MAX) failed: %d\n", fpclassify (d));
	result = 1;
      }
    d = nextafter (d, INFINITY);
    if (fpclassify (d) != FP_INFINITE)
      {
	printf ("fpclassify (DBL_MAX+epsilon) failed: %d\n", fpclassify (d));
	result = 1;
      }

    d = -DBL_MAX;
    if (fpclassify (d) != FP_NORMAL)
      {
	printf ("fpclassify (-DBL_MAX) failed: %d\n", fpclassify (d));
	result = 1;
      }
    d = nextafter (d, -INFINITY);
    if (fpclassify (d) != FP_INFINITE)
      {
	printf ("fpclassify (-DBL_MAX-epsilon) failed: %d\n", fpclassify (d));
	result = 1;
      }

    v1.d = d = 0.0625;
    d = nextafter (d, 0.0);
    v2.d = d = nextafter (d, 1.0);

    if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
      {
	printf ("0.0625 down: mantissa0 differs: %8x vs %8x\n",
		v1.ieee.mantissa0, v2.ieee.mantissa0);
	result = 1;
      }
    if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
      {
	printf ("0.0625 down: mantissa1 differs: %8x vs %8x\n",
		v1.ieee.mantissa1, v2.ieee.mantissa1);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("0.0625 down: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("0.0625 down: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    v1.d = d = 0.0625;
    d = nextafter (d, 1.0);
    v2.d = d = nextafter (d, 0.0);

    if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
      {
	printf ("0.0625 up: mantissa0 differs: %8x vs %8x\n",
		v1.ieee.mantissa0, v2.ieee.mantissa0);
	result = 1;
      }
    if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
      {
	printf ("0.0625 up: mantissa1 differs: %8x vs %8x\n",
		v1.ieee.mantissa1, v2.ieee.mantissa1);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("0.0625 up: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("0.0625 up: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    v1.d = d = -0.0625;
    d = nextafter (d, 0.0);
    v2.d = d = nextafter (d, -1.0);

    if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
      {
	printf ("-0.0625 up: mantissa0 differs: %8x vs %8x\n",
		v1.ieee.mantissa0, v2.ieee.mantissa0);
	result = 1;
      }
    if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
      {
	printf ("-0.0625 up: mantissa1 differs: %8x vs %8x\n",
		v1.ieee.mantissa1, v2.ieee.mantissa1);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("-0.0625 up: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("-0.0625 up: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    v1.d = d = -0.0625;
    d = nextafter (d, -1.0);
    v2.d = d = nextafter (d, 0.0);

    if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
      {
	printf ("-0.0625 down: mantissa0 differs: %8x vs %8x\n",
		v1.ieee.mantissa0, v2.ieee.mantissa0);
	result = 1;
      }
    if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
      {
	printf ("-0.0625 down: mantissa1 differs: %8x vs %8x\n",
		v1.ieee.mantissa1, v2.ieee.mantissa1);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("-0.0625 down: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (v1.ieee.negative != v2.ieee.negative)
      {
	printf ("-0.0625 down: negative differs: %d vs %d\n",
		v1.ieee.negative, v2.ieee.negative);
	result = 1;
      }

    v1.d = d = 0.0;
    d = nextafter (d, 1.0);
    v2.d = nextafter (d, -1.0);

    if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
      {
	printf ("0.0 up: mantissa0 differs: %8x vs %8x\n",
		v1.ieee.mantissa0, v2.ieee.mantissa0);
	result = 1;
      }
    if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
      {
	printf ("0.0 up: mantissa1 differs: %8x vs %8x\n",
		v1.ieee.mantissa1, v2.ieee.mantissa1);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("0.0 up: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (0 != v2.ieee.negative)
      {
	printf ("0.0 up: negative differs: 0 vs %d\n",
		v2.ieee.negative);
	result = 1;
      }

    v1.d = d = 0.0;
    d = nextafter (d, -1.0);
    v2.d = nextafter (d, 1.0);

    if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
      {
	printf ("0.0 down: mantissa0 differs: %8x vs %8x\n",
		v1.ieee.mantissa0, v2.ieee.mantissa0);
	result = 1;
      }
    if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
      {
	printf ("0.0 down: mantissa1 differs: %8x vs %8x\n",
		v1.ieee.mantissa1, v2.ieee.mantissa1);
	result = 1;
      }
    if (v1.ieee.exponent != v2.ieee.exponent)
      {
	printf ("0.0 down: exponent differs: %4x vs %4x\n",
		v1.ieee.exponent, v2.ieee.exponent);
	result = 1;
      }
    if (1 != v2.ieee.negative)
      {
	printf ("0.0 down: negative differs: 1 vs %d\n",
		v2.ieee.negative);
	result = 1;
      }

    if (nextafter (0.0, INFINITY) != nextafter (0.0, 1.0)
        || nextafter (-0.0, INFINITY) != nextafter (-0.0, 1.0)
        || nextafter (0.0, -INFINITY) != nextafter (0.0, -1.0)
        || nextafter (-0.0, -INFINITY) != nextafter (-0.0, -1.0))
      {
	printf ("nextafter (+-0, +-Inf) != nextafter (+-0, +-1)\n");
	result = 1;
      }

    if (nexttoward (0.0, INFINITY) != nexttoward (0.0, 1.0)
        || nexttoward (-0.0, INFINITY) != nexttoward (-0.0, 1.0)
        || nexttoward (0.0, -INFINITY) != nexttoward (0.0, -1.0)
        || nexttoward (-0.0, -INFINITY) != nexttoward (-0.0, -1.0))
      {
	printf ("nexttoward (+-0, +-Inf) != nexttoward (+-0, +-1)\n");
	result = 1;
      }
  }

#ifndef NO_LONG_DOUBLE
  {
    long double v1, v2;

    v1 = LDBL_MIN;
    if (fpclassify (v1) != FP_NORMAL)
      {
	printf ("fpclassify (LDBL_MIN) failed: %d (%La)\n",
		fpclassify (v1), v1);
	result = 1;
      }
    v2 = nextafterl (v1, LDBL_MIN / 2.0);
    if (fpclassify (v2) != FP_SUBNORMAL)
      {
	printf ("fpclassify (LDBL_MIN-epsilon) failed: %d (%La)\n",
		fpclassify (v2), v2);
	result = 1;
      }
    v2 = nextafterl (v2, LDBL_MIN);
    if (fpclassify (v2) != FP_NORMAL)
      {
	printf ("fpclassify (LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
		fpclassify (v2), v2);
	result = 1;
      }

    if (v1 != v2)
      {
	printf ("LDBL_MIN-epsilon+epsilon != LDBL_MIN: %La vs %La\n", v2, v1);
	result = 1;
      }

    v1 = -LDBL_MIN;
    if (fpclassify (v1) != FP_NORMAL)
      {
	printf ("fpclassify (-LDBL_MIN) failed: %d (%La)\n",
		fpclassify (v1), v1);
	result = 1;
      }
    v2 = nextafterl (v1, -LDBL_MIN / 2.0);
    if (fpclassify (v2) != FP_SUBNORMAL)
      {
	printf ("fpclassify (-LDBL_MIN-epsilon) failed: %d (%La)\n",
		fpclassify (v2), v2);
	result = 1;
      }
    v2 = nextafterl (v2, -LDBL_MIN);
    if (fpclassify (v2) != FP_NORMAL)
      {
	printf ("fpclassify (-LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
		fpclassify (v2), v2);
	result = 1;
      }

    if (v1 != v2)
      {
	printf ("-LDBL_MIN-epsilon+epsilon != -LDBL_MIN: %La vs %La\n", v2, v1);
	result = 1;
      }

    v1 = LDBL_MAX;
    if (fpclassify (v1) != FP_NORMAL)
      {
	printf ("fpclassify (LDBL_MAX) failed: %d (%La)\n",
		fpclassify (v1), v1);
	result = 1;
      }
    v2 = nextafterl (v1, INFINITY);
    if (fpclassify (v2) != FP_INFINITE)
      {
	printf ("fpclassify (LDBL_MAX+epsilon) failed: %d (%La)\n",
		fpclassify (v2), v2);
	result = 1;
      }

    v1 = -LDBL_MAX;
    if (fpclassify (v1) != FP_NORMAL)
      {
	printf ("fpclassify (-LDBL_MAX) failed: %d (%La)\n",
		fpclassify (v1), v1);
	result = 1;
      }
    v2 = nextafterl (v1, -INFINITY);
    if (fpclassify (v2) != FP_INFINITE)
      {
	printf ("fpclassify (-LDBL_MAX-epsilon) failed: %d (%La)\n",
		fpclassify (v2), v2);
	result = 1;
      }

    v1 = 0.0625;
    v2 = nextafterl (v1, 0.0);
    v2 = nextafterl (v2, 1.0);

    if (v1 != v2)
      {
	printf ("0.0625L-epsilon+epsilon != 0.0625L: %La vs %La\n", v2, v1);
	result = 1;
      }

    v1 = 0.0625;
    v2 = nextafterl (v1, 1.0);
    v2 = nextafterl (v2, 0.0);

    if (v1 != v2)
      {
	printf ("0.0625L+epsilon-epsilon != 0.0625L: %La vs %La\n", v2, v1);
	result = 1;
      }

    v1 = -0.0625;
    v2 = nextafterl (v1, 0.0);
    v2 = nextafterl (v2, -1.0);

    if (v1 != v2)
      {
	printf ("-0.0625L+epsilon-epsilon != -0.0625L: %La vs %La\n", v2, v1);
	result = 1;
      }

    v1 = -0.0625;
    v2 = nextafterl (v1, -1.0);
    v2 = nextafterl (v2, 0.0);

    if (v1 != v2)
      {
	printf ("-0.0625L-epsilon+epsilon != -0.0625L: %La vs %La\n", v2, v1);
	result = 1;
      }

    v1 = 0.0;
    v2 = nextafterl (v1, 1.0);
    v2 = nextafterl (v2, -1.0);

    if (v1 != v2)
      {
	printf ("0.0+epsilon-epsilon != 0.0L: %La vs %La\n", v2, v1);
	result = 1;
      }
    if (signbit (v2))
      {
	printf ("0.0+epsilon-epsilon is negative\n");
	result = 1;
      }

    v1 = 0.0;
    v2 = nextafterl (v1, -1.0);
    v2 = nextafterl (v2, 1.0);

    if (v1 != v2)
      {
	printf ("0.0-epsilon+epsilon != 0.0L: %La vs %La\n", v2, v1);
	result = 1;
      }
    if (!signbit (v2))
      {
	printf ("0.0-epsilon+epsilon is positive\n");
	result = 1;
      }

    if (nextafterl (0.0, INFINITY) != nextafterl (0.0, 1.0)
        || nextafterl (-0.0, INFINITY) != nextafterl (-0.0, 1.0)
        || nextafterl (0.0, -INFINITY) != nextafterl (0.0, -1.0)
        || nextafterl (-0.0, -INFINITY) != nextafterl (-0.0, -1.0))
      {
	printf ("nextafterl (+-0, +-Inf) != nextafterl (+-0, +-1)\n");
	result = 1;
      }

    if (nexttowardl (0.0L, INFINITY) != nexttowardl (0.0L, 1.0L)
        || nexttowardl (-0.0L, INFINITY) != nexttowardl (-0.0L, 1.0L)
        || nexttowardl (0.0L, -INFINITY) != nexttowardl (0.0L, -1.0L)
        || nexttowardl (-0.0L, -INFINITY) != nexttowardl (-0.0L, -1.0L))
      {
	printf ("nexttowardl (+-0, +-Inf) != nexttowardl (+-0, +-1)\n");
	result = 1;
      }
  }
#endif

  if (! isnormal (FLT_MIN))
    {
      puts ("isnormal (FLT_MIN) failed");
      result = 1;
    }
  if (! isnormal (DBL_MIN))
    {
      puts ("isnormal (DBL_MIN) failed");
      result = 1;
    }
#ifndef NO_LONG_DOUBLE
  if (! isnormal (LDBL_MIN))
    {
      puts ("isnormal (LDBL_MIN) failed");
      result = 1;
    }
#endif

#if defined (__i386__) || defined (__x86_64__)
  /* This is a test for the strange long doubles in x86 FPUs.  */
  {
    union
    {
      char b[10];
      long double d;
    } u =
      { .b = { 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0 } };

    if (fpclassify (u.d) != FP_NORMAL)
      {
	printf ("fpclassify (0x00008000000000000000) failed: %d (%Lg)\n",
		fpclassify (u.d), u.d);
	result = 1;
      }
  }

  /* Special qNaNs in x86 long double.  Test for scalbl.  */
  {
    union
    {
      char b[10];
      long double d;
    } u =
      { .b = { 0, 1, 0, 0, 0, 0, 0, 0xc0, 0xff, 0x7f } };
    long double r;

    r = scalbl (u.d, 0.0);
    if (!isnan (r))
      {
	puts ("scalbl (qNaN, 0) does not return NaN");
	result = 1;
      }
    else if (memcmp (&r, &u.d, sizeof (double)) != 0)
      {
	puts ("scalbl (qNaN, 0) does not return the same NaN");
	result = 1;
      }
  }
#endif

#ifndef NO_LONG_DOUBLE
  {
    long double r;

    feclearexcept (FE_ALL_EXCEPT);
    r = scalbl (LDBL_MIN, 2147483647);
    if (! isinf (r))
      {
	puts ("scalbl (LDBL_MIN, 2147483647) does not return Inf");
	result = 1;
      }
    else if (signbit (r) != 0)
      {
	puts ("scalbl (LDBL_MIN, 2147483647) returns -Inf");
	result = 1;
      }
    else if (fetestexcept (FE_UNDERFLOW))
      {
	puts ("scalbl (LDBL_MIN, 2147483647) raises underflow exception");
	result = 1;
      }

    feclearexcept (FE_ALL_EXCEPT);
    r = scalbl (LDBL_MAX, -2147483647);
    if (r != 0.0)
      {
	puts ("scalbl (LDBL_MAX, -2147483647) does not return 0");
	result = 1;
      }
    else if (signbit (r) != 0)
      {
	puts ("scalbl (LDBL_MAX, -2147483647) returns -Inf");
	result = 1;
      }
    else if (fetestexcept (FE_OVERFLOW))
      {
	puts ("scalbl (LDBL_MAX, -2147483647) raises overflow exception");
	result = 1;
      }
  }
#endif

  /* The tests here are very similar to tests earlier in this file,
     the important difference is just that there are no intervening
     union variables that cause some GCC versions to hide possible
     bugs in nextafter* implementation.  */
  if (nextafterf (nextafterf (FLT_MIN, FLT_MIN / 2.0), FLT_MIN) != FLT_MIN)
    {
      puts ("nextafterf FLT_MIN test failed");
      result = 1;
    }
  if (nextafterf (nextafterf (-FLT_MIN, -FLT_MIN / 2.0), -FLT_MIN)
      != -FLT_MIN)
    {
      puts ("nextafterf -FLT_MIN test failed");
      result = 1;
    }
  if (nextafter (nextafter (DBL_MIN, DBL_MIN / 2.0), DBL_MIN) != DBL_MIN)
    {
      puts ("nextafter DBL_MIN test failed");
      result = 1;
    }
  if (nextafter (nextafter (-DBL_MIN, -DBL_MIN / 2.0), -DBL_MIN) != -DBL_MIN)
    {
      puts ("nextafter -DBL_MIN test failed");
      result = 1;
    }
#ifndef NO_LONG_DOUBLE
  if (nextafterl (nextafterl (LDBL_MIN, LDBL_MIN / 2.0), LDBL_MIN)
      != LDBL_MIN)
    {
      puts ("nextafterl LDBL_MIN test failed");
      result = 1;
    }
  if (nextafterl (nextafterl (-LDBL_MIN, -LDBL_MIN / 2.0), -LDBL_MIN)
      != -LDBL_MIN)
    {
      puts ("nextafterl -LDBL_MIN test failed");
      result = 1;
    }
#endif

  volatile float f1 = FLT_MAX;
  volatile float f2 = FLT_MAX / 2;
  (void) &f1;
  (void) &f2;
  feclearexcept (FE_ALL_EXCEPT);
  f2 += f1;
#if defined(FE_OVERFLOW) && defined(FE_INEXACT)
  int fe = fetestexcept (FE_ALL_EXCEPT);
  if (EXCEPTION_TESTS (float) && fe != (FE_OVERFLOW | FE_INEXACT))
    {
      printf ("float overflow test failed: %x\n", fe);
      result = 1;
    }
#endif

  volatile double d1 = DBL_MAX;
  volatile double d2 = DBL_MAX / 2;
  (void) &d1;
  (void) &d2;
  feclearexcept (FE_ALL_EXCEPT);
  d2 += d1;
#if defined(FE_OVERFLOW) && defined(FE_INEXACT)
  fe = fetestexcept (FE_ALL_EXCEPT);
  if (EXCEPTION_TESTS (double) && fe != (FE_OVERFLOW | FE_INEXACT))
    {
      printf ("double overflow test failed: %x\n", fe);
      result = 1;
    }
#endif

#ifndef NO_LONG_DOUBLE
  volatile long double ld1 = LDBL_MAX;
  volatile long double ld2 = LDBL_MAX / 2;
  (void) &ld1;
  (void) &ld2;
  feclearexcept (FE_ALL_EXCEPT);
  ld2 += ld1;
# if defined(FE_OVERFLOW) && defined(FE_INEXACT)
  fe = fetestexcept (FE_ALL_EXCEPT);
  if (EXCEPTION_TESTS (long double) && fe != (FE_OVERFLOW | FE_INEXACT))
    {
      printf ("long double overflow test failed: %x\n", fe);
      result = 1;
    }
# endif
#endif

#if !defined NO_LONG_DOUBLE && LDBL_MANT_DIG == 113
  volatile long double ld3 = 0x1.0000000000010000000100000001p+1;
  volatile long double ld4 = 0x1.0000000000000000000000000001p+1;
  (void) &ld3;
  (void) &ld4;
  ld3 -= ld4;
  if (ld3 != 0x1.0p-47)
    {
      printf ("long double subtraction test failed %.28La\n", ld3);
      result = 1;
    }
#endif

/* Skip testing IBM long double format, for 2 reasons:
   1) it only supports FE_TONEAREST
   2) nextafter (0.0, 1.0) == nextafterl (0.0L, 1.0L), so
      nextafter (0.0, 1.0) / 16.0L will be 0.0L.  */
#if !defined NO_LONG_DOUBLE && LDBL_MANT_DIG >= DBL_MANT_DIG + 4 \
    && LDBL_MANT_DIG != 106
  int oldmode = fegetround ();
  int j;
  for (j = 0; j < 4; j++)
    {
      int mode;
      int i;
      int k = 0;
      const char *mstr;
      switch (j)
	{
#ifdef FE_TONEAREST
	case 0:
	  mode = FE_TONEAREST;
	  mstr = "nearest";
	  k = 8;
	  break;
#endif
#ifdef FE_DOWNWARD
	case 1:
	  mode = FE_DOWNWARD;
	  mstr = "-inf";
	  break;
#endif
#ifdef FE_UPWARD
	case 2:
	  mode = FE_UPWARD;
	  mstr = "+inf";
	  k = 15;
	  break;
#endif
#ifdef FE_TOWARDZERO
	case 3:
	  mode = FE_TOWARDZERO;
	  mstr = "0";
	  break;
#endif
	default:
	  continue;
	}

      volatile long double ld5 = nextafter (0.0, 1.0) / 16.0L;
      volatile double d5;
      (void) &ld5;
      for (i = 0; i <= 32; i++)
	{
	  if (fesetround (mode))
	    {
	      printf ("failed to set rounding mode to %s\n", mstr);
	      if (ROUNDING_TESTS (long double, mode)
		  && ROUNDING_TESTS (double, mode))
		result = 1;
	      else
		puts ("ignoring this failure");
	      break;
	    }
	  d5 = ld5 * i;
	  (void) &d5;
	  fesetround (oldmode);
	  if (d5 != ((j == 0 && i == 8) ? 0 : (i + k) / 16)
		    * nextafter (0.0, 1.0))
	    {
	      printf ("%La incorrectly rounded to %s as %a\n",
		      ld5 * i, mstr, d5);
	      if (ROUNDING_TESTS (long double, mode)
		  && ROUNDING_TESTS (double, mode))
		result = 1;
	      else
		puts ("ignoring this failure");
	    }
Exemplo n.º 19
0
static char *__format_double(long double value, int flags, int precision) {
	char *int_part;
	char *dec_part;
	char *string;
	long double i;

	if (isnan(value)) {
		if (flags & FLAG_UPPER) {
			return strdup("NAN");
		}
		else {
			return strdup("nan");
		}
	}

	if (isinf(value)) {
		if (flags & FLAG_UPPER) {
			if (value < 0) {
				return strdup("-INF");
			}
			else {
				if (flags & FLAG_SIGN) {
					return strdup("+INF");
				}
				else {
					return strdup("INF");
				}
			}
		}
		else {
			if (value < 0) {
				return strdup("-inf");
			}
			else {
				if (flags & FLAG_SIGN) {
					return strdup("+inf");
				}
				else {
					return strdup("inf");
				}
			}
		}
	}

	if (flags & FLAG_EXP || (flags & FLAG_MEXP && value > 1000000000)) {
		i = log10l(value);
		value /= powl(10, floorl(i));

		int_part = __format_double(value, flags & ~(FLAG_EXP), precision);
		dec_part = __format_int(i, flags | FLAG_SIGN);

		string = strvcat(int_part, (flags & FLAG_UPPER) ? "E" : "e", dec_part, NULL);

		free(int_part);
		free(dec_part);
	}
	else {
		value = modfl(value, &i);

		if (value > 2000000000) {
			int_part = __format_double_int(i, flags);
		}
		else {
			int_part = __format_int(i, flags);
		}
		dec_part = __format_double_frac(value, flags, precision);

		if (i == 0.0 && value < 0) {
			if (value != 0.0 || flags & FLAG_ALT) {
				string = strvcat("-", int_part, ".", dec_part, NULL);
			}
			else {
				string = strvcat("-", int_part, NULL);
			}
		}
		else {
			if (value != 0.0 || flags & FLAG_ALT) {
				string = strvcat(int_part, ".", dec_part, NULL);
			}
			else {
				string = strdup(int_part);
			}
		}

		free(int_part);
		free(dec_part);
	}

	return string;
}
Exemplo n.º 20
0
static int testl(long double long_double_x, int int_x, long long_x)
{
int r = 0;
r += __finitel(long_double_x);
r += __fpclassifyl(long_double_x);
r += __isinfl(long_double_x);
r += __isnanl(long_double_x);
r += __signbitl(long_double_x);
r += acoshl(long_double_x);
r += acosl(long_double_x);
r += asinhl(long_double_x);
r += asinl(long_double_x);
r += atan2l(long_double_x, long_double_x);
r += atanhl(long_double_x);
r += atanl(long_double_x);
r += cbrtl(long_double_x);
r += ceill(long_double_x);
r += copysignl(long_double_x, long_double_x);
r += coshl(long_double_x);
r += cosl(long_double_x);
r += erfcl(long_double_x);
r += erfl(long_double_x);
r += exp2l(long_double_x);
r += expl(long_double_x);
r += expm1l(long_double_x);
r += fabsl(long_double_x);
r += fdiml(long_double_x, long_double_x);
r += floorl(long_double_x);
r += fmal(long_double_x, long_double_x, long_double_x);
r += fmaxl(long_double_x, long_double_x);
r += fminl(long_double_x, long_double_x);
r += fmodl(long_double_x, long_double_x);
r += frexpl(long_double_x, &int_x);
r += hypotl(long_double_x, long_double_x);
r += ilogbl(long_double_x);
r += ldexpl(long_double_x, int_x);
r += lgammal(long_double_x);
r += llrintl(long_double_x);
r += llroundl(long_double_x);
r += log10l(long_double_x);
r += log1pl(long_double_x);
r += log2l(long_double_x);
r += logbl(long_double_x);
r += logl(long_double_x);
r += lrintl(long_double_x);
r += lroundl(long_double_x);
r += modfl(long_double_x, &long_double_x);
r += nearbyintl(long_double_x);
r += nextafterl(long_double_x, long_double_x);
r += nexttowardl(long_double_x, long_double_x);
r += powl(long_double_x, long_double_x);
r += remainderl(long_double_x, long_double_x);
r += remquol(long_double_x, long_double_x, &int_x);
r += rintl(long_double_x);
r += roundl(long_double_x);
r += scalblnl(long_double_x, long_x);
r += scalbnl(long_double_x, int_x);
r += sinhl(long_double_x);
r += sinl(long_double_x);
r += sqrtl(long_double_x);
r += tanhl(long_double_x);
r += tanl(long_double_x);
r += tgammal(long_double_x);
r += truncl(long_double_x);
return r;
}
Exemplo n.º 21
0
TCylinderElasticBoundary* TCylinderElasticBoundary::Initialize()
{
    //LOG(INFO) << "Start boundary creation";
	/*
	this->nodes = new TNode*[this->nodesCount];

    for(int n = 0; n < 120; ++n) {
        for (int i = 0; i < 120; i++) {
            this->nodes[i+n*120] = new TFixedElasticNode();
        }
    }

    for(int n = 0; n < 120; ++n) {
        for (int i = 0; i < 120; i++) {
            long double x = float(n) / float(120);
            long double y = this->yCenter - this->radius * cos(-M_PI * 2 * (double)(119-i)/119);
            long double z = this->zCenter + this->radius * sin(-M_PI * 2 * (double)(119-i)/119);

            this->nodes[i+n*120]->x = x;
            this->nodes[i+n*120]->xRef = x;
            this->nodes[i+n*120]->xVel = 0;
            this->nodes[i+n*120]->xForce = 0;

            this->nodes[i+n*120]->y = y;
            this->nodes[i+n*120]->yRef = y;
            this->nodes[i+n*120]->yVel = 0;
            this->nodes[i+n*120]->yForce = 0;

            this->nodes[i+n*120]->z = z;
            this->nodes[i+n*120]->zRef = z;
            this->nodes[i+n*120]->zVel = 0;
            this->nodes[i+n*120]->zForce = 0;
        }
    }

    for(int n = 0; n < 120; ++n) {
        for (int i = 0; i < 120; i++) {
            this->nodes[i+n*120]->boundary = this;

            if (n < 119)
            {
                this->nodes[i+n*120]->neighbors.next = this->nodes[i+(n+1)*120];
                this->nodes[i+n*120]->neighbors.initialDistanceNext = TNode::distance_3d(this->nodes[i+n*120], this->nodes[i+n*120]->neighbors.next);
            }
            if (n > 0)
            {
                this->nodes[i+n*120]->neighbors.prev = this->nodes[i+(n-1)*120];
                this->nodes[i+n*120]->neighbors.initialDistancePrev = TNode::distance_3d(this->nodes[i+n*120], this->nodes[i+n*120]->neighbors.prev);
            }

            if (this->nodes[i+n*120]->neighbors.prev != nullptr && this->nodes[i+n*120]->neighbors.next != nullptr )
            {
                this->nodes[i+n*120]->neighbors.initialCurvatures[OX] = TNode::curvature(
                    this->nodes[i+n*120],
                    this->nodes[i+n*120]->neighbors.next,
                    this->nodes[i+n*120]->neighbors.prev,
                    TNode::Ox
                );
                this->nodes[i+n*120]->neighbors.initialCurvatures[OY] = TNode::curvature(
                    this->nodes[i+n*120],
                    this->nodes[i+n*120]->neighbors.next,
                    this->nodes[i+n*120]->neighbors.prev,
                    TNode::Oy
                );
                this->nodes[i+n*120]->neighbors.initialCurvatures[OZ] = TNode::curvature(
                    this->nodes[i+n*120],
                    this->nodes[i+n*120]->neighbors.next,
                    this->nodes[i+n*120]->neighbors.prev,
                    TNode::Oz
                );
            }
        }
    }
	*/

	this->step = 0.01; // 0.069;
	long double iPart = 0.;
	//this->height = 1.0;

	modfl(this->height / this->step, &iPart);
	int endIndex = (int)iPart;
	this->height_nodes = endIndex + 1;

	modfl(this->radius*2.*M_PI / this->step, &iPart);
	endIndex = (int)iPart;
	this->radius_nodes = endIndex;
	this->nodesCount = this->height_nodes*this->radius_nodes;
	this->nodes = new TNode*[this->nodesCount];

	for (int n = 0; n < this->height_nodes; ++n) {
		for (int i = 0; i < this->radius_nodes; i++) {
			this->nodes[i + n*this->radius_nodes] = new TFixedElasticNode();
			//this->nodes[i + n * 120]->;
		}
	}


	double rc, stiffness_plus = this->stiffness / 50;
	double iRadius = (double) this->radius_nodes;
	double iHeight = (double) this->height_nodes - 1.;
	int cx = this->height_nodes/2., cy = 3.*this->radius_nodes/4., Rpip = this->radius_nodes/10., ix, iy;

	for (int n = 0; n < this->height_nodes; ++n) {
		for (int i = 0; i < this->radius_nodes; i++) {
			long double x = this->height*float(n) / iHeight;
			long double y = this->yCenter + this->radius * cos(-M_PI * 2 * (iRadius-i) / iRadius);
			long double z = this->zCenter + this->radius * sin(-M_PI * 2 * (iRadius-i) / iRadius);

			this->nodes[i + n*this->radius_nodes]->x = x;
			this->nodes[i + n*this->radius_nodes]->xRef = x;
			this->nodes[i + n*this->radius_nodes]->xVel = 0;
			this->nodes[i + n*this->radius_nodes]->xForce = 0;

			this->nodes[i + n*this->radius_nodes]->y = y;
			this->nodes[i + n*this->radius_nodes]->yRef = y;
			this->nodes[i + n*this->radius_nodes]->yVel = 0;
			this->nodes[i + n*this->radius_nodes]->yForce = 0;

			this->nodes[i + n*this->radius_nodes]->z = z;
			this->nodes[i + n*this->radius_nodes]->zRef = z;
			this->nodes[i + n*this->radius_nodes]->zVel = 0;
			this->nodes[i + n*this->radius_nodes]->zForce = 0;

			/*
			ix = abs(n-cx);
			iy = abs(i-cy);
			rc = sqrt((double)(ix*ix + iy*iy));
			if (rc <= Rpip)
				//this->nodes[i + n * 120]->stretchingStiffness = this->stiffness*rc*rc + sin(rc/Rpip)*stiffness_plus;
				this->nodes[i + n * this->radius_nodes]->stretchingStiffness = stiffness_plus; //+(this->stiffness - stiffness_plus)*sqrt(rc);    //sin(rc*0.5*M_PI / Rpip);
			else
			this->nodes[i + n *this->radius_nodes]->stretchingStiffness = this->stiffness;
			*/
			// Verison 1 (not good)
			/*
			if ((n>=49 && n<=69) && (i>=20 && i<=39))
			this->nodes[i + n * 120]->stretchingStiffness = this->stiffness/100;
			else
			this->nodes[i + n * 120]->stretchingStiffness=this->stiffness;
			*/
		}
		this->zCenter += 0.005;
	}
	this->zCenter -= 0.005;
	printf("\nzCenter=%lf\n", this->zCenter);

	for (int n = 0; n < this->height_nodes; ++n) {
		for (int i = 0; i < this->radius_nodes; i++) {
			this->nodes[i + n*this->radius_nodes]->boundary = this;

			if (n <  this->height_nodes - 1)
			{
				this->nodes[i + n*this->radius_nodes]->neighbors.next = this->nodes[i + (n + 1) * this->radius_nodes];
				this->nodes[i + n*this->radius_nodes]->neighbors.initialDistanceNext =
					TNode::distance_3d(this->nodes[i + n * this->radius_nodes], this->nodes[i + n * this->radius_nodes]->neighbors.next);
			}
			if (n > 0)
			{
				this->nodes[i + n*this->radius_nodes]->neighbors.prev = this->nodes[i + (n - 1) * this->radius_nodes];
				this->nodes[i + n*this->radius_nodes]->neighbors.initialDistancePrev = TNode::distance_3d(this->nodes[i + n * this->radius_nodes], this->nodes[i + n * this->radius_nodes]->neighbors.prev);
			}

			if (this->nodes[i + n*this->radius_nodes]->neighbors.prev != nullptr && this->nodes[i + n * this->radius_nodes]->neighbors.next != nullptr)
			{
				this->nodes[i + n*this->radius_nodes]->neighbors.initialCurvatures[OX] = TNode::curvature(
					this->nodes[i + n*this->radius_nodes],
					this->nodes[i + n*this->radius_nodes]->neighbors.next,
					this->nodes[i + n*this->radius_nodes]->neighbors.prev,
					TNode::Ox
					);
				this->nodes[i + n*this->radius_nodes]->neighbors.initialCurvatures[OY] = TNode::curvature(
					this->nodes[i + n*this->radius_nodes],
					this->nodes[i + n*this->radius_nodes]->neighbors.next,
					this->nodes[i + n*this->radius_nodes]->neighbors.prev,
					TNode::Oy
					);
				this->nodes[i + n*this->radius_nodes]->neighbors.initialCurvatures[OZ] = TNode::curvature(
					this->nodes[i + n*this->radius_nodes],
					this->nodes[i + n*this->radius_nodes]->neighbors.next,
					this->nodes[i + n*this->radius_nodes]->neighbors.prev,
					TNode::Oz
					);
			}
		}
	}

	//TNode **CutNodes;
	//int **CutGrid;
	/*
	ncut = this->radius_nodes*this->radius_nodes/8.0 + this->radius_nodes/2.0+1;
	double x_level,z_level;
	int ix_stp_before = 0, ix_stp_after = this->height_nodes-1;
	int iy_start = ix_stp_before*this->radius_nodes;
	int scount = 0, nd_count, mcount=0;
	cut_nodes = new TNode* [2];
	for (int i = 0; i < 2; i++)
		cut_nodes[i] = new TNode[ncut];

	for (int i = 0; i <= 4; i++)
	{
		printf(" ->%lf, %lf", this->nodes[ix_stp_before*this->radius_nodes + i]->y, this->nodes[ix_stp_before*this->radius_nodes + i]->z);
	}
	printf("\n");

	for (int ix = 0; ix < 2; ix++)
	{
		x_level = ix == 0 ? this->nodes[ix_stp_before*this->radius_nodes]->x : this->nodes[ix_stp_after*this->radius_nodes]->x;
		for (int lv = 0; lv <= this->radius_nodes / 4; lv++)
		{

			z_level = this->nodes[ix_stp_before*this->radius_nodes + lv]->z;
			for (int i = 0 + lv; i <= this->radius_nodes / 2 - lv; i++)
			{
				cut_nodes[ix][scount].x = x_level;
				cut_nodes[ix][scount].y = this->nodes[ix_stp_before*this->radius_nodes + i]->y;
				cut_nodes[ix][scount].z = z_level;
				printf(" !!!->num=%d %lf, %lf, %lf", scount,cut_nodes[ix][scount].x, cut_nodes[ix][scount].y, cut_nodes[ix][scount].z);
				++scount;
			}
		}

		for (int lv = 1; lv <= this->radius_nodes / 4; lv++)
		{

			z_level = this->nodes[ix_stp_before*this->radius_nodes + this->radius_nodes - lv]->z;
			for (int i = 0 + lv; i <= this->radius_nodes / 2 - lv; i++)
			{
				cut_nodes[ix][scount].x = x_level;
				cut_nodes[ix][scount].y = this->nodes[ix_stp_before*this->radius_nodes + this->radius_nodes - i]->y;
				cut_nodes[ix][scount].z = z_level;
				printf(" ***->num = %d %lf, %lf, %lf", scount,cut_nodes[ix][scount].x, cut_nodes[ix][scount].y, cut_nodes[ix][scount].z);
				++scount;
			}
		}

	}

	//necut = ncut - 1;
	
	int ne = 0;
	//int begin_point = 0;
	int no_node = -1;
	int nmdl = this->radius_nodes / 2 + 1;
	int nlv,el;
	int ne_tmp;
	for (el = nmdl - 1, nlv = 0, ne_tmp = 0; el>1; el -= 2)
	{
		ne_tmp += el;
		nlv++;
	}
		
	necut = ne_tmp*2;
    cut_grid = new int*[necut];
	for (int i = 0; i < necut; i++)
		cut_grid[i] = new int[4];

	// выше середины
	int lv,point,nline;
	for (lv = 0, nline=nmdl, point=0; lv < nlv; lv++,nline-=2)
	{
		for (int i = 0; i < nline-1; i++)
		{
			if (i == 0)
			{
				cut_grid[ne][0] = point++;
				cut_grid[ne][1] = point;
				cut_grid[ne][2] = point+nline-1;
				cut_grid[ne][3] = -1;
				ne++;
			}
			else if (i == nline-2)
			{
				cut_grid[ne][0] = point++;
				cut_grid[ne][1] = point;
				cut_grid[ne][2] = point++ + (nline - 2);
				cut_grid[ne][3] = -1;
				//point += (nline - 2)+1;
				ne++;
			}
			else 
			{
				cut_grid[ne][0] = point++;
				cut_grid[ne][1] = point;
				cut_grid[ne][2] = point + (nline - 2) + 1;
				cut_grid[ne][3] = point + (nline - 2);
				ne++;
			}
			printf("\nel=%d : %d, %d, %d, %d", ne-1,cut_grid[ne-1][0], cut_grid[ne-1][1], cut_grid[ne-1][2], cut_grid[ne-1][3]);
		}
	}
	point += (nline - 2) + 2;

	// первая строка ниже
	//int in_mdline_point = this->radius_nodes / 2;
	//int begin_point = this->radius_nodes*this->radius_nodes /4 + this->radius_nodes/2;
	for (int i = 0, nline = nmdl; i < nline - 1; i++)
	{
		if (i == 0)
		{
			cut_grid[ne][0] = i;
			cut_grid[ne][1] = point;
			cut_grid[ne][2] = i+1;
			cut_grid[ne][3] = -1;
			ne++;
		}
		else if (i == nline - 2)
		{
			cut_grid[ne][0] = nline - 2;
			cut_grid[ne][1] = point;
			cut_grid[ne][2] = nline -1;
			cut_grid[ne][3] = -1;
			ne++;
		}
		else
		{
			cut_grid[ne][0] = i;
			cut_grid[ne][1] = point++;
			cut_grid[ne][2] = point;
			cut_grid[ne][3] = i +1;
			ne++;
		}

		printf("\nel=%d : %d, %d, %d, %d", ne - 1, cut_grid[ne - 1][0], cut_grid[ne - 1][1], cut_grid[ne - 1][2], cut_grid[ne - 1][3]);
	}
	point = point - (nmdl - 2) + 1;

	// последние строки
	for ( lv = 1, nline = nmdl-2; lv < nlv; lv++, nline -= 2)
	{
		for (int i = 0; i < nline - 1; i++)
		{
			if (i == 0)
			{
				cut_grid[ne][0] = point++;
				cut_grid[ne][1] = point + nline - 1;
				cut_grid[ne][2] = point;
				cut_grid[ne][3] = -1;
				ne++;
			}
			else if (i == nline - 2)
			{
				cut_grid[ne][0] = point++;
				cut_grid[ne][1] = point+ (nline - 2);
				cut_grid[ne][2] = point;
				cut_grid[ne][3] = -1;
				ne++;
			}
			else
			{
				cut_grid[ne][0] = point++;
				cut_grid[ne][1] = point + (nline - 2);
				cut_grid[ne][2] = point + (nline - 2) + 1;
				cut_grid[ne][3] = point;
				ne++;
			}
			printf("\nel=%d : %d, %d, %d, %d", ne - 1, cut_grid[ne - 1][0], cut_grid[ne - 1][1], cut_grid[ne - 1][2], cut_grid[ne - 1][3]);
		}
	}

	printf("\nall right!");
	*/
	/*
	double sum[] = { 0.0, 0.0 };
	int i1, i2, i3, i4;
	double xc, yc, zc;
	for (int ix = 0; ix < 2; ix++)
	for (int i = 0; i < necut; i++)
	{
		i1 = cut_grid[i][0];
		i2 = cut_grid[i][1];
		i3 = cut_grid[i][2];
		i4 = cut_grid[i][3];

		// calculate center of element
		if (i4 != -1) //square
		{
			xc = (cut_nodes[ix][i1].x + cut_nodes[ix][i2].x + cut_nodes[ix][i3].x + cut_nodes[ix][i4].x)*.25;
			yc = (cut_nodes[ix][i1].y + cut_nodes[ix][i2].y + cut_nodes[ix][i3].y + cut_nodes[ix][i4].y)*.25;
			zc = (cut_nodes[ix][i1].z + cut_nodes[ix][i2].z + cut_nodes[ix][i3].z + cut_nodes[ix][i4].z)*.25;
		}
		else //triangle
		{
			xc = (cut_nodes[ix][i1].x + cut_nodes[ix][i2].x + cut_nodes[ix][i3].x) / 3.;
			yc = (cut_nodes[ix][i1].y + cut_nodes[ix][i2].y + cut_nodes[ix][i3].y) / 3.;
			zc = (cut_nodes[ix][i1].z + cut_nodes[ix][i2].z + cut_nodes[ix][i3].z) / 3.;
		}

		// calculate S of element

		// calculate u in point (xc,yc,zc)

		//sum plus

	}
	*/
    //cnpy::NpyArray x_valves = cnpy::npy_load("aortic_valve_x.npy");
    //cnpy::NpyArray y_valves = cnpy::npy_load("aortic_valve_y.npy");
    //cnpy::NpyArray z_valves = cnpy::npy_load("aortic_valve_z.npy");

    //cnpy::NpyArray prev_indices = cnpy::npy_load("prev_indices.npy");
    //cnpy::NpyArray next_indices = cnpy::npy_load("next_indices.npy");
    //cnpy::NpyArray fixed_indices = cnpy::npy_load("fixed_indices.npy");
    //cnpy::NpyArray closed_indices = cnpy::npy_load("closed_indices.npy");

    //cnpy::NpyArray x_valves = cnpy::npy_load("cloned_valve_x.npy");
    //cnpy::NpyArray y_valves = cnpy::npy_load("cloned_valve_y.npy");
    //cnpy::NpyArray z_valves = cnpy::npy_load("cloned_valve_z.npy");

//    cnpy::NpyArray x_valves = cnpy::npy_load("cloned_closed_valves_x.npy");
//    cnpy::NpyArray y_valves = cnpy::npy_load("cloned_closed_valves_y.npy");
//    cnpy::NpyArray z_valves = cnpy::npy_load("cloned_closed_valves_z.npy");
//
//    //cnpy::NpyArray initial_force_x = cnpy::npy_load("cloned_closed_initial_force_x.npy");
//    //cnpy::NpyArray initial_force_y = cnpy::npy_load("cloned_closed_initial_force_y.npy");
//    //cnpy::NpyArray initial_force_z = cnpy::npy_load("cloned_closed_initial_force_z.npy");
//
//    cnpy::NpyArray prev_indices = cnpy::npy_load("cloned_closed_prev_indices.npy");
//    cnpy::NpyArray next_indices = cnpy::npy_load("cloned_closed_next_indices.npy");
//    cnpy::NpyArray fixed_indices = cnpy::npy_load("cloned_closed_fixed_indices.npy");
//    //cnpy::NpyArray closed_indices = cnpy::npy_load("cloned_closed_indices.np_steppedy");
//
//    float *x_loaded_data = reinterpret_cast<float *>(x_valves.data);
//    float *y_loaded_data = reinterpret_cast<float *>(y_valves.data);
//    float *z_loaded_data = reinterpret_cast<float *>(z_valves.data);
//
//    //float *initial_force_x_data = reinterpret_cast<float *>(initial_force_x.data);
//    //float *initial_force_y_data = reinterpret_cast<float *>(initial_force_y.data);
//    //float *initial_force_z_data = reinterpret_cast<float *>(initial_force_z.data);
//
//    long int *prev_indices_data = reinterpret_cast<long int *>(prev_indices.data);
//    long int *next_indices_data = reinterpret_cast<long int *>(next_indices.data);
//    long int *fixed_indices_data = reinterpret_cast<long int *>(fixed_indices.data);
//    //long int *closed_indices_data = reinterpret_cast<long int *>(closed_indices.data);
//
//    int fixed_iter = 0;
//    for(int i=0; i<x_valves.shape[0]; i++)
//    {
//        if (fixed_indices_data[fixed_iter] == i) 
//        {
//            this->nodes[this->nodesCount - 3282 + i] = new TFixedElasticNode();
//            fixed_iter++;
//            continue;
//        }
//
//        this->nodes[this->nodesCount - 3282 + i] = new TElasticNode();
//        //if (IN(closed_indices_data, closed_indices_data + x_valves.shape[0], i))
//        //{
//        //    LOG(INFO) << "Found a TFixedStretchingNode at " << this->nodesCount - 3282 + i;
//        //    this->nodes[this->nodesCount - 3282 + i] = new TFixedStretchingNode();
//        //}
//        //else
//        //{
//        //    this->nodes[this->nodesCount - 3282 + i] = new TElasticNode();
//        //}
//    }
//
//    for(int i=0; i<x_valves.shape[0]; i++)
//    {
//        long double x = x_loaded_data[i];
//        this->nodes[this->nodesCount - 3282 + i]->x = x - 0.2;
//        this->nodes[this->nodesCount - 3282 + i]->xRef = x - 0.2;
//        this->nodes[this->nodesCount - 3282 + i]->xVel = 0;
//        this->nodes[this->nodesCount - 3282 + i]->xForce = 0;//initial_force_x_data[i];
//
//        long double y = y_loaded_data[i];
//        this->nodes[this->nodesCount - 3282 + i]->y = y;
//        this->nodes[this->nodesCount - 3282 + i]->yRef = y;
//        this->nodes[this->nodesCount - 3282 + i]->yVel = 0;
//        this->nodes[this->nodesCount - 3282 + i]->yForce = 0;//initial_force_y_data[i];
//
//        long double z = z_loaded_data[i];
//        this->nodes[this->nodesCount - 3282 + i]->z = z;
//        this->nodes[this->nodesCount - 3282 + i]->zRef = z;
//        this->nodes[this->nodesCount - 3282 + i]->zVel = 0;
//        this->nodes[this->nodesCount - 3282 + i]->zForce = 0;//initial_force_z_data[i];
//    }
//
//    for(int i=0; i<x_valves.shape[0]; i++)
//    {
//        this->nodes[this->nodesCount - 3282 + i]->boundary = this;
//        this->nodes[this->nodesCount - 3282 + i]->neighbors.next = this->nodes[this->nodesCount - 3282 + next_indices_data[i]];
//        this->nodes[this->nodesCount - 3282 + i]->neighbors.prev = this->nodes[this->nodesCount - 3282 + prev_indices_data[i]];
//        this->nodes[this->nodesCount - 3282 + i]->neighbors.initialDistanceNext = TNode::distance_3d(
//            this->nodes[this->nodesCount - 3282 + i],
//            this->nodes[this->nodesCount - 3282 + i]->neighbors.next
//        );
//
//        this->nodes[this->nodesCount - 3282 + i]->neighbors.initialCurvatures[OX] = TNode::curvature(
//            this->nodes[this->nodesCount - 3282 + i],
//            this->nodes[this->nodesCount - 3282 + i]->neighbors.next,
//            this->nodes[this->nodesCount - 3282 + i]->neighbors.prev,
//            TNode::Ox
//        );
//        this->nodes[this->nodesCount - 3282 + i]->neighbors.initialCurvatures[OY] = TNode::curvature(
//            this->nodes[this->nodesCount - 3282 + i],
//            this->nodes[this->nodesCount - 3282 + i]->neighbors.next,
//            this->nodes[this->nodesCount - 3282 + i]->neighbors.prev,
//            TNode::Oy
//        );
//        this->nodes[this->nodesCount - 3282 + i]->neighbors.initialCurvatures[OZ] = TNode::curvature(
//            this->nodes[this->nodesCount - 3282 + i],
//            this->nodes[this->nodesCount - 3282 + i]->neighbors.next,
//            this->nodes[this->nodesCount - 3282 + i]->neighbors.prev,
//            TNode::Oz
//        );
//
//        if (this->nodes[this->nodesCount - 3282 + i]->neighbors.initialDistanceNext == 0)
//        {
//            this->nodes[this->nodesCount - 3282 + i]->neighbors.next = nullptr;
//        }
//    }

    return this;
}
Exemplo n.º 22
0
npy_longdouble npy_modfl(npy_longdouble x, npy_longdouble *iptr)
{
    return modfl(x, iptr);
}
Exemplo n.º 23
0
TEST(math, modfl) {
  long double ldi;
  long double ldf = modfl(123.456, &ldi);
  ASSERT_FLOAT_EQ(123.0, ldi);
  ASSERT_FLOAT_EQ(0.456, ldf);
}
Exemplo n.º 24
0
TEST(math, modfl) {
  long double ldi;
  long double ldf = modfl(123.75L, &ldi);
  ASSERT_DOUBLE_EQ(123.0L, ldi);
  ASSERT_DOUBLE_EQ(0.75L, ldf);
}
Exemplo n.º 25
0
static int
print_float (struct printf_info *pinfo, char *startp, char *endp, int *signp, snv_long_double n)
{
  int prec, fmtch;
  char *p, *t;
  snv_long_double fract;
  int expcnt, gformat = 0;
  snv_long_double integer, tmp;
  char expbuf[10];

  prec = pinfo->prec;
  fmtch = pinfo->spec;
  t = startp;
  *signp = 0;

  /* Do the special cases: nans, infinities, zero, and negative numbers. */
  if (isnanl (n))
    {
      /* Not-a-numbers are printed as a simple string. */
      *t++ = fmtch < 'a' ? 'N' : 'n';
      *t++ = fmtch < 'a' ? 'A' : 'a';
      *t++ = fmtch < 'a' ? 'N' : 'n';
      return t - startp;
    }

  /* Zero and infinity also can have a sign in front of them. */
  if (copysignl (1.0, n) < 0.0)
    {
      n = -1.0 * n;
      *signp = '-';
    }

  if (isinfl (n))
    {
      /* Infinities are printed as a simple string. */
      *t++ = fmtch < 'a' ? 'I' : 'i';
      *t++ = fmtch < 'a' ? 'N' : 'n';
      *t++ = fmtch < 'a' ? 'F' : 'f';
      goto set_signp;
    }

  expcnt = 0;
  fract = modfl (n, &integer);

  /* get an extra slot for rounding. */
  *t++ = '0';

  /* get integer portion of number; put into the end of the buffer; the
     .01 is added for modfl (356.0 / 10, &integer) returning .59999999...  */
  for (p = endp - 1; p >= startp && integer; ++expcnt)
    {
      tmp = modfl (integer / 10, &integer);
      *p-- = '0' + ((int) ((tmp + .01L) * 10));
    }

  switch (fmtch)
    {
    case 'g':
    case 'G':
      gformat = 1;

      /* a precision of 0 is treated as a precision of 1. */
      if (!prec)
	pinfo->prec = ++prec;

      /* ``The style used depends on the value converted; style e
         will be used only if the exponent resulting from the
         conversion is less than -4 or greater than the precision.''
                -- ANSI X3J11 */
      if (expcnt > prec || (!expcnt && fract && fract < .0001L))
	{
	  /* g/G format counts "significant digits, not digits of
	     precision; for the e/E format, this just causes an
	     off-by-one problem, i.e. g/G considers the digit
	     before the decimal point significant and e/E doesn't
	     count it as precision.  */
	  --prec;
	  fmtch -= 2;		/* G->E, g->e */
	  goto eformat;
	}
      else
	{
          /* Decrement precision */
          if (n != 0.0L)
	    prec -= (endp - p) - 1;
	  else
	    prec--;

	  goto fformat;
	}

    case 'f':
    case 'F':
    fformat:
      /* reverse integer into beginning of buffer */
      if (expcnt)
	for (; ++p < endp; *t++ = *p);
      else
	*t++ = '0';

      /* If precision required or alternate flag set, add in a
         decimal point.  */
      if (pinfo->prec || pinfo->alt)
	*t++ = '.';

      /* if requires more precision and some fraction left */
      if (fract)
	{
	  if (prec)
	    {
	      /* For %g, if no integer part, don't count initial
	         zeros as significant digits. */
	      do
		{
		  fract = modfl (fract * 10, &tmp);
		  *t++ = '0' + ((int) tmp);
		}
	      while (!tmp && !expcnt && gformat);

	      while (--prec && fract)
		{
		  fract = modfl (fract * 10, &tmp);
		  *t++ = '0' + ((int) tmp);
		}
	    }

	  if (fract)
	    startp =
	      print_float_round (fract, (int *) NULL, startp, t - 1, (char) 0, signp);
	}

      break;

    case 'e':
    case 'E':
    eformat:
      if (expcnt)
	{
	  *t++ = *++p;
	  if (pinfo->prec || pinfo->alt)
	    *t++ = '.';

	  /* if requires more precision and some integer left */
	  for (; prec && ++p < endp; --prec)
	    *t++ = *p;

	  /* if done precision and more of the integer component,
	     round using it; adjust fract so we don't re-round
	     later.  */
	  if (!prec && ++p < endp)
	    {
	      fract = 0;
	      startp = print_float_round ((snv_long_double) 0, &expcnt, startp, t - 1, *p, signp);
	    }

	  /* adjust expcnt for digit in front of decimal */
	  --expcnt;
	}

      /* until first fractional digit, decrement exponent */
      else if (fract)
	{
	  /* adjust expcnt for digit in front of decimal */
	  for (expcnt = -1;; --expcnt)
	    {
	      fract = modfl (fract * 10, &tmp);
	      if (tmp)
		break;
	    }
	  *t++ = '0' + ((int) tmp);
	  if (pinfo->prec || pinfo->alt)
	    *t++ = '.';
	}

      else
	{
	  *t++ = '0';
	  if (pinfo->prec || pinfo->alt)
	    *t++ = '.';
	}

      /* if requires more precision and some fraction left */
      if (fract)
	{
	  if (prec)
	    do
	      {
		fract = modfl (fract * 10, &tmp);
		*t++ = '0' + ((int) tmp);
	      }
	    while (--prec && fract);

	  if (fract)
	    startp = print_float_round (fract, &expcnt, startp, t - 1, (char) 0, signp);
	}
      break;

    default:
      abort ();
    }

  /* %e/%f/%#g add 0's for precision, others trim 0's */
  if (gformat && !pinfo->alt)
    {
      while (t > startp && *--t == '0');
      if (*t != '.')
        ++t;
    }
  else
    for (; prec--; *t++ = '0');

  if (fmtch == 'e' || fmtch == 'E')
    {
      *t++ = fmtch;
      if (expcnt < 0)
        {
          expcnt = -expcnt;
          *t++ = '-';
        }
      else
        *t++ = '+';

      p = expbuf;
      do
        *p++ = '0' + (expcnt % 10);
      while ((expcnt /= 10) > 9);
      *p++ = '0' + expcnt;
      while (p > expbuf)
	*t++ = *--p;
    }

set_signp:
  if (!*signp)
    {
      if (pinfo->showsign)
        *signp = '+';
      else if (pinfo->space)
        *signp = ' ';
    }

  return (t - startp);
}