当前位置: 首页>>代码示例>>C++>>正文


C++ copysignf函数代码示例

本文整理汇总了C++中copysignf函数的典型用法代码示例。如果您正苦于以下问题:C++ copysignf函数的具体用法?C++ copysignf怎么用?C++ copysignf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了copysignf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: csqrtf

float complex
csqrtf (float complex z)
{
  float re, im;
  float complex v;

  re = REALPART (z);
  im = IMAGPART (z);
  if (im == 0)
    {
      if (re < 0)
        {
          COMPLEX_ASSIGN (v, 0, copysignf (sqrtf (-re), im));
        }
      else
        {
          COMPLEX_ASSIGN (v, fabsf (sqrtf (re)), copysignf (0, im));
        }
    }
  else if (re == 0)
    {
      float r;

      r = sqrtf (0.5 * fabsf (im));

      COMPLEX_ASSIGN (v, r, copysignf (r, im));
    }
  else
    {
      float d, r, s;

      d = hypotf (re, im);
      /* Use the identity   2  Re res  Im res = Im x
         to avoid cancellation error in  d +/- Re x.  */
      if (re > 0)
        {
          r = sqrtf (0.5 * d + 0.5 * re);
          s = (0.5 * im) / r;
        }
      else
        {
          s = sqrtf (0.5 * d - 0.5 * re);
          r = fabsf ((0.5 * im) / s);
        }

      COMPLEX_ASSIGN (v, r, copysignf (s, im));
    }
  return v;
}
开发者ID:5432935,项目名称:crossbridge,代码行数:49,代码来源:c99_functions.c

示例2: csqrtf

float complex
csqrtf(float complex z)
{
	double t;
	float a, b;

	a = creal(z);
	b = cimag(z);

	/* Handle special cases. */
	if (z == 0)
		return (CMPLXF(0, b));
	if (isinf(b))
		return (CMPLXF(INFINITY, b));
	if (isnan(a)) {
		t = (b - b) / (b - b);	/* raise invalid if b is not a NaN */
		return (CMPLXF(a + 0.0L + t, a + 0.0L + t)); /* NaN + NaN i */
	}
	if (isinf(a)) {
		/*
		 * csqrtf(inf + NaN i)  = inf +  NaN i
		 * csqrtf(inf + y i)    = inf +  0 i
		 * csqrtf(-inf + NaN i) = NaN +- inf i
		 * csqrtf(-inf + y i)   = 0   +  inf i
		 */
		if (signbit(a))
			return (CMPLXF(fabsf(b - b), copysignf(a, b)));
		else
			return (CMPLXF(a, copysignf(b - b, b)));
	}
	if (isnan(b)) {
		t = (a - a) / (a - a);	/* raise invalid */
		return (CMPLXF(b + 0.0L + t, b + 0.0L + t)); /* NaN + NaN i */
	}

	/*
	 * We compute t in double precision to avoid overflow and to
	 * provide correct rounding in nearly all cases.
	 * This is Algorithm 312, CACM vol 10, Oct 1967.
	 */
	if (a >= 0) {
		t = sqrt((a + hypot(a, b)) * 0.5);
		return (CMPLXF(t, b / (2 * t)));
	} else {
		t = sqrt((-a + hypot(a, b)) * 0.5);
		return (CMPLXF(fabsf(b) / (2 * t), copysignf(t, b)));
	}
}
开发者ID:android,项目名称:platform_bionic,代码行数:48,代码来源:s_csqrtf.c

示例3: test_copysign

void test_copysign()
{
    static_assert((std::is_same<decltype(copysign((double)0, (double)0)), double>::value), "");
    static_assert((std::is_same<decltype(copysignf(0,0)), float>::value), "");
    static_assert((std::is_same<decltype(copysignl(0,0)), long double>::value), "");
    assert(copysign(1,1) == 1);
}
开发者ID:Bluerise,项目名称:bitrig,代码行数:7,代码来源:math_h.pass.cpp

示例4: gl_signbitf

