Example #1
0
float complex
csinhf(float complex z)
{
	float x, y, h;
	int32_t hx, hy, ix, iy;

	x = crealf(z);
	y = cimagf(z);

	GET_FLOAT_WORD(hx, x);
	GET_FLOAT_WORD(hy, y);

	ix = 0x7fffffff & hx;
	iy = 0x7fffffff & hy;

	if (ix < 0x7f800000 && iy < 0x7f800000) {
		if (iy == 0)
			return (cpackf(sinhf(x), y));
		if (ix < 0x41100000)	/* small x: normal case */
			return (cpackf(sinhf(x) * cosf(y), coshf(x) * sinf(y)));

		/* |x| >= 9, so cosh(x) ~= exp(|x|) */
		if (ix < 0x42b17218) {
			/* x < 88.7: expf(|x|) won't overflow */
			h = expf(fabsf(x)) * 0.5f;
			return (cpackf(copysignf(h, x) * cosf(y), h * sinf(y)));
		} else if (ix < 0x4340b1e7) {
			/* x < 192.7: scale to avoid overflow */
			z = __ldexp_cexpf(cpackf(fabsf(x), y), -1);
			return (cpackf(crealf(z) * copysignf(1, x), cimagf(z)));
		} else {
			/* x >= 192.7: the result always overflows */
			h = huge * x;
			return (cpackf(h * cosf(y), h * h * sinf(y)));
		}
	}

	if (ix == 0 && iy >= 0x7f800000)
		return (cpackf(copysignf(0, x * (y - y)), y - y));

	if (iy == 0 && ix >= 0x7f800000) {
		if ((hx & 0x7fffff) == 0)
			return (cpackf(x, y));
		return (cpackf(x, copysignf(0, y)));
	}

	if (ix < 0x7f800000 && iy >= 0x7f800000)
		return (cpackf(y - y, x * (y - y)));

	if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) {
		if (iy >= 0x7f800000)
			return (cpackf(x * x, x * (y - y)));
		return (cpackf(x * cosf(y), INFINITY * sinf(y)));
	}

	return (cpackf((x * x) * (y - y), (x + x) * (y - y)));
}
Example #2
0
static float
kepler(const float ecc, float mean_anom)
{
	float curr, err, thresh;
	int is_negative = 0, n_iter = 0;

	if( !mean_anom) {
		return( 0.);
	}

	if( ecc < .3) {   /* low-eccentricity formula from Meeus,  p. 195 */
		curr = atan2f( sinf( mean_anom), cosf( mean_anom) - ecc);
			/* one correction step,  and we're done */
		err = curr - ecc * sinf( curr) - mean_anom;
		curr -= err / (1. - ecc * cosf( curr));
	} else {
	    curr = mean_anom;
	}

	if( mean_anom < 0.) {
		mean_anom = -mean_anom;
		curr = - curr;
		is_negative = 1;
	}

	thresh = THRESH * fabsf( 1. - ecc);
	if( ecc > .8 && mean_anom < PI / 3. || ecc > 1.)    /* up to 60 degrees */ {
		float trial = mean_anom / fabsf( 1. - ecc);

		if( trial * trial > 6. * fabsf(1. - ecc))   /* cubic term is dominant */ {
			if( mean_anom < PI) {
				trial = CUBE_ROOT( 6. * mean_anom);
			} else {      /* hyperbolic w/ 5th & higher-order terms predominant */
				trial = asinhf( mean_anom / ecc);
			}
		}
		curr = trial;
	}

	if( ecc < 1.) {
		err = curr - ecc * sinf( curr) - mean_anom;
		while( fabsf( err) > thresh) {
			n_iter++;
			curr -= err / (1. - ecc * cosf( curr));
			err = curr - ecc * sinf( curr) - mean_anom;
		}
	} else {
		err = ecc * sinhf( curr) - curr - mean_anom;
		while( fabsf( err) > thresh) {
			n_iter++;
			curr -= err / (ecc * coshf( curr) - 1.);
			err = ecc * sinhf( curr) - curr - mean_anom;
		}
	}
	return( is_negative ? -curr : curr);
}
Example #3
0
ATF_TC_BODY(sinhf_nan, tc)
{
	const float x = 0.0L / 0.0L;

	ATF_CHECK(isnan(x) != 0);
	ATF_CHECK(isnan(sinhf(x)) != 0);
}
Example #4
0
static TACommandVerdict sinhf_cmd(TAThread thread,TAInputStream stream)
{
    float x, res;

    // Prepare

    x = readFloat(&stream);
    errno = 0;
    
    START_TARGET_OPERATION(thread);
    
    // Execute

    res = sinhf(x);
    
    END_TARGET_OPERATION(thread);
    
    // Response
    
    writeFloat(thread, res);
    writeInt(thread, errno);

    sendResponse(thread);
    return taDefaultVerdict;
}
Example #5
0
/**
 * Performs some maths operation
 */
