Ejemplo n.º 1
0
void
ArcoSeno (Token ** Pila)
{

  Token *Operando = EntornoEjecucion_BuscaSimbolo (*Pila);
  if (Buzon.GetHuboError ())
    return;
  if (NoEsReal (Operando))
    {
      BorrarTokenSiEsVariable (Operando);
      return;
    }

  long double ValorDominio = Operando->GetDatoReal ();
  BorrarTokenSiEsVariable (Operando);
  long double ValorRetorno = asinl (ValorDominio);
  if (Buzon.GetHuboError ())
    return;
  ValorRetorno = Estado.AngulosEnGrados ? ValorRetorno * (180.0L / M_PI) :
    ValorRetorno;
  Token *TokenRetorno = ConsigueToken (ValorRetorno);
  if (Buzon.GetHuboError ())
    return;
  delete Desapila (Pila);
  Apila (Pila, TokenRetorno);
  return;
}
Ejemplo n.º 2
0
void test_asin()
{
    static_assert((std::is_same<decltype(asin((double)0)), double>::value), "");
    static_assert((std::is_same<decltype(asinf(0)), float>::value), "");
    static_assert((std::is_same<decltype(asinl(0)), long double>::value), "");
    assert(asin(0) == 0);
}
Ejemplo n.º 3
0
long double TSolver::gcalc(const char f,const long double a,const long double b,const long double step) //calculates function
{
 #define ain(x) (a-step<=x && a+step>=x)
 #define bin(x) (b-step<=x && b+step>=x)
 #define angin(x) (torad(a)-step<x && torad(a)+step>x)
 switch (f)
   {case '+' : return a+b;
    case '-' : return a-b;
    case '*' : return a*b;
    case '/' : if (bin(0)) {Err=E_DEV_ZERO;return 0;};return a/b;
    case '!' : if (floorl(a)!=a) {Err=E_ARG;return 0;}return factor(a);
    case '_' : return -a;

    case cpi   : return M_PI;
    case cx    : return X;

    case fexp  : return exp(a);
    case fln   : if (a<0) {Err=E_ARG;return 0;}return logl(a);
    case flog  : if (a<0) {Err=E_ARG;return 0;}return log10l(a);
    case flogn : if (a<0) {Err=E_ARG;return 0;}return log(a)/log(b);

    case '^':
    case f_op_pow:
    case fpow  : if (a<0 && b<1 && b>0 && (!fmodl(b,2))) {Err=E_ARG;return 0;}return powl(a,b);
    case fsqr  : return a*a;
    case f_op_root:
    case froot : if (a<0 && (!fmodl(b,2))){Err=E_ARG;return 0;}
		   return (a>0 || (!fmodl(b,2)))?powl(a,1/b):-powl(-a,1/b);
    case fsqrt : if (a<0) {Err=E_ARG;return 0;}return sqrtl(a);
    case f_abs  : return fabsl(a);

    case fsin  : return sinl(a);
    case fcos  : return cosl(a);
    case ftan  : if (angin(M_PI_2) || angin(M_PI_2+M_PI)) {Err=E_ARG;return 0;} return tanl(a);
    case fctan : if (angin(0) || angin(M_PI)) {Err=E_ARG;return 0;} return 1/tanl(a);

    case fsin+ARC : if (fabsl(a)>1) {Err=E_ARG;return 0;} return asinl(a);
    case fcos+ARC : if (fabsl(a)>1) {Err=E_ARG;return 0;} return acosl(a);
    case ftan+ARC : return atanl(a);
    case fctan+ARC: return atanl(1/a);

    case fsin+HYP : return sinhl(a);
    case fcos+HYP : return coshl(a);
    case ftan+HYP : return tanhl(a);
    case fctan+HYP : return 1/tanhl(a);
#ifndef _OLD_
    case fsin+HYP+ARC : return asinhl(a);
    case fcos+HYP+ARC : return acoshl(a);
    case ftan+HYP+ARC : if (fabsl(a)>=1) {Err=E_ARG;return 0;} return atanhl(a);
    case fctan+HYP+ARC : if (angin(0)) {Err=E_ARG;return 0;} return atanhl(1/a);
#endif
    default: return 0;
   }
}
Ejemplo n.º 4
0
long double complex
casinhl(long double complex z)
{
	long double x, y, ax, ay, rx, ry, B, sqrt_A2my2, new_y;
	int B_is_usable;
	long double complex w;

	x = creall(z);
	y = cimagl(z);
	ax = fabsl(x);
	ay = fabsl(y);

	if (isnan(x) || isnan(y)) {
		if (isinf(x))
			return (CMPLXL(x, y + y));
		if (isinf(y))
			return (CMPLXL(y, x + x));
		if (y == 0)
			return (CMPLXL(x + x, y));
		return (CMPLXL(nan_mix(x, y), nan_mix(x, y)));
	}

	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
		if (signbit(x) == 0)
			w = clog_for_large_values(z) + m_ln2;
		else
			w = clog_for_large_values(-z) + m_ln2;
		return (CMPLXL(copysignl(creall(w), x),
		    copysignl(cimagl(w), y)));
	}

	if (x == 0 && y == 0)
		return (z);

	raise_inexact();

	if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
		return (z);

	do_hard_work(ax, ay, &rx, &B_is_usable, &B, &sqrt_A2my2, &new_y);
	if (B_is_usable)
		ry = asinl(B);
	else
		ry = atan2l(new_y, sqrt_A2my2);
	return (CMPLXL(copysignl(rx, x), copysignl(ry, y)));
}
Ejemplo n.º 5
0
/* Equ 20.2, 20.4 pg 126 */
void ln_get_equ_prec2 (struct ln_equ_posn * mean_position, double fromJD, double toJD, struct ln_equ_posn * position)
{
	long double t, t2, t3, A, B, C, zeta, eta, theta, ra, dec, mean_ra, mean_dec, T, T2;
	
	/* change original ra and dec to radians */
	mean_ra = ln_deg_to_rad (mean_position->ra);
	mean_dec = ln_deg_to_rad (mean_position->dec);

	/* calc t, T, zeta, eta and theta Equ 20.2 */
	T = ((long double) (fromJD - JD2000)) / 36525.0;
	T *= 1.0 / 3600.0;
	t = ((long double) (toJD - fromJD)) / 36525.0;
	t *= 1.0 / 3600.0;
	T2 = T * T;
	t2 = t * t;
	t3 = t2 *t;
	zeta = (2306.2181 + 1.39656 * T - 0.000139 * T2) * t + (0.30188 - 0.000344 * T) * t2 + 0.017998 * t3;
	eta = (2306.2181 + 1.39656 * T - 0.000139 * T2) * t + (1.09468 + 0.000066 * T) * t2 + 0.018203 * t3;
	theta = (2004.3109 - 0.85330 * T - 0.000217 * T2) * t - (0.42665 + 0.000217 * T) * t2 - 0.041833 * t3;
	zeta = ln_deg_to_rad (zeta);
	eta = ln_deg_to_rad (eta);
	theta = ln_deg_to_rad (theta); 

	/* calc A,B,C equ 20.4 */
	A = cosl (mean_dec) * sinl (mean_ra + zeta);
	B = cosl (theta) * cosl (mean_dec) * cosl (mean_ra + zeta) - sinl (theta) * sinl (mean_dec);
	C = sinl (theta) * cosl (mean_dec) * cosl (mean_ra + zeta) + cosl (theta) * sinl (mean_dec);
	
	ra = atan2l (A,B) + eta;
	
	/* check for object near celestial pole */
	if (mean_dec > (0.4 * M_PI) || mean_dec < (-0.4 * M_PI)) {
		/* close to pole */
		dec = acosl (sqrt(A * A + B * B));
		if (mean_dec < 0.)
		  dec *= -1; /* 0 <= acos() <= PI */
	} else {
		/* not close to pole */
		dec = asinl (C);
	}

	/* change to degrees */
	position->ra = ln_range_degrees (ln_rad_to_deg (ra));
	position->dec = ln_rad_to_deg (dec);
}
Ejemplo n.º 6
0
long double
hw2p7 (long double h, long double p)
{
  // trough
  // h is height of water from top of trough
  // volume is 12.4 feet.
  // Got the formula for the water volume by height from here:
  // http://answers.yahoo.com/question/index?qid=20120329114323AAgspZg

  long double r = 1.0L;		// radius
  long double l = 10.0L;	// length
  long double maxVol = M_PI * r * r * 0.5L * l;

  long double result = l * ( 0.5L *M_PI * r*r- r*r * asinl( h/r - h * sqrtl( r*r-h*h) ) );

  printf("  h %Lf r %Lf l %Lf max %Lf result %Lf p %Lf\n", h, r, l, maxVol, result, p );
  return result - p;
}
Ejemplo n.º 7
0
static TACommandVerdict asinl_cmd(TAThread thread,TAInputStream stream)
{
    long double x, res;

    x = readLongDouble(&stream);

    START_TARGET_OPERATION(thread);

    errno = 0;
    res = asinl(x);

    END_TARGET_OPERATION(thread);

    writeInt(thread, errno);
    writeLongDouble(thread, res);
    sendResponse(thread);

    return taDefaultVerdict;
}
Ejemplo n.º 8
0
LONG_DOUBLE eval_expr_func(eval_context *ctx, ast_node *tree) {
    expr_func_data *func_data = (expr_func_data*)tree->data;
    if (strcmp(func_data->name, "sin") == 0) return sinl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "cos") == 0) return cosl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "tan") == 0) return tanl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "acos") == 0) return acosl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "asin") == 0) return asinl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "atan") == 0) return atanl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "cosh") == 0) return coshl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "sinh") == 0) return sinhl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "tanh") == 0) return tanhl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "log") == 0) return logl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "log10") == 0) return log10l(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "ceil") == 0) return ceill(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "fabs") == 0) return fabsl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "floor") == 0) return floorl(eval_expr(ctx, func_data->rhs));
    else if (strcmp(func_data->name, "sqrt") == 0) return sqrtl(eval_expr(ctx, func_data->rhs));
    else return eval_emit_error(ctx, "Unknown function %s.", func_data->name);
}
Ejemplo n.º 9
0
/* Equ 20.3, 20.4 pg 126 
*/
void ln_get_equ_prec (struct ln_equ_posn * mean_position, double JD, struct ln_equ_posn * position)
{
	long double t, t2, t3, A, B, C, zeta, eta, theta, ra, dec, mean_ra, mean_dec;
	
	/* change original ra and dec to radians */
	mean_ra = ln_deg_to_rad (mean_position->ra);
	mean_dec = ln_deg_to_rad (mean_position->dec);

	/* calc t, zeta, eta and theta for J2000.0 Equ 20.3 */
	t = (JD - JD2000) / 36525.0;
	t *= 1.0 / 3600.0;
	t2 = t * t;
	t3 = t2 *t;
	zeta = 2306.2181 * t + 0.30188 * t2 + 0.017998 * t3;
	eta = 2306.2181 * t + 1.09468 * t2 + 0.041833 * t3;
	theta = 2004.3109 * t - 0.42665 * t2 - 0.041833 * t3;
	zeta = ln_deg_to_rad (zeta);
	eta = ln_deg_to_rad (eta);
	theta = ln_deg_to_rad (theta); 

	/* calc A,B,C equ 20.4 */
	A = cosl (mean_dec) * sinl (mean_ra + zeta);
	B = cosl (theta) * cosl (mean_dec) * cosl (mean_ra + zeta) - sinl (theta) * sinl (mean_dec);
	C = sinl (theta) * cosl (mean_dec) * cosl (mean_ra + zeta) + cosl (theta) * sinl (mean_dec);
	
	ra = atan2l (A,B) + eta;
	
	/* check for object near celestial pole */
	if (mean_dec > (0.4 * M_PI) || mean_dec < (-0.4 * M_PI)) {
		/* close to pole */
		dec = acosl (sqrt(A * A + B * B));
		if (mean_dec < 0.)
		  dec *= -1; /* 0 <= acos() <= PI */
	} else {
		/* not close to pole */
		dec = asinl (C);
	}

	/* change to degrees */
	position->ra = ln_range_degrees (ln_rad_to_deg (ra));
	position->dec = ln_rad_to_deg (dec);
}
Ejemplo n.º 10
0
long double complex casinl (long double complex Z)
{
  long double complex Res;
  long double x, y;

  x = __real__ Z;
  y = __imag__ Z;

  if (y == 0.0L)
    {
      __real__ Res = asinl (x);
      __imag__ Res = 0.0L;
    }
  else  /* -I * clog(I * Z + csqrt(1.0 - Z * Z))) */
    {
      long double complex ZZ;
                                 
      /* Z * Z = ((x - y) * (x + y)) + (2.0 * x * y) * I */
      /* calculate 1 - Z * Z */
      __real__ ZZ = 1.0L - (x - y) * (x + y);
      __imag__ ZZ = -2.0L * x * y;
      ZZ = csqrtl (ZZ);


      /* add  I * Z  to ZZ */

      __real__ ZZ -= y;
      __imag__ ZZ += x;

      ZZ = clogl (ZZ);

      /* mult by -I */
      __real__ Res = __imag__ ZZ;
      __imag__ Res = - __real__ ZZ;  
    }
  return (Res);
}
Ejemplo n.º 11
0
/* Tests along the real and imaginary axes. */
void
test_axes(void)
{
	static const long double nums[] = {
		-2, -1, -0.5, 0.5, 1, 2
	};
	long double complex z;
	int i;

	for (i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) {
		/* Real axis */
		z = CMPLXL(nums[i], 0.0);
		if (fabs(nums[i]) <= 1) {
			testall_tol(cacosh, z, CMPLXL(0.0, acos(nums[i])), 1);
			testall_tol(cacos, z, CMPLXL(acosl(nums[i]), -0.0), 1);
			testall_tol(casin, z, CMPLXL(asinl(nums[i]), 0.0), 1);
			testall_tol(catanh, z, CMPLXL(atanh(nums[i]), 0.0), 1);
		} else {
			testall_tol(cacosh, z,
				    CMPLXL(acosh(fabs(nums[i])),
					   (nums[i] < 0) ? pi : 0), 1);
			testall_tol(cacos, z,
				    CMPLXL((nums[i] < 0) ? pi : 0,
					   -acosh(fabs(nums[i]))), 1);
			testall_tol(casin, z,
				    CMPLXL(copysign(pi / 2, nums[i]),
					   acosh(fabs(nums[i]))), 1);
			testall_tol(catanh, z,
				    CMPLXL(atanh(1 / nums[i]), pi / 2), 1);
		}
		testall_tol(casinh, z, CMPLXL(asinh(nums[i]), 0.0), 1);
		testall_tol(catan, z, CMPLXL(atan(nums[i]), 0), 1);

		/* TODO: Test the imaginary axis. */
	}
}
Ejemplo n.º 12
0
sfloat math_arcsin(const sfloat val)
{
	return asinl(val);
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
long double atanl(long double x)
{
  return asinl(x / sqrtl(x * x + 1));
}
Ejemplo n.º 15
0
long double acosl(long double x)
{
    return (M_PI_2 - asinl(x));
}
Ejemplo n.º 16
0
double getPi(double arc, double factor)
{
  return asinl(arc)*factor;
}
Ejemplo n.º 17
0
ldcomplex
casinl(ldcomplex z) {
	long double x, y, t, R, S, A, Am1, B, y2, xm1, xp1, Apx;
	int ix, iy, hx, hy;
	ldcomplex ans;

	x = LD_RE(z);
	y = LD_IM(z);
	hx = HI_XWORD(x);
	hy = HI_XWORD(y);
	ix = hx & 0x7fffffff;
	iy = hy & 0x7fffffff;
	x = fabsl(x);
	y = fabsl(y);

	/* special cases */

	/* x is inf or NaN */
	if (ix >= 0x7fff0000) {	/* x is inf or NaN */
		if (isinfl(x)) {	/* x is INF */
			LD_IM(ans) = x;
			if (iy >= 0x7fff0000) {
				if (isinfl(y))
					/* casin(inf + i inf) = pi/4 + i inf */
					LD_RE(ans) = pi_4 + pi_4_l;
				else	/* casin(inf + i NaN) = NaN + i inf */
					LD_RE(ans) = y + y;
			} else	/* casin(inf + iy) = pi/2 + i inf */
				LD_RE(ans) = pi_2 + pi_2_l;
		} else {		/* x is NaN */
			if (iy >= 0x7fff0000) {
				/* INDENT OFF */
				/*
				 * casin(NaN + i inf) = NaN  + i inf
				 * casin(NaN + i NaN) = NaN  + i NaN
				 */
				/* INDENT ON */
				LD_IM(ans) = y + y;
				LD_RE(ans) = x + x;
			} else {
				/* INDENT OFF */
				/* casin(NaN + i y  ) = NaN  + i NaN */
				/* INDENT ON */
				LD_IM(ans) = LD_RE(ans) = x + y;
			}
		}
		if (hx < 0)
			LD_RE(ans) = -LD_RE(ans);
		if (hy < 0)
			LD_IM(ans) = -LD_IM(ans);
		return (ans);
	}

	/* casin(+0 + i 0) = 0 + i 0. */
	if (x == zero && y == zero)
		return (z);

	if (iy >= 0x7fff0000) {	/* y is inf or NaN */
		if (isinfl(y)) {	/* casin( x + i inf ) = 0 + i inf */
			LD_IM(ans) = y;
			LD_RE(ans) = zero;
		} else {		/* casin( x + i NaN ) = NaN + i NaN */
			LD_IM(ans) = x + y;
			if (x == zero)
				LD_RE(ans) = x;
			else
				LD_RE(ans) = y;
		}
		if (hx < 0)
			LD_RE(ans) = -LD_RE(ans);
		if (hy < 0)
			LD_IM(ans) = -LD_IM(ans);
		return (ans);
	}

	if (y == zero) {	/* region 1: y=0 */
		if (ix < 0x3fff0000) {	/* |x| < 1 */
			LD_RE(ans) = asinl(x);
			LD_IM(ans) = zero;
		} else {
			LD_RE(ans) = pi_2 + pi_2_l;
			if (ix >= ip1)	/* |x| >= i386 ? 2**65 : 2**114 */
				LD_IM(ans) = ln2 + logl(x);
			else if (ix >= 0x3fff8000)	/* x > Acrossover */
				LD_IM(ans) = logl(x + sqrtl((x - one) * (x +
					one)));
			else {
				xm1 = x - one;
				LD_IM(ans) = log1pl(xm1 + sqrtl(xm1 * (x +
					one)));
			}
		}
	} else if (y <= E * fabsl(x - one)) {	/* region 2: y < tiny*|x-1| */
		if (ix < 0x3fff0000) {	/* x < 1 */
			LD_RE(ans) = asinl(x);
			LD_IM(ans) = y / sqrtl((one + x) * (one - x));
		} else {
			LD_RE(ans) = pi_2 + pi_2_l;
			if (ix >= ip1)	/* i386 ? 2**65 : 2**114 */
				LD_IM(ans) = ln2 + logl(x);
			else if (ix >= 0x3fff8000)	/* x > Acrossover */
				LD_IM(ans) = logl(x + sqrtl((x - one) * (x +
					one)));
			else
				LD_IM(ans) = log1pl((x - one) + sqrtl((x -
					one) * (x + one)));
		}
	} else if (y < Foursqrtu) {	/* region 3 */
		t = sqrtl(y);
		LD_RE(ans) = pi_2 - (t - pi_2_l);
		LD_IM(ans) = t;
	} else if (E * y - one >= x) {	/* region 4 */
		LD_RE(ans) = x / y;	/* need to fix underflow cases */
		LD_IM(ans) = ln2 + logl(y);
	} else if (ix >= 0x5ffb0000 || iy >= 0x5ffb0000) {
		/* region 5: x+1 and y are both (>= sqrt(max)/8) i.e. 2**8188 */
		t = x / y;
		LD_RE(ans) = atanl(t);
		LD_IM(ans) = ln2 + logl(y) + half * log1pl(t * t);
	} else if (x < Foursqrtu) {
		/* region 6: x is very small, < 4sqrt(min) */
		A = sqrtl(one + y * y);
		LD_RE(ans) = x / A;	/* may underflow */
		if (iy >= 0x3fff8000)	/* if y > Acrossover */
			LD_IM(ans) = logl(y + A);
		else
			LD_IM(ans) = half * log1pl((y + y) * (y + A));
	} else {	/* safe region */
		y2 = y * y;
		xp1 = x + one;
		xm1 = x - one;
		R = sqrtl(xp1 * xp1 + y2);
		S = sqrtl(xm1 * xm1 + y2);
		A = half * (R + S);
		B = x / A;
		if (B <= Bcrossover)
			LD_RE(ans) = asinl(B);
		else {		/* use atan and an accurate approx to a-x */
			Apx = A + x;
			if (x <= one)
				LD_RE(ans) = atanl(x / sqrtl(half * Apx * (y2 /
					(R + xp1) + (S - xm1))));
			else
				LD_RE(ans) = atanl(x / (y * sqrtl(half * (Apx /
					(R + xp1) + Apx / (S + xm1)))));
		}
		if (A <= Acrossover) {
			/* use log1p and an accurate approx to A-1 */
			if (x < one)
				Am1 = half * (y2 / (R + xp1) + y2 / (S - xm1));
			else
				Am1 = half * (y2 / (R + xp1) + (S + xm1));
			LD_IM(ans) = log1pl(Am1 + sqrtl(Am1 * (A + one)));
		} else {
			LD_IM(ans) = logl(A + sqrtl(A * A - one));
		}
	}

	if (hx < 0)
		LD_RE(ans) = -LD_RE(ans);
	if (hy < 0)
		LD_IM(ans) = -LD_IM(ans);

	return (ans);
}
Ejemplo n.º 18
0
 inline long double MathTrait<long double>::asin( const long double val )
 {
   return asinl( val ) ;
 }
Ejemplo n.º 19
0
TEST(math, asinl) {
  ASSERT_DOUBLE_EQ(0.0L, asinl(0.0L));
}
Ejemplo n.º 20
0
inline long double _asin(long double value) {
    return asinl(value);
}
Ejemplo n.º 21
0
npy_longdouble npy_asinl(npy_longdouble x)
{
    return asinl(x);
}
Ejemplo n.º 22
0
static long double
sinasinl(long double x)
{

	return (sinl(asinl(x)));
}
Ejemplo n.º 23
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
}
Ejemplo n.º 24
0
TEST(math, asinl) {
  ASSERT_FLOAT_EQ(0.0, asinl(0.0));
}
Ejemplo n.º 25
0
int grow_poly(polygon **poly, int npolys, polygon *polys[/*npolys*/], long double grow_angle, long double mtol, int *np){
  int i, ip, jp, iret, ier, dn;
  long double s, cmi, cm_new,theta, theta_new, tol;
  polygon *poly1= 0x0;
  
/* part_poly should lasso all one-boundary polygons */
#define ALL_ONEBOUNDARY		2
  /* how part_poly should tighten lasso */
#define ADJUST_LASSO            2
  /* part_poly should force polygon to be split even if no part can be lassoed */
#define FORCE_SPLIT             1
  /* partition_poly should overwrite all original polygons */
#define OVERWRITE_ORIGINAL      2

  if((*poly)->pixel!=0){
    fprintf(stderr, "Error: input polygon is pixelized. The grow function can only be applied to non-pixelized polygons.");
    return(-1);
  }
  
  *np=0;
  // partition disconnected polygons
  tol = mtol;
  ier = partition_poly(poly, npolys, polys, tol, ALL_ONEBOUNDARY, ADJUST_LASSO, FORCE_SPLIT, OVERWRITE_ORIGINAL, &dn); 
  // error
  if (ier == -1) {
    fprintf(stderr, "grow: UHOH at polygon %lld; continuing ...\n",polys[i]->id);
    // return(-1);
      // failed to partition polygon into desired number of parts
  } else if (ier == 1) {
    fprintf(stderr, "grow: failed to partition polygon %lld fully; partitioned it into %d parts\n", (*poly)->id, dn + 1);
  }  
  *np+=dn;
  
  // check whether exceeded maximum number of polygons
  //printf("(2) n = %d\n", n);
  if (*np > npolys) {
    fprintf(stderr, "grow: total number of polygons exceeded maximum\n");
    fprintf(stderr, "if you need more space, enlarge NPOLYSMAX in defines.h, and recompile\n");
    return(-1);
  }
  
  for(i=-1; i<*np; i++){
    if(i=-1)
      poly1=(*poly);
    else
      poly1=polys[i];
    
    for (ip = 0; ip < poly1->np; ip++) { 
      cmi=poly1->cm[ip];
      //convert cm into an angle
      s = sqrtl(fabsl(cmi) / 2.);
      if (s > 1.) s = 1.;
      theta = 2. * asinl(s);
      theta=(cmi >= 0.)? theta : -theta;
      
      theta_new=theta+grow_angle;
      
      // if growing angle has caused cap to encompass whole sphere, set cm_new=2 to make it superfluous
      if(theta>=0 && theta_new>=PI)
	cm_new=2.;
      else if(theta<0 && theta_new>=0) 
	cm_new=2.;
      // if growing angle (with a negative value for grow_angle) has shrunk cap to less than nothing, make polygon null
      else if(theta>=0 && theta_new<0) 
	cm_new=0.;
      else if(theta<0 && theta_new<=-PI) 
	cm_new=0.;
      // otherwise convert normally
      else{
	/* 1 - cosl(radius) = 2 sin^2(radius/2) */
	s = sinl(theta_new / 2.);
	cm_new = s * s * 2.;
	cm_new = (theta_new >= 0.)? cm_new : -cm_new;
      }
      
      poly1->cm[ip]=cm_new;
    }
    tol=mtol;
    iret=prune_poly(poly1,tol);
  }
  return(iret);
}
Ejemplo n.º 26
0
/*------------------------------------------------------------------------------
  Partition a polygon by lassoing its connected boundaries with circles.

  Normally the input polygon poly would be a group polygon,
  all of whose connected boundaries belong to a single group.
  If the boundaries of the input polygon belong to more than one group,
  then the polygon is not simply-connected, and each non-simply-connected part
  of the polygon will contain two or more boundaries.
  The algorithm will attempt to lasso all these boundaries, even though
  lassoing boundaries of a non-simply-connected part of the polygon
  cannot partition the polygon.

  The routine attempts to lasso all the connected boundaries of a polygon,
  unless the polygon has only a single connected boundary.
  If the polygon has a single connected boundary, then
  the all_oneboundary option controls whether or not this boundary is lassoed.

  An attempted lasso is discarded if it lies fully inside or fully outside
  all the caps of the polygon.  It would be incorrect to retain a lasso
  that lies fully inside the polygon, and it would be superfluous to retain
  a lasso that fully encloses the polygon.
  In the normal case where the input polygon is a group polygon,
  a lasso can lie fully inside or outside the caps of the group polygon
  if the group polygon has a single connected boundary.

  If the input polygon has two or more connected boundaries none of which
  can be lassoed, then the force_split option controls whether the
  routine gives up, or else forcibly splits the input polygon into two parts,
  each of which will require further splitting.

   Input: poly is a polygon.
	  npolys = maximum number of polygons available in polys array.
	  mtol = initial angular tolerance within which to merge multiple intersections.
	  all_oneboundary = 2 to lasso all one-boundary polygons,
			    1 to lasso only those one-boundary polygons
			      with more caps than vertices,
			    0 never to lasso one-boundary polygons;
			    in all cases, all multi-boundary polygons are lassoed.
	  adjust_lasso = how to tighten lasso:
		       = 0 as tight as possible,
			 1 for balkanize,
			 2 for ransack.
	  force_split = 1 to force a polygon to be split
			  even if no boundary can be lassoed;
			0 otherwise.
  Output: polys[i], i = 0 to npoly-1, are the connected parts of poly;
              if return value = 0, then:
		  if *npoly = *npoly_try = 0, then:
		      input poly already consists of a single connected part
		      that needs no partitioning;
		  if *npoly = *npoly_try > 0, then:
		      poly was fully partitioned into its parts;
		  if *npoly < *npoly_try then:
		      poly was partially partitioned,
		      and poly[npoly - 1] contains the parts of poly
		      that were not partitioned successfully;
	      if return value = 1,
		    which can occur only if force_split = 1, then:
		    poly contains at least 2 connected boundaries,
		    none of which could be lassoed successfully,
		    and instead poly was split forcibly into two,
		    with the two parts in polys[0] and polys[1].
	  *npoly = number of polygons in polys;
		   if *npoly > npolys, then there was not enough space.
	  *npoly_try = attempted number of polygons.
  Return value: -1 if error occurred;
		 0 for a normal return;
		 1 if poly was split forcibly when no boundary could be lassoed;
		   can only occur if force_split = 1.
*/
int part_poly(polygon *poly, int npolys, polygon *polys[/*npolys*/], long double mtol, int all_oneboundary, int adjust_lasso, int force_split, int *npoly, int *npoly_try)
{
    /* number of extra caps to allocate to polygon, to allow for expansion */
#define DNP		4
    static polygon *extracap = 0x0;
    const int do_vcirc = 1;
    const int per = 0;
    const int nve = 2;
    const int itmax = 30;
    int dnp, found, i, ier, iev, ip, it, iv, ivm, ivmax_that, ivmax_this, ivmin_that, ivmin_this, nev, nev0, np, nret, nv, nvm;
    int *ipv, *gp, *ev;
    long double *angle;
    vec *ve, *vm;
    long double *cmvmin, *cmvmax, *cmpmin, *cmpmax;
    vec *vmax, *vmin;
    long double cmbest, cme, cmforce, dth, dthbest, dthforce, dthm, dthp, s, th, thm, tol;
    long double cmpmax_all, cmpmin_all, cmvmax_that, cmvmax_this, cmvmin_that, cmvmin_this, thmax_that, thmax_this, thmin_that, thmin_this;
    vec v, vmbest, vmforce;

    /* initialize return value to normal */
    nret = 0;

    /* initialize number of polygon parts in polys to zero */
    *npoly = 0;

    /* initialize attempted number of polygon parts to zero */
    *npoly_try = 0;

    /* vertices and centres of edges of polygon */
    tol = mtol;
    ier = gverts(poly, do_vcirc, &tol, per, nve, &nv, &ve, &angle, &ipv, &gp, &nev, &nev0, &ev);
    if (ier) return(-1);

    /* no boundaries */
    if (nev == 0) return(nret);

    /* polygon has just 1 connected boundary */
    if (nev == 1) {
        if (all_oneboundary == 0) {
            return(nret);
        } else if (all_oneboundary == 1) {
            /* polygon has not too many caps */
            if (poly->np <= nv + 1) return(nret);
        }
    }

    /* barycentres of connected boundaries of polygon */
    ier = vmidc(poly, nv, nve, ve, ipv, ev, &nvm, &vm);
    if (ier == -1) return(-1);

    /* number of polygons to try to split into */
    *npoly_try = nvm;

    /* initialize lasso to be used to force split */
    if (force_split) dthforce = -4.;

    /* attempt to partition polygon around each barycentre vm[ivm] */
    for (ivm = 0; ivm < nvm; ivm++) {

        /* initialize best lasso so far */
        if (force_split) dthbest = -4.;

        /* repeat until find isolating lasso */
        it = 0;
        do {

            /* points on each edge nearest to and farthest from vm[ivm] */
            ier = gvlims(poly, do_vcirc, &tol, vm[ivm], &nv, &vmin, &vmax, &cmvmin, &cmvmax, &cmpmin, &cmpmax, &ipv, &gp, &nev, &nev0, &ev);
            if (ier == -1) return(-1);
            if (ier) break;

            /* distances that exclude/enclose all circles */
            cmpmin_all = 2.;
            cmpmax_all = 0.;
            for (ip = 0; ip < poly->np; ip++) {
                if (cmpmin[ip] <= cmpmin_all) {
                    cmpmin_all = cmpmin[ip];
                }
                if (cmpmax[ip] >= cmpmax_all) {
                    cmpmax_all = cmpmax[ip];
                }
            }

            /* distances that exclude/enclose this connected boundary */
            ivmax_this = -1;
            ivmin_this = -1;
            cmvmin_this = 2.;
            cmvmax_this = 0.;
            for (iv = (ivm == 0)? 0 : ev[ivm - 1]; iv < ev[ivm]; iv++) {
                if (cmvmin[iv] <= cmvmin_this) {
                    ivmin_this = iv;
                    cmvmin_this = cmvmin[iv];
                }
                if (cmvmax[iv] >= cmvmax_this) {
                    ivmax_this = iv;
                    cmvmax_this = cmvmax[iv];
                }
            }

            /* distances that exclude/enclose other connected boundaries */
            ivmin_that = -1;
            ivmax_that = -1;
            cmvmin_that = 2.;
            cmvmax_that = 0.;
            for (iev = 0; iev < nev; iev++) {
                if (iev == ivm) continue;
                for (iv = (iev == 0)? 0 : ev[iev - 1]; iv < ev[iev]; iv++) {
                    if (cmvmin[iv] <= cmvmin_that) {
                        ivmin_that = iv;
                        cmvmin_that = cmvmin[iv];
                    }
                    if (cmvmax[iv] >= cmvmax_that) {
                        ivmax_that = iv;
                        cmvmax_that = cmvmax[iv];
                    }
                }
            }

            /* angles corresponding to cmmin_this, cmvmax_this, cmvmin_that, and cmvmax_that */
            thmin_this = 2. * asinl(sqrtl(cmvmin_this / 2.));
            thmax_this = 2. * asinl(sqrtl(cmvmax_this / 2.));
            thmin_that = 2. * asinl(sqrtl(cmvmin_that / 2.));
            thmax_that = 2. * asinl(sqrtl(cmvmax_that / 2.));

            dthp = thmin_that - thmax_this;
            dthm = thmin_this - thmax_that;

            dth = (dthp >= dthm)? dthp : dthm;

            /* found lasso that isolates this connected boundary of polygon */
            if (dth >= - tol) {

                /* if (it >= 10) printf("%21.15Lg %21.15Lg %21.15Lg %4d %2d%21.15Lg %21.15Lg %21.15Lg %21.15Lg %21.15Lg %21.15Lg\n", vm[ivm][0], vm[ivm][1], vm[ivm][2], ivm, it, thmin_this, thmax_this, thmin_that, thmax_that, dthp, dthm); */

                /* thmin_that >= thmax_this - tol */
                if (dthp >= dthm) {
                    /* isolating lasso */
                    th = (thmax_this + thmin_that) / 2.;
                    switch (adjust_lasso) {
                    /* as tight as possible */
                    case 0:
                        thm = thmax_this;
                        break;
                    /* for balkanize: tiny angles give garea problems */
                    case 1:
                        thm = thmax_this + .001;
                        break;
                    /* for ransack: want tight lasso */
                    case 2:
                        thm = thmax_this * 1.05;
                        break;
                    }
                    /* tighten lasso */
                    if (th > thm) th = thm;
                    if (th < PI) {
                        s = sinl(th / 2.);
                        cme = 2. * s * s;
                    } else {
                        cme = 2.;
                    }

                    /* discard lasso that completely encloses all circles */
                    if (cme >= cmpmax_all) {
                        /* printf("%21.15Lg %21.15Lg %21.15Lg %21.15Lg\n", vm[ivm][0], vm[ivm][1], vm[ivm][2], cme); */
                        /* decrement number of polygons to try for */
                        (*npoly_try)--;
                        /* break out of search loop */
                        break;
                    }

                    /* thmin_this >= thmax_that - tol */
                } else {
                    /* isolating lasso */
                    th = (thmax_that + thmin_this) / 2.;
                    switch (adjust_lasso) {
                    /* as tight as possible */
                    case 0:
                        thm = thmin_this;
                        break;
                    /* for balkanize: tiny angles give garea problems */
                    case 1:
                        thm = thmin_this - .001;
                        break;
                    /* for ransack: want tight lasso */
                    case 2:
                        thm = thmin_this / 1.05;
                        break;
                    }
                    /* tighten lasso */
                    if (th < thm) th = thm;
                    if (th > 0.) {
                        s = sinl(th / 2.);
                        cme = 2. * s * s;
                    } else {
                        cme = 0.;
                    }

                    /* discard lasso that completely encloses all circles */
                    if (cme <= cmpmin_all) {
                        /* printf("%21.15Lg %21.15Lg %21.15Lg %21.15Lg\n", vm[ivm][0], vm[ivm][1], vm[ivm][2], cme); */
                        /* decrement number of polygons to try for */
                        (*npoly_try)--;
                        /* break out of search loop */
                        break;
                    }

                    cme = - cme;

                }

                /* not enough polygons for a new one */
                if (*npoly >= npolys) {
                    (*npoly)++;
                    return(0);
                }

                /* put isolating lasso into new polygon */
                np = 1;
                dnp = DNP;
                ier = room_poly(&extracap, np, dnp, 0);
                if (ier == -1) goto out_of_memory;
                for (i = 0; i < 3; i++) {
                    extracap->rp[0][i] = vm[ivm][i];
                }

                extracap->cm[0] = cme;
                extracap->np = 1;

                /* make sure new polygon contains enough space */
                np = poly->np + 1;
                dnp = 0;
                ier = room_poly(&polys[*npoly], np, dnp, 0);
                if (ier == -1) goto out_of_memory;

                /* combination of poly with new circle */
                poly_poly(poly, extracap, polys[*npoly]);

                /* increment number of polygons */
                (*npoly)++;

                /* flag found isolating boundary */
                found = 1;

                /* failed to find isolating lasso */
            } else {

                dthp = thmin_that - thmin_this;
                dthm = thmax_this - thmax_that;

                if (dthp >= dthm) {
                    /* paranoid check that ivmax_this and ivmin_that were initialized */
                    if (ivmax_this == -1 || ivmin_that == -1) {
                        /* error should never happen */
                        fprintf(stderr, "partition_poly: ivmax_this = %d ivmin_that = %d should be in interval [0, %d]\n", ivmax_this, ivmin_that, nv);
                        return(-1);
                    }

                    /* record the best lasso so far */
                    if (force_split) {
                        if (dthp > dthbest) {
                            dthbest = dthp;
                            /* circle that does not enclose connected boundary,
                               but does exclude other connected boundaries */
                            th = (thmin_this + thmin_that) / 2.;
                            thm = thmin_that * .999;
                            if (th < thm) th = thm;
                            s = sinl(th / 2.);
                            cmbest = 2. * s * s;
                            for (i = 0; i < 3; i++) {
                                vmbest[i] = vm[ivm][i];
                            }
                        }
                    }

                    /* vector to this from that */
                    for (i = 0; i < 3; i++) {
                        v[i] = vmax[ivmax_this][i] - vmin[ivmin_that][i];
                    }
                    s = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
                    /* translate centre point along vector */
                    /* the 0.02 puts centre just beyond equal distance */
                    for (i = 0; i < 3; i++) {
                        v[i] = vm[ivm][i] + ((cmvmax_this - cmvmin_that) / s + 0.02 * (it + 1)) * v[i];
                    }
                    s = sqrtl(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
                    for (i = 0; i < 3; i++) {
                        vm[ivm][i] = v[i] / s;
                    }

                } else {
                    /* paranoid check that ivmin_this and ivmax_that were initialized */
                    if (ivmin_this == -1 || ivmax_that == -1) {
                        /* error should never happen */
                        fprintf(stderr, "partition_poly: ivmin_this = %d ivmax_that = %d should be in interval [0, %d]\n", ivmin_this, ivmax_that, nv);
                        return(-1);
                    }

                    /* record the best lasso so far */
                    if (force_split) {
                        if (dthm > dthbest) {
                            dthbest = dthm;
                            /* circle that does not enclose connected boundary,
                               but does exclude other connected boundaries */
                            th = PI - (thmax_this + thmax_that) / 2.;
                            thm = (PI - thmax_that) * .999;
                            if (th < thm) th = thm;
                            s = cosl(th / 2.);
                            cmbest = - 2. * s * s;
                            for (i = 0; i < 3; i++) {
                                vmbest[i] = vm[ivm][i];
                            }
                        }
                    }

                    /* vector to that from this */
                    for (i = 0; i < 3; i++) {
                        v[i] = vmax[ivmax_that][i] - vmin[ivmin_this][i];
                    }
                    s = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
                    /* translate centre point along vector */
                    /* the 0.02 puts centre just beyond equal distance */
                    for (i = 0; i < 3; i++) {
                        v[i] = vm[ivm][i] + ((cmvmax_that - cmvmin_this) / s + 0.02 * (it + 1)) * v[i];
                    }
                    s = sqrtl(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
                    for (i = 0; i < 3; i++) {
                        vm[ivm][i] = v[i] / s;
                    }

                }

                /* flag failed to find isolating boundary */
                found = 0;

            }

        } while (!found && it++ < itmax);

        /* record the best lasso so far */
        if (force_split && !found) {
            if (dthbest > dthforce) {
                dthforce = dthbest;
                cmforce = cmbest;
                for (i = 0; i < 3; i++) {
                    vmforce[i] = vmbest[i];
                }
            }
        }

    }

    /* no polygons were lassoed */
    if (*npoly == 0) {

        /* go with original polygon */
        if (*npoly_try <= 1) {
            *npoly_try = 0;
            return(nret);
        }

        /* split polygon along best circle so far, even though it is not a lasso */
        if (force_split) {
            /* not enough polygons for a new one */
            if (*npoly >= npolys) {
                (*npoly)++;
                return(0);
            }

            /* put circle into new polygon */
            np = 1;
            dnp = DNP;
            ier = room_poly(&extracap, np, dnp, 0);
            if (ier == -1) goto out_of_memory;
            for (i = 0; i < 3; i++) {
                extracap->rp[0][i] = vmforce[i];
            }
            extracap->cm[0] = cmforce;
            extracap->np = 1;

            /* make sure new polygon contains enough space */
            np = poly->np + 1;
            dnp = 0;
            ier = room_poly(&polys[*npoly], np, dnp, 0);
            if (ier == -1) goto out_of_memory;

            /* combination of polygon with new circle */
            poly_poly(poly, extracap, polys[*npoly]);

            /* increment number of polygons */
            (*npoly)++;

            /* flag that split was forced */
            nret = 1;
        }

    }

    /* if some polygons were lassoed and others not, add complement of all new caps to polygon */
    if (*npoly > 0 && *npoly < *npoly_try) {
        /* not enough polygons for a new one */
        if (*npoly >= npolys) {
            (*npoly)++;
            return(0);
        }

        /* put complement of all new caps into new polygon */
        np = *npoly;
        dnp = DNP;
        ier = room_poly(&extracap, np, dnp, 0);
        if (ier == -1) goto out_of_memory;
        for (np = 0; np < *npoly; np++) {
            ip = polys[np]->np - 1;
            for (i = 0; i < 3; i++) {
                extracap->rp[np][i] = polys[np]->rp[ip][i];
            }
            extracap->cm[np] = - polys[np]->cm[ip];
        }
        extracap->np = *npoly;

        /* make sure new polygon contains enough space */
        np = poly->np + *npoly;
        dnp = 0;
        ier = room_poly(&polys[*npoly], np, dnp, 0);
        if (ier == -1) goto out_of_memory;

        /* poly with complement of new caps from other polygons */
        poly_poly(poly, extracap, polys[*npoly]);

        /* increment number of polygons */
        (*npoly)++;
    }

    /* trim new polygons to suppress obviously coincident caps */
    for (ip = 0; ip < *npoly; ip++) {
        trim_poly(polys[ip]);
    }

    return(nret);

    /* ---------------- error returns ---------------- */
out_of_memory:
    fprintf(stderr, "part_poly: failed to allocate memory for polygon of %d caps\n", np + dnp);
    return(-1);
}
Ejemplo n.º 27
0
Archivo: math.c Proyecto: DeforaOS/libc
double asin(double x)
{
	return asinl(x);
}
Ejemplo n.º 28
0
float asinf(float x) {
	return (float)asinl(x);
}