int
gl_signbitf (float arg)
{
#if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
  /* The use of a union to extract the bits of the representation of a
     'long double' is safe in practice, despite of the "aliasing rules" of
     C99, because the GCC docs say
       "Even with '-fstrict-aliasing', type-punning is allowed, provided the
        memory is accessed through the union type."
     and similarly for other compilers.  */
# define NWORDS \
    ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
  union { float value; unsigned int word[NWORDS]; } m;
  m.value = arg;
  return (m.word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1;
#elif HAVE_COPYSIGNF_IN_LIBC
  return copysignf (1.0f, arg) < 0;
#else
  /* This does not do the right thing for NaN, but this is irrelevant for
     most use cases.  */
  if (isnanf (arg))
    return 0;
  if (arg < 0.0f)
    return 1;
  else if (arg == 0.0f)
    {
      /* Distinguish 0.0f and -0.0f.  */
      static float plus_zero = 0.0f;
      float arg_mem = arg;
      return (memcmp (&plus_zero, &arg_mem, SIZEOF_FLT) != 0);
    }
  else
    return 0;
#endif
}
开发者ID:iauther,项目名称:x,代码行数:35,代码来源:signbitf.c

示例5: find_midtangent

// Given a convex curve segment with the following order-2 tangent function:
//
//                                                       |C2x  C2y|
//     tan = some_scale * |dx/dt  dy/dt| = |t^2  t  1| * |C1x  C1y|
//                                                       |C0x  C0y|
//
// This function finds the T value whose tangent angle is halfway between the tangents at T=0 and
// T=1 (tan0 and tan1).
static inline float find_midtangent(const Sk2f& tan0, const Sk2f& tan1,
                                    const Sk2f& C2, const Sk2f& C1, const Sk2f& C0) {
    // Tangents point in the direction of increasing T, so tan0 and -tan1 both point toward the
    // midtangent. 'n' will therefore bisect tan0 and -tan1, giving us the normal to the midtangent.
    //
    //     n dot midtangent = 0
    //
    Sk2f n = normalize(tan0) - normalize(tan1);

    // Find the T value at the midtangent. This is a simple quadratic equation:
    //
    //     midtangent dot n = 0
    //
    //     (|t^2  t  1| * C) dot n = 0
    //
    //     |t^2  t  1| dot C*n = 0
    //
    // First find coeffs = C*n.
    Sk4f C[2];
    Sk2f::Store4(C, C2, C1, C0, 0);
    Sk4f coeffs = C[0]*n[0] + C[1]*n[1];

    // Now solve the quadratic.
    float a = coeffs[0], b = coeffs[1], c = coeffs[2];
    float discr = b*b - 4*a*c;
    if (discr < 0) {
        return 0; // This will only happen if the curve is a line.
    }

    // The roots are q/a and c/q. Pick the one closer to T=.5.
    float q = -.5f * (b + copysignf(std::sqrt(discr), b));
    float r = .5f*q*a;
    return std::abs(q*q - r) < std::abs(a*c - r) ? q/a : c/q;
}
开发者ID:jasonLaster,项目名称:gecko-dev,代码行数:42,代码来源:GrCCFillGeometry.cpp

示例6: vector_copysign

void
vector_copysign (void)
{
  int i;

  for (i = 0; i < SIZE; i++)
    a[i] = copysignf (b[i], c[i]);
}
开发者ID:MaxKellermann,项目名称:gcc,代码行数:8,代码来源:altivec-32.c

示例7: casinhf

float complex
casinhf(float complex z)
{
	float x, y, ax, ay, rx, ry, B, sqrt_A2my2, new_y;
	int B_is_usable;
	float complex w;

	x = crealf(z);
	y = cimagf(z);
	ax = fabsf(x);
	ay = fabsf(y);

	if (isnan(x) || isnan(y)) {
		if (isinf(x))
			return (CMPLXF(x, y + y));
		if (isinf(y))
			return (CMPLXF(y, x + x));
		if (y == 0)
			return (CMPLXF(x + x, y));
		return (CMPLXF(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
	}

	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 (CMPLXF(copysignf(crealf(w), x),
		    copysignf(cimagf(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 = asinf(B);
	else
		ry = atan2f(new_y, sqrt_A2my2);
	return (CMPLXF(copysignf(rx, x), copysignf(ry, y)));
}
开发者ID:0xDEC0DE8,项目名称:platform_bionic,代码行数:46,代码来源:catrigf.c

示例8: csqrtf

float complex
csqrtf(float complex z)
{
	float a = crealf(z), b = cimagf(z);
	double t;

	/* Handle special cases. */
	if (z == 0)
		return (cpackf(0, b));
	if (isinf(b))
		return (cpackf(INFINITY, b));
	if (isnan(a)) {
		t = (b - b) / (b - b);	/* raise invalid if b is not a NaN */
		return (cpackf(a, t));	/* return NaN + NaN i */
	}
	if (isinf(a)) {
		/*
		 * csqrtf(inf + NaN i)  = inf +  NaN i
		 * csqrtf(inf + y i)    = inf +  0 i
		 * csqrtf(-inf + NaN i) = NaN +- inf i
		 * csqrtf(-inf + y i)   = 0   +  inf i
		 */
		if (signbit(a))
			return (cpackf(fabsf(b - b), copysignf(a, b)));
		else
			return (cpackf(a, copysignf(b - b, b)));
	}
	/*
	 * The remaining special case (b is NaN) is handled just fine by
	 * the normal code path below.
	 */

	/*
	 * We compute t in double precision to avoid overflow and to
	 * provide correct rounding in nearly all cases.
	 * This is Algorithm 312, CACM vol 10, Oct 1967.
	 */
	if (a >= 0) {
		t = sqrt((a + hypot(a, b)) * 0.5);
		return (cpackf(t, b / (2.0 * t)));
	} else {
		t = sqrt((-a + hypot(a, b)) * 0.5);
		return (cpackf(fabsf(b) / (2.0 * t), copysignf(t, b)));
	}
}
开发者ID:CoryXie,项目名称:BarrelfishOS,代码行数:45,代码来源:s_csqrtf.c

示例9: bounce

 void bounce(const Player &player, float &newXSpeed, float &newYSpeed) {
     const float ballCenterY = _y + (BALL_SIZE / 2);
     const float playerCenterY = player.getCoords().y + HALF_PLAYER_HEIGHT;
     const float normalizedDistance = fmin(1.0f, fabs(playerCenterY - ballCenterY) / HALF_PLAYER_HEIGHT);
     const float speedScaleX = fmax(0.5f, 1.0f - normalizedDistance);
     const float speedScaleY = fmax(0.5f, normalizedDistance);
     newXSpeed = fmin(MAX_BALL_SPEED, MAX_BALL_SPEED * speedScaleX + MAX_BALL_SPEED / 2.0f);
     newYSpeed = copysignf(MAX_BALL_SPEED * speedScaleY, _ySpeed);
 }
开发者ID:johnnyw,项目名称:GLPong,代码行数:9,代码来源:main.cpp

示例10: cprojf

DLLEXPORT float complex
cprojf(float complex z)
{

	if (!isinf(crealf(z)) && !isinf(cimagf(z)))
		return (z);
	else
		return (CMPLXF(INFINITY, copysignf(0.0, cimagf(z))));
}
开发者ID:iblis17,项目名称:openlibm,代码行数:9,代码来源:s_cprojf.c

示例11: cprojf

float complex
cprojf(float complex z)
{

    if (!isinf(crealf(z)) && !isinf(cimagf(z)))
        return (z);
    else
        return (cpackf(INFINITY, copysignf(0.0, cimagf(z))));
}
开发者ID:NuclearAndroidProject1,项目名称:android_bionic,代码行数:9,代码来源:s_cprojf.c

示例12: radius_callback

static void
radius_callback (GtkWidget *slider, gpointer user_data)
{
  dt_iop_module_t *self = (dt_iop_module_t *)user_data;
  if(self->dt->gui->reset) return;
  dt_iop_lowpass_params_t *p = (dt_iop_lowpass_params_t *)self->params;
  p->radius = copysignf(dt_bauhaus_slider_get(slider), p->radius);
  dt_dev_add_history_item(darktable.develop, self, TRUE);
}
开发者ID:jmarca,项目名称:darktable,代码行数:9,代码来源:lowpass.c

示例13: __lroundf

long int
__lroundf (float x)
{
  float adj;

  adj = 0x1.fffffep-2;		/* nextafterf (0.5f, 0.0f) */
  adj = copysignf (adj, x);
  return x + adj;
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.toolchain,代码行数:9,代码来源:s_lroundf.c

示例14: rangecompress

inline float rangecompress (float x)
{
    // Formula courtesy of Sony Pictures Imageworks
    const float x1 = 1.0, a = 1.2607481479644775391;
    const float b = 0.28785100579261779785, c = -1.4042005538940429688;
    float absx = fabsf(x);
    if (absx <= x1)
        return x;
    return copysignf (a + b * logf(fabsf(c*absx + 1.0f)), x);
}
开发者ID:jcrogel,项目名称:oiio,代码行数:10,代码来源:imagebufalgo_pixelmath.cpp

示例15: erff

float erff(float x)
{
  float t;
  float z;

  z = fabsf(x);
  t = 1.0F / (1.0F + P * z);
  t = 1.0F - (((((A5 * t + A4) * t) + A3) * t + A2) * t + A1) * t * expf(-z * z);
  return copysignf(t, x);
}
开发者ID:a1ien,项目名称:nuttx,代码行数:10,代码来源:lib_erff.c


注:本文中的copysignf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。