static void performMathsOp(struct core_ctrl * core) {
	if (core->core_command-1000 == RANDOM_MATHS_OP) {
		core->data[0]=INT_TYPE;
		int r=rand();
		memcpy(&core->data[1], &r, sizeof(int));
	} else {
		float fvalue=0.0, r=0.0;
		if (core->data[0]==1) {
			fvalue=*((float*) &core->data[1]);
		} else if (core->data[0]==0) {
			fvalue=(float) *((int*) &core->data[1]);
		}
		if (core->core_command-1000 == SQRT_MATHS_OP) r=sqrtf(fvalue);
		if (core->core_command-1000 == SIN_MATHS_OP) r=sinf(fvalue);
		if (core->core_command-1000 == COS_MATHS_OP) r=cosf(fvalue);
		if (core->core_command-1000 == TAN_MATHS_OP) r=tanf(fvalue);
		if (core->core_command-1000 == ASIN_MATHS_OP) r=asinf(fvalue);
		if (core->core_command-1000 == ACOS_MATHS_OP) r=acosf(fvalue);
		if (core->core_command-1000 == ATAN_MATHS_OP) r=atanf(fvalue);
		if (core->core_command-1000 == SINH_MATHS_OP) r=sinhf(fvalue);
		if (core->core_command-1000 == COSH_MATHS_OP) r=coshf(fvalue);
		if (core->core_command-1000 == TANH_MATHS_OP) r=tanhf(fvalue);
		if (core->core_command-1000 == FLOOR_MATHS_OP) r=floorf(fvalue);
		if (core->core_command-1000 == CEIL_MATHS_OP) r=ceilf(fvalue);
		if (core->core_command-1000 == LOG_MATHS_OP) r=logf(fvalue);
		if (core->core_command-1000 == LOG10_MATHS_OP) r=log10f(fvalue);
		core->data[0]=REAL_TYPE;
		memcpy(&core->data[1], &r, sizeof(float));
	}
}
Example #6
0
float complex ctanhf(float complex z)
{
	float x, y;
	float t, beta, s, rho, denom;
	uint32_t hx, ix;

	x = crealf(z);
	y = cimagf(z);

	GET_FLOAT_WORD(hx, x);
	ix = hx & 0x7fffffff;

	if (ix >= 0x7f800000) {
		if (ix & 0x7fffff)
			return CMPLXF(x, (y == 0 ? y : x * y));
		SET_FLOAT_WORD(x, hx - 0x40000000);
		return CMPLXF(x, copysignf(0, isinf(y) ? y : sinf(y) * cosf(y)));
	}

	if (!isfinite(y))
		return CMPLXF(y - y, y - y);

	if (ix >= 0x41300000) { /* x >= 11 */
		float exp_mx = expf(-fabsf(x));
		return CMPLXF(copysignf(1, x), 4 * sinf(y) * cosf(y) * exp_mx * exp_mx);
	}

	t = tanf(y);
	beta = 1.0 + t * t;
	s = sinhf(x);
	rho = sqrtf(1 + s * s);
	denom = 1 + beta * s * s;
	return CMPLXF((beta * rho * s) / denom, t / denom);
}
Example #7
0
float complex csinf (float complex Z)
{
  float complex Res;
  __real__ Res = sinf (__real__ Z) * coshf ( __imag__ Z);
  __imag__ Res = cosf (__real__ Z) * sinhf ( __imag__ Z);
  return Res;
}
/* Convert lla to utm (float).
 * Note this conversion is not very accurate. If high accuracy needed use lla_of_utm_d.
 * @param[out] utm position in m, alt is copied directly from lla
 * @param[in]  lla position in rad, alt in m
 */
void utm_of_lla_f(struct UtmCoor_f *utm, struct LlaCoor_f *lla)
{
  // compute zone if not initialised
  if (utm->zone == 0) {
    utm->zone = UtmZoneOfLlaLonRad(lla->lon);
  }

  float lambda_c = LambdaOfUtmZone(utm->zone);
  float ll = isometric_latitude_f(lla->lat , E);
  float dl = lla->lon - lambda_c;
  float phi_ = asinf(sinf(dl) / coshf(ll));
  float ll_ = isometric_latitude_fast_f(phi_);
  float lambda_ = atanf(sinhf(ll) / cosf(dl));
  struct complex z_ = { lambda_,  ll_ };
  CScal(serie_coeff_proj_mercator[0], z_);
  int8_t k;
  for (k = 1; k < 3; k++) {
    struct complex z = { lambda_, ll_ };
    CScal(2.*k, z);
    CSin(z);
    CScal(serie_coeff_proj_mercator[k], z);
    CAdd(z, z_);
  }
  CScal(N, z_);
  utm->east = DELTA_EAST + z_.im;
  utm->north = DELTA_NORTH + z_.re;

  // copy alt above reference ellipsoid
  utm->alt = lla->alt;
}
Example #9
0
float complex CLANG_PORT_DECL(ccoshf) (float complex Z)
{
  float complex Res;
  __real__ Res = coshf (__real__ Z) * cosf (__imag__ Z);
  __imag__ Res = sinhf (__real__ Z) * sinf (__imag__ Z);
  return Res;
}
/* Convert utm to lla (float).
 * Note this conversion is not very accurate. If high accuracy needed use lla_of_utm_d.
 * @param[out] lla position in rad, alt is copied directly from utm
 * @param[in]  utm position in m, alt in m
 */
void lla_of_utm_f(struct LlaCoor_f *lla, struct UtmCoor_f *utm)
{
  float scale = 1 / N / serie_coeff_proj_mercator[0];
  float real = (utm->north - DELTA_NORTH) * scale;
  float img = (utm->east - DELTA_EAST) * scale;
  struct complex z = { real, img };

  int8_t k;
  for (k = 1; k < 2; k++) {
    struct complex z_ = { real, img };
    CScal(2.*k, z_);
    CSin(z_);
    CScal(serie_coeff_proj_mercator_inverse[k], z_);
    CSub(z_, z);
  }

  float lambda_c = LambdaOfUtmZone(utm->zone);
  lla->lon = lambda_c + atanf(sinhf(z.im) / cosf(z.re));
  float phi_ = asinf(sinf(z.re) / coshf(z.im));
  float il = isometric_latitude_fast_f(phi_);
  lla->lat = inverse_isometric_latitude_f(il, E, 1e-8);

  // copy alt above reference ellipsoid
  lla->alt = utm->alt;
}
Example #11
0
void test_sinh()
{
    static_assert((std::is_same<decltype(sinh((double)0)), double>::value), "");
    static_assert((std::is_same<decltype(sinhf(0)), float>::value), "");
    static_assert((std::is_same<decltype(sinhl(0)), long double>::value), "");
    assert(sinh(0) == 0);
}
Example #12
0
/**
 * Called when running on the host, this performs some maths operation
 */
struct value_defn performMathsOp(unsigned short operation, struct value_defn value) {
	struct value_defn result;
	result.dtype=SCALAR;
	if (operation== RANDOM_MATHS_OP) {
		result.type=INT_TYPE;
		int r=rand();
		cpy(result.data, &r, sizeof(int));
	} else {
		float fvalue, r;
		if (value.type==REAL_TYPE) {
			fvalue=*((float*) value.data);
		} else if (value.type==INT_TYPE) {
			fvalue=(float) *((int*) value.data);
		}
		result.type=REAL_TYPE;
		if (operation==SQRT_MATHS_OP) r=sqrtf(fvalue);
		if (operation==SIN_MATHS_OP) r=sinf(fvalue);
		if (operation==COS_MATHS_OP) r=cosf(fvalue);
		if (operation==TAN_MATHS_OP) r=tanf(fvalue);
		if (operation==ASIN_MATHS_OP) r=asinf(fvalue);
		if (operation==ACOS_MATHS_OP) r=acosf(fvalue);
		if (operation==ATAN_MATHS_OP) r=atanf(fvalue);
		if (operation==SINH_MATHS_OP) r=sinhf(fvalue);
		if (operation==COSH_MATHS_OP) r=coshf(fvalue);
		if (operation==TANH_MATHS_OP) r=tanhf(fvalue);
		if (operation==FLOOR_MATHS_OP) r=floorf(fvalue);
		if (operation==CEIL_MATHS_OP) r=ceilf(fvalue);
		if (operation==LOG_MATHS_OP) r=logf(fvalue);
		if (operation==LOG10_MATHS_OP) r=log10f(fvalue);
		cpy(result.data, &r, sizeof(float));
	}
	return result;
}
Example #13
0
float complex ctanf (float complex Z)
{
  float complex Res;
  float two_I = 2.0f * __imag__ Z;
  float two_R = 2.0f * __real__ Z;
  float denom = cosf (two_R) + coshf (two_I);
  if (denom == 0.0f)
    {
      errno = ERANGE;
      __real__ Res = HUGE_VALF;
      __imag__ Res = HUGE_VALF;
    }
  else if (isinf (denom))
    {
      errno = ERANGE;
      __real__ Res = 0.0;
      __imag__ Res = two_I > 0 ? 1.0f : -1.0f;
    }
  else
    {
      __real__ Res = sinf (two_R) / denom;
      __imag__ Res = sinhf (two_I) / denom;
    }
  return Res;
}
Example #14
0
ATF_TC_BODY(sinhf_zero_pos, tc)
{
	const float x = 0.0L;
	float y = sinhf(x);

	if (fabsf(y) > 0.0 || signbit(y) != 0)
		atf_tc_fail_nonfatal("sinhf(+0.0) != +0.0");
}
Example #15
0
ATF_TC_BODY(sinhf_inf_pos, tc)
{
	const float x = 1.0L / 0.0L;
	float y = sinhf(x);

	ATF_CHECK(isinf(y) != 0);
	ATF_CHECK(signbit(y) == 0);
}
Example #16
0
static void *sinh_new(t_floatarg f)
{
    t_sinh *x = (t_sinh *)pd_new(sinh_class);
    /* CHECKME large values */
    x->x_value = sinhf(f);
    outlet_new((t_object *)x, &s_float);
    return (x);
}
Example #17
0
complex __ccos(float zreal, float zimag)
{
  complex r;

  r.real = cosf(zreal) * coshf(zimag);
  r.imag = - sinf(zreal) * sinhf(zimag);
  return r;
}
Example #18
0
ATF_TC_BODY(sinhf_zero_neg, tc)
{
	const float x = -0.0L;
	float y = sinhf(x);

	if (fabsf(y) > 0.0 || signbit(y) == 0)
		atf_tc_fail_nonfatal("sinhf(-0.0) != -0.0");
}
Example #19
0
float complex
csinhf(float complex z)
{
	float complex w;
	float x, y;

	x = crealf(z);
	y = cimagf(z);
	w = sinhf (x) * cosf (y)  +  (coshf (x) * sinf (y)) * I;
	return (w);
}
Example #20
0
float complex
ccoshf (float complex a)
{
  float r, i;
  float complex v;

  r = REALPART (a);
  i = IMAGPART (a);
  COMPLEX_ASSIGN (v, coshf (r) * cosf (i), - (sinhf (r) * sinf (i)));
  return v;
}
Example #21
0
float complex
ccoshf(float complex z)
{
	float complex w;
	float x, y;

	x = creal(z);
	y = cimag(z);
	w = coshf (x) * cosf (y)  +  (sinhf (x) * sinf (y)) * I;
	return (w);
}
Example #22
0
float complex
ctanhf(float complex z)
{
	float complex w;
	float x, y, d;

	x = crealf(z);
	y = cimagf(z);
	d = coshf (2.0f * x) + cosf (2.0f * y);
	w = sinhf (2.0f * x) / d  +  (sinf (2.0f * y) / d) * I;
	return (w);
}
/* cosh(z) = cosh(a)cos(b) - isinh(a)sin(b)  */
GFC_COMPLEX_4
ccoshf (GFC_COMPLEX_4 a)
{
  GFC_REAL_4 r;
  GFC_REAL_4 i;
  GFC_COMPLEX_4 v;

  r = REALPART (a);
  i = IMAGPART (a);
  COMPLEX_ASSIGN (v, coshf (r) * cosf (i), - (sinhf (r) * sinf (i)));
  return v;
}
Example #24
0
// substitute STDampedSpringStep's r with ri (i=imaginary unit),
// you get over-damping equation.
float STOverDampedSpringStep(float value){
    const float r=3.3f; // [???]
    if(value<0.f)value=0.f;
    if(value>1.f)value=1.f;

    float theta=r*value;
    float v=1.f;
    float tt=(value*(value-2.f)+1.f);
    v-=tt*coshf(theta);
    v-=(2.f/r)*(value*(value-2.f)+1.f)*sinhf(theta);
    return v;
}
Example #25
0
kiss_fft_cpx sf_ccosf(kiss_fft_cpx z)
/*< complex cosine >*/
{
    float x, y;

    x = z.r;
    y = z.i;

    z.r = coshf(y)*cosf(x);
    z.i = -sinhf(y)*sinf(x);

    return z;
}
Example #26
0
kiss_fft_cpx sf_csinhf(kiss_fft_cpx z)
/*< complex hyperbolic sine >*/
{
    float x, y;

    x = z.r;
    y = z.i;

    z.r = sinhf(x)*cosf(y);
    z.i = coshf(x)*sinf(y);

    return z;
}
Example #27
0
kiss_fft_cpx sf_ctanhf(kiss_fft_cpx z)
/*< complex hyperbolic tangent >*/
{
    float x, y, d;

    x = z.r;
    y = z.i;

    d = coshf(2*x) + cosf(2*y);
    z.r = sinhf(2*x)/ d;
    z.i = sinf (2*y)/ d;

    return z;
}
Example #28
0
ATF_TC_BODY(sinhf_inrange, tc)
{
	float eps;
	float x;
	float y;
	size_t i;

	for (i = 0; i < __arraycount(values); i++) {
		x = values[i].x;
		y = values[i].y;
		eps = 1e-6 * values[i].e;

		if (fabsf(sinhf(x) - y) > eps)
			atf_tc_fail_nonfatal("sinhf(%g) != %g\n", x, y);
	}
}
Example #29
0
static void
cchshf(float xx, float *c, float *s)
{
	float x, e, ei;

	x = xx;
	if(fabsf(x) <= 0.5f) {
		*c = coshf(x);
		*s = sinhf(x);
	}
	else {
		e = expf(x);
		ei = 0.5f/e;
		e = 0.5f * e;
		*s = e - ei;
		*c = e + ei;
	}
}
Example #30
0
float complex
ctanf(float complex z)
{
	float complex w;
	float d;

	d = cosf( 2.0f * crealf(z) ) + coshf( 2.0f * cimagf(z) );

	if(fabsf(d) < 0.25f)
		d = _ctansf(z);

	if (d == 0.0f) {
		/*mtherr( "ctanf", OVERFLOW );*/
		w = MAXNUMF + MAXNUMF * I;
		return (w);
	}
	w = sinf (2.0f * crealf(z)) / d + (sinhf (2.0f * cimagf(z)) / d) * I;
	return (w);
}