Ejemplo n.º 1
0
AABB Triangle::getClippedAABB(const Point *positions, const AABB &aabb) const {
    /* Reserve room for some additional vertices */
    Point3d vertices1[MAX_VERTS], vertices2[MAX_VERTS];
    int nVertices = 3;

    /* The kd-tree code will frequently call this function with
       almost-collapsed AABBs. It's extremely important not to introduce
       errors in such cases, otherwise the resulting tree will incorrectly
       remove triangles from the associated nodes. Hence, do the
       following computation in double precision! */
    for (int i=0; i<3; ++i)
        vertices1[i] = Point3d(positions[idx[i]]);

    for (int axis=0; axis<3; ++axis) {
        nVertices = sutherlandHodgman(vertices1, nVertices, vertices2, axis, aabb.min[axis], true);
        nVertices = sutherlandHodgman(vertices2, nVertices, vertices1, axis, aabb.max[axis], false);
    }

    AABB result;
    for (int i=0; i<nVertices; ++i) {
#if defined(SINGLE_PRECISION)
        for (int j=0; j<3; ++j) {
            /* Now this is really paranoid! */
            double pos_d = vertices1[i][j];
            float  pos_f = (float) pos_d;
            float  pos_roundedDown, pos_roundedUp;

            if (pos_f < pos_d) {
                /* Float value is too small */
                pos_roundedDown = pos_f;
                pos_roundedUp = nextafterf(pos_f,
                                           std::numeric_limits<float>::infinity());
            } else if (pos_f > pos_d) {
                /* Float value is too large */
                pos_roundedUp = pos_f;
                pos_roundedDown = nextafterf(pos_f,
                                             -std::numeric_limits<float>::infinity());
            } else {
                /* Double value is exactly representable */
                pos_roundedDown = pos_roundedUp = pos_f;
            }

            result.min[j] = std::min(result.min[j], pos_roundedDown);
            result.max[j] = std::max(result.max[j], pos_roundedUp);
        }
#else
        result.expandBy(vertices1[i]);
#endif
    }
    result.clip(aabb);

    return result;
}
static inline GFC_REAL_4
almostone_r4 ()
{
#ifdef HAVE_NEXTAFTERF
  return nextafterf (1.0f, 0.0f);
#else
  /* The volatile is a hack to prevent excess precision on x86.  */
  static volatile GFC_REAL_4 val = 0.0f;
  GFC_REAL_4 x;

  if (val != 0.0f)
    return val;

  val = 0.9999f;
  do
    {
      x = val;
      val = (val + 1.0f) / 2.0f;
    }
  while (val > x && val < 1.0f);
  if (val == 1.0f)
    val = x;
  return val;
#endif
}
Ejemplo n.º 3
0
edge_ref delaunay_build(int nsites)
{
    edge_ref le, re;
    site_struct **sites;
    Node *N;
    int i, j;

    assert(sites =
           (site_struct **) malloc(nsites * sizeof(site_struct *)));
    for (i = 0, N = FirstNode; i < nsites; i++, N = N->Suc) {
        sites[i] = N;
        N->Yc = N->Y;
    }
    qsort(sites, nsites, sizeof(site_struct *), compare);
    /* Perturb duplicate points a bit in their Y-coordinate */
    for (i = 0; i < nsites; i++) {
        for (j = i + 1; j < nsites; j++)
            if ((float) sites[j]->X != (float) sites[i]->X ||
                (float) sites[j]->Y != (float) sites[i]->Y)
                break;
        for (j--; i < j; i++)
            sites[i + 1]->Y = nextafterf((float) sites[i]->Y, FLT_MAX);
    }
    rec_delaunay(sites, 0, nsites, &le, &re);
    for (i = 0; i < nsites; i++)
        sites[i]->Y = sites[i]->Yc;
    free(sites);
    return le;
}
static double clampToRange(double value, InterpolationRange clamp)
{
    switch (clamp) {
    case RangeAll:
        // Do nothing
        return value;
    case RangeZeroToOne:
        return clampTo<float>(value, 0, 1);
    case RangeOpacityFIXME:
        return clampTo<float>(value, 0, nextafterf(1, 0));
    case RangeFloor:
        return floor(value);
    case RangeRound:
        return round(value);
    case RangeRoundGreaterThanOrEqualToOne:
        return clampTo<float>(round(value), 1);
    case RangeGreaterThanOrEqualToOne:
        return clampTo<float>(value, 1);
    case RangeNonNegative:
        return clampTo<float>(value, 0);
    default:
        ASSERT_NOT_REACHED();
        return value;
    }
}
Ejemplo n.º 5
0
void test_nextafter()
{
    static_assert((std::is_same<decltype(nextafter((double)0, (double)0)), double>::value), "");
    static_assert((std::is_same<decltype(nextafterf(0,0)), float>::value), "");
    static_assert((std::is_same<decltype(nextafterl(0,0)), long double>::value), "");
    assert(nextafter(0,1) == hexfloat<double>(0x1, 0, -1074));
}
Ejemplo n.º 6
0
void delaunay(int n,LKH::LKHAlg *Alg)
{
    edge *l_cw, *r_ccw;
    point **p_sorted;
    LKH::LKHAlg::Node *N = Alg->FirstNode;
    int i, j;

    alloc_memory(n);
    for (i = 0; i < n; i++) {
        p_array.get()[i].x = N->X;
        p_array.get()[i].y = N->Y;
        p_array.get()[i].id = N->Id;
        p_array.get()[i].entry_pt = 0;
        N = N->Suc;
    }

    assert(p_sorted = (point **) malloc(n * sizeof(point *)));
    for (i = 0; i < n; i++)
        p_sorted[i] = p_array.get() + i;
    qsort(p_sorted, n, sizeof(point *), compare);

    /* Perturb duplicate points a bit in their Y-coordinate */
    for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++)
            if ((float) p_sorted[j]->x != (float) p_sorted[i]->x ||
                (float) p_sorted[j]->y != (float) p_sorted[i]->y)
                break;
        for (j--; i < j; i++)
            p_sorted[i + 1]->y =
                nextafterf((float) p_sorted[i]->y, FLT_MAX);
    }

    divide(p_sorted, 0, n - 1, &l_cw, &r_ccw);
    free(p_sorted);
}
Ejemplo n.º 7
0
PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::interpolableValueToDouble(InterpolableValue* value, ClampRange clamp)
{
    ASSERT(value->isNumber());
    double doubleValue = toInterpolableNumber(value)->value();
    if (clamp == ClampOpacity) {
        doubleValue = clampTo<float>(doubleValue, 0, nextafterf(1, 0));
    }
    return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUMBER);
}
Ejemplo n.º 8
0
SkLinearBitmapPipeline::SkLinearBitmapPipeline(
    const SkMatrix& inverse,
    SkFilterQuality filterQuality,
    SkShader::TileMode xTile, SkShader::TileMode yTile,
    SkColor paintColor,
    const SkPixmap& srcPixmap)
{
    SkISize dimensions = srcPixmap.info().dimensions();
    const SkImageInfo& srcImageInfo = srcPixmap.info();

    SkMatrix adjustedInverse = inverse;
    if (filterQuality == kNone_SkFilterQuality) {
        if (inverse.getScaleX() >= 0.0f) {
            adjustedInverse.setTranslateX(
                nextafterf(inverse.getTranslateX(), std::floor(inverse.getTranslateX())));
        }
        if (inverse.getScaleY() >= 0.0f) {
            adjustedInverse.setTranslateY(
                nextafterf(inverse.getTranslateY(), std::floor(inverse.getTranslateY())));
        }
    }

    SkScalar dx = adjustedInverse.getScaleX();

    // If it is an index 8 color type, the sampler converts to unpremul for better fidelity.
    SkAlphaType alphaType = srcImageInfo.alphaType();
    if (srcPixmap.colorType() == kIndex_8_SkColorType) {
        alphaType = kUnpremul_SkAlphaType;
    }

    float postAlpha = SkColorGetA(paintColor) * (1.0f / 255.0f);
    // As the stages are built, the chooser function may skip a stage. For example, with the
    // identity matrix, the matrix stage is skipped, and the tilerStage is the first stage.
    auto blenderStage = choose_blender_for_shading(alphaType, postAlpha, &fBlenderStage);
    auto samplerStage = choose_pixel_sampler(
        blenderStage, filterQuality, xTile, yTile,
        srcPixmap, paintColor, &fSampleStage, &fAccessor);
    auto tilerStage   = choose_tiler(samplerStage, dimensions, xTile, yTile,
                                     filterQuality, dx, &fTileStage);
    fFirstStage       = choose_matrix(tilerStage, adjustedInverse, &fMatrixStage);
    fLastStage        = blenderStage;
}
Ejemplo n.º 9
0
int main(int npar, char * []) {

  constexpr auto maxf = std::numeric_limits<float>::max();
  

  float a = 100.f+3.f/7.f;
  float b = 4.f/7.f;
  if (npar>2) b=nextafterf(b,-maxf);


  float s =a+b;
  float z = s-a;
  float t = b-z;
  
  printf("a=%g b=%g s=%g z=%g t=%g\n",a,b,s,z,t);
  printf("a=%a b=%a s=%a z=%a t=%a\n",a,b,s,z,t);
  printf("nextafterf(s,maxf) =  %g %a\n",nextafterf(s,maxf),nextafterf(s,maxf));
  printf("nextafterf(s,maxf)-s = %g %a\n\n\n",nextafterf(s,maxf)-s,nextafterf(s,maxf)-s);

  return 0;

}
Ejemplo n.º 10
0
int
main(int argc, char *argv[])
{
    assert(test(nextafter(0.0, 0.0), 0.0));
    assert(test(nextafter(-0.0, 0.0), 0.0));
    assert(test(nextafter(0.0, -0.0), -0.0));
    assert(test(nextafter(-0.0, -0.0), -0.0));

    assert(test(nextafterf(0.0F, 0.0F), 0.0F));
    assert(test(nextafterf(-0.0F, 0.0F), 0.0F));
    assert(test(nextafterf(0.0F, -0.0F), -0.0F));
    assert(test(nextafterf(-0.0F, -0.0F), -0.0F));

    assert(test(nextafterl(0.0L, 0.0L), 0.0L));
    assert(test(nextafterl(-0.0L, 0.0L), 0.0L));
    assert(test(nextafterl(0.0L, -0.0L), -0.0L));
    assert(test(nextafterf(-0.0L, -0.0L), -0.0L));

    assert(test(nextafter(NAN, 1.0), NAN));
    assert(test(nextafter(1.0, NAN), NAN));
    assert(test(nextafter(NAN, NAN), NAN));

    assert(test(nextafterf(NAN, 1.0F), NAN));
    assert(test(nextafterf(1.0F, NAN), NAN));
    assert(test(nextafterf(NAN, NAN), NAN));

    assert(test(nextafterl(NAN, 1.0L), NAN));
    assert(test(nextafterl(1.0L, NAN), NAN));
    assert(test(nextafterl(NAN, NAN), NAN));

    assert(test(nextafter(0x1.fffffffffffffp+0, INFINITY), 0x1p1));
    assert(test(nextafter(0x1p1, -INFINITY), 0x1.fffffffffffffp+0));

    assert(test(nextafterf(0x1.fffffep+0f, INFINITY), 0x1p1f));
    assert(test(nextafterf(0x1p1f, -INFINITY), 0x1.fffffep+0f));

    return (0);
}
Ejemplo n.º 11
0
int
main(int argc, char *argv[])
{

	printf("1..12\n");

	testall(1, 1.0, 0.0);
	testall(2, 42.0, nextafterf(42.0, -INFINITY));
	testall(3, nextafterf(42.0, INFINITY), 42.0);
	testall(4, -5.0, -5.0);
	testall(5, -3.0, -4.0);
	testall(6, 1.0, NAN);
	testall(7, INFINITY, NAN);
	testall(8, INFINITY, 1.0);
	testall(9, -3.0, -INFINITY);
	testall(10, 3.0, -INFINITY);
	testall(11, NAN, NAN);

	/* This test isn't strictly required to work by C99. */
	testall(12, 0.0, -0.0);

	return (0);
}
Ejemplo n.º 12
0
Archivo: main.cpp Proyecto: CCJY/coliru
int main()
{
    float from1 = 0, to1 = nextafterf(0, 1);
    printf("The next representable float after %.2f (%a) is %.20g (%a)\n",
           from1, from1, to1, to1);
 
    float from2 = 1, to2 = nextafterf(1, 2);
    printf("The next representable float after %.2f (%a) is %.23f (%a)\n",
           from2, from2, to2, to2);
 
    double from3 = nextafter(0.1, 0), to3 = 0.1;
    printf("The number 0.1 lies between two valid doubles:\n    %.56f (%a)\nand %.55f  (%a)\n",
           from3, from3, to3, to3);
 
    {
        #pragma STDC FENV_ACCESS ON
        feclearexcept(FE_ALL_EXCEPT);
        double from4 = DBL_MAX, to4 = nextafter(DBL_MAX, INFINITY);
        printf("The next representable double after %.2g (%a) is %.23f (%a)\n",
               from4, from4, to4, to4);
        if(fetestexcept(FE_OVERFLOW)) puts("   raised FE_OVERFLOW");
        if(fetestexcept(FE_INEXACT)) puts("   raised FE_INEXACT");
    } // end FENV_ACCESS block
}
void gesture_maker_multipart_timings(t_gesture_multipart *x, long argc, t_atom *argv)
{
	long num_splits;
	double *split_points = x->split_points;
	
	if (argc > MAX_NUM_SPLITS)
		argc = MAX_NUM_SPLITS;
	
	num_splits = argc;
	
	while (argc--)
		*split_points++ = nextafterf(atom_getfloat(argv++), -1.);		// There may be a better way to do this that brings us closer to the desired value

	x->num_splits = num_splits;
	x->force_output = true;
}
Ejemplo n.º 14
0
int main(int argc, char **argv)
{
        int cnt, i;
        float a, b;
        cnt = atoi(argv[1]);
        a = strtod(argv[2], NULL);
        b = strtod(argv[3], NULL);
        while (cnt-- > 0) {
                for (i = 0; i < sizeof(a); i++) {
                        unsigned char c = ((char*)(&a))[i];
                        printf("%x%x", (c >> 4), (c & 0xf));
                }
                printf(" %f\n", a);
                a = nextafterf(a, b);
        }
        return 0;
}
Ejemplo n.º 15
0
Color Color::dark() const
{
    // Hardcode this common case for speed.
    if (m_color == white)
        return darkenedWhite;

    const float scaleFactor = nextafterf(256.0f, 0.0f);

    float r, g, b, a;
    getRGBA(r, g, b, a);

    float v = std::max(r, std::max(g, b));
    float multiplier = std::max(0.0f, (v - 0.33f) / v);

    return Color(static_cast<int>(multiplier * r * scaleFactor),
                 static_cast<int>(multiplier * g * scaleFactor),
                 static_cast<int>(multiplier * b * scaleFactor),
                 alpha());
}
Ejemplo n.º 16
0
void d8_flats_alter_dem(
  const int_2d &flat_mask,
  const int_2d &labels,
  array2d<U> &elevations
){
  ProgressBar progress;

  diagnostic("%%Calculating D8 flow directions using flat mask...\n");
  progress.start( flat_mask.width()*flat_mask.height() );
  #pragma omp parallel for
  for(int x=1;x<flat_mask.width()-1;x++){
    progress.update( x*flat_mask.height() );
    for(int y=1;y<flat_mask.height()-1;y++){
      if(labels(x,y)==0)
        continue;

      bool higher[9];
      for(int n=1;n<=8;++n)
        higher[n]=elevations(x,y)>elevations(x+dx[n],y+dy[n]);
      //TODO: nextafterf is the floating point version; should use an
      //overloaded version instead to be able to handle both double and float
      for(int i=0;i<flat_mask(x,y);++i)
        elevations(x,y)=nextafterf(elevations(x,y),std::numeric_limits<U>::infinity());
      for(int n=1;n<=8;++n){
        int nx=x+dx[n];
        int ny=y+dy[n];      
        if(labels(nx,ny)==labels(x,y))
          continue;
        if(elevations(x,y)<elevations(nx,ny))
          continue;
        if(!higher[n])
          diagnostic_arg("Attempting to raise (%d,%d) resulted in an invalid alteration of the DEM!\n",x,y);
      }
    }
  }
  diagnostic_arg(SUCCEEDED_IN,progress.stop());
}
Ejemplo n.º 17
0
int main(int argc, char *argv[])
{
	int i;
	float f;
	double d;
	long double ld;
	char *eptr;

	for (i = 1; i < argc; i++) {
		errno = 0;
		f = strtof(argv[i], &eptr);
		f = nextafterf(f, INFINITY);
		printf("%a  (*eptr:%d errno:%d)\n", f, *eptr, errno);
		errno = 0;
		d = strtod(argv[i], &eptr);
		d = nextafter(d, INFINITY);
		printf("%a  (*eptr:%d errno:%d)\n", d, *eptr, errno);
		errno = 0;
		ld = strtold(argv[i], &eptr);
		ld = nextafterl(ld, INFINITY);
		printf("%La  (*eptr:%d errno:%d)\n", ld, *eptr, errno);
	}
	return 0;
}
Ejemplo n.º 18
0
int main(){
  float a = 1.0f, b = 1.0f, c = 1.0f;
  int i = 0;
  FILE *fh;
  fh = fopen("r.txt", "w");
 
  if(fh == NULL){
    return 0;
  }
  
  //degenerate case: a = point; b = point; c = interval;
  float prev_sr = 0.0f, prev_sl = 0.0f;
  while(c <= 1.1){
    float sr = sum3_right_asso(a, b, c);
    float sl = sum3_left_asso(a, b, c);
    //	if(sl != sr){
    fprintf(fh, "%d %.17f %.17f\n", i++, sl, sr);
    //}
    c = nextafterf(c, 100);
  }
  /*
  while(a <= 10.1){
    while(b <= 1.1){
      while(c <= 1.1){
	float sr = sum3_right_asso(a, b, c);
	float sl = sum3_left_asso(a, b, c);
	//	if(sl != sr){
	fprintf(fh, "%d %.17f %.17f\n", i++, sl, sr);
	  //}
	c = nextafterf(c, 100);
      }
      b = nextafterf(b, 100);
    }
    a = nextafterf(a, 100);
    } */
}
Ejemplo n.º 19
0
Color Color::light() const
{
    // Hardcode this common case for speed.
    if (m_color == black)
        return lightenedBlack;

    const float scaleFactor = nextafterf(256.0f, 0.0f);

    float r, g, b, a;
    getRGBA(r, g, b, a);

    float v = std::max(r, std::max(g, b));

    if (v == 0.0f)
        // Lightened black with alpha.
        return Color(0x54, 0x54, 0x54, alpha());

    float multiplier = std::min(1.0f, v + 0.33f) / v;

    return Color(static_cast<int>(multiplier * r * scaleFactor),
                 static_cast<int>(multiplier * g * scaleFactor),
                 static_cast<int>(multiplier * b * scaleFactor),
                 alpha());
}
Ejemplo n.º 20
0
_f_real4
_NEAREST_4_8(_f_real4 x, _f_real8 s)
{
#ifdef KEY /* Bug 10771 */
   if (s == (_f_real8) 0.0) {
	   _lerror (_LELVL_ABORT, FENEARZS);
   }
  _f_int4 infinity =
    signbit(s) ? (0x80000000 | IEEE_32_INFINITY) : IEEE_32_INFINITY;
  _f_real4 result = nextafterf(x, * (_f_real4 *) &infinity);
  return result;
#elif 0 /* KEY Bug 3399 */
	/* See comment in _NEAREST_4 */
	REGISTER_4 x_reg;
	int positive_s = (s > (_f_real8) 0.0);

	if (s == (_f_real8) 0.0) {
		_lerror (_LELVL_ABORT, FENEARZS);
	}

	x_reg.f = x;

	if (IEEE_32_EXPO_ALL_ONES(x_reg.ui)) {
		return x;
	}

	if (x == (_f_real4) 0.0) { /* either +0.0 or -0.0 */
		x_reg.ui = positive_s ? 1 : (IEEE_32_SIGN_BIT | 1);
	} else {
		int increment = (positive_s == (x > (_f_real4) 0.0)) ? 1 : -1;
		x_reg.ui += increment;
	}

	return x_reg.f;
#else
	REGISTER_4 s1, s2, s3;
	s1.f = x;
	if (s == 0.0) {
		_lerror (_LELVL_ABORT, FENEARZS);
	}
#if defined (_CRAY1) && defined(_CRAYIEEE)
	s3.ui = s1.ui & ~(IEEE_64_SIGN_BIT);
	s2.ui = (s1.f > 0) ? LL_CONST(0x20000000) : -(LL_CONST(0x20000000));
	if ((_f_real4) TINY_REAL4_F90 > s3.f)
		s1.f = 0.0;
#else
	s2.ui = (s1.f > 0) ? 0x1 : -(0x1);
#endif
	if (s1.f == 0.0) {
		s1.f = (s > 0.0) ?
			(_f_real4) TINY_REAL4_F90 : (_f_real4) -TINY_REAL4_F90;
	} else if (s > 0.0) {
		s1.ui += s2.ui;
	} else {
		s1.ui -= s2.ui;
	}
#if defined (_CRAY1) && defined(_CRAYIEEE)
	if (isnormal64(s1.ui))
#else
	if (isnormal32(s1.ui))
#endif
		return s1.f;
	if (x > 1.0 || x < -1.0)
		return s1.f;
	return (0.0);
#endif /* KEY */
}
Ejemplo n.º 21
0
int main() {

  // c++  -std=gnu++11 round.cpp -frounding-math
  #pragma STDC FENV_ACCESS ON 

  // fesetround(FE_DOWNWARD);
  // fesetround(FE_UPWARD);
  
  constexpr auto maxf = std::numeric_limits<float>::max();
  


  float a=0.1f;
  float a1=nextafterf(a,-maxf);
  float a2=nextafterf(a,maxf);
  float b1=0x1.8p-4;   // 0x2.0p-4;
  float b2=0x1.9p-4;   // 0x2.0p-4;
  float b3=0x1.ap-4;   // 0x2.0p-4;

  float s0=0., s1=0., s2=0., s3=0.;

  for (int i=0; i!=1000000; ++i) {
    s0+=a; s1+=b1; s2+=b2;s3+=b3;
  }

  printf("%g %a\n",a,a);
  printf("%g %a\n",a1,a1);
  printf("%g %a\n\n",a2,a2);
  printf("%g %a\n",2*a,2*a);
  printf("%g %a\n",3*a,3*a);
  printf("%g %a\n",4*a,4*a);
  printf("%g %a\n",5*a,5*a);
  printf("%g %a\n\n",6*a,6*a);
  printf("%g %a\n",3*a+a,3*a+a);
  printf("%g %a\n\n",5*a+a,5*a+a);
  printf("%g %a\n",0.9f,0.9f);
  printf("%g %a\n",0.6f,0.6f);
  printf("%g %a\n",0.3f,0.3f);
  printf("%g %a\n",0.9f-0.6f,0.9f-0.6f);
  printf("%g %a\n",0.9f/3.f,0.9f/3.f);
  printf("%g %a\n",0.6f/2.f,0.6f/2.f);
  printf("%g %a\n",0.9f*(1.f/3.f),0.9f*(1.f/3.f));
  printf("%g %a\n\n",0.6f*0.5f,0.6f*0.5f);

  printf("%g %a\n",b1,b1);
  printf("%g %a\n",b2,b2);
  printf("%g %a\n\n",b3,b3);


  printf("%g %a\n",s0,s0);
  printf("%g %a\n",s1,s1);
  printf("%g %a\n",s2,s2);
  printf("%g %a\n\n\n",s3,s3);


  //  float x = 0x1.000002p-1;
  //float x = 0x1.000004p-1;
  float x = 0x1.000006p-1;
  printf("x   %g %a\n",x,x);
  printf("x+x %g %a\n",x+x,x+x);
  float y=x;
  for (int i=0; i<5; i++) {
    y*=2;
    float z = y+x;
    double d = double(y)+double(x);
    printf("y %g %a\n",y,y);
    printf("y+x %g %a\n",z,z);
    printf("y+x %g %a\n",d,d);
    printf("y+x %g %a\n",float(d),float(d));
  }



  return 0;
}
Ejemplo n.º 22
0
float nexttowardf(float f, long double td) {
  return nextafterf(f, (float)td);
}
Ejemplo n.º 23
0
float npy_nextafterf(float x, float y)
{
    return nextafterf(x, y);
}
Ejemplo n.º 24
0
int main(int argc, char *argv[])
{
  float x = 0.0;
  if (argv) x = nextafterf((float) argc, (float) argc);
  return 0;
}
Ejemplo n.º 25
0
int
main(int argc, char *argv[])
{
	static const int ex_under = FE_UNDERFLOW | FE_INEXACT;	/* shorthand */
	static const int ex_over = FE_OVERFLOW | FE_INEXACT;
	long double ldbl_small, ldbl_eps, ldbl_max;

	printf("1..5\n");

#ifdef	__i386__
	fpsetprec(FP_PE);
#endif
	/*
	 * We can't use a compile-time constant here because gcc on
	 * FreeBSD/i386 assumes long doubles are truncated to the
	 * double format.
	 */
	ldbl_small = ldexpl(1.0, LDBL_MIN_EXP - LDBL_MANT_DIG);
	ldbl_eps = LDBL_EPSILON;
	ldbl_max = ldexpl(1.0 - ldbl_eps / 2, LDBL_MAX_EXP);

	/*
	 * Special cases involving zeroes.
	 */
#define	ztest(prec)							      \
	test##prec(copysign##prec(1.0, nextafter##prec(0.0, -0.0)), -1.0, 0); \
	test##prec(copysign##prec(1.0, nextafter##prec(-0.0, 0.0)), 1.0, 0);  \
	test##prec(copysign##prec(1.0, nexttoward##prec(0.0, -0.0)), -1.0, 0);\
	test##prec(copysign##prec(1.0, nexttoward##prec(-0.0, 0.0)), 1.0, 0)

	ztest();
	ztest(f);
	ztest(l);
#undef	ztest

#define	stest(next, eps, prec)					\
	test##prec(next(-0.0, 42.0), eps, ex_under);		\
	test##prec(next(0.0, -42.0), -eps, ex_under);		\
	test##prec(next(0.0, INFINITY), eps, ex_under);		\
	test##prec(next(-0.0, -INFINITY), -eps, ex_under)

	stest(nextafter, 0x1p-1074, );
	stest(nextafterf, 0x1p-149f, f);
	stest(nextafterl, ldbl_small, l);
	stest(nexttoward, 0x1p-1074, );
	stest(nexttowardf, 0x1p-149f, f);
	stest(nexttowardl, ldbl_small, l);
#undef	stest

	printf("ok 1 - next\n");

	/*
	 * `x == y' and NaN tests
	 */
	testall(42.0, 42.0, 42.0, 0);
	testall(-42.0, -42.0, -42.0, 0);
	testall(INFINITY, INFINITY, INFINITY, 0);
	testall(-INFINITY, -INFINITY, -INFINITY, 0);
	testall(NAN, 42.0, NAN, 0);
	testall(42.0, NAN, NAN, 0);
	testall(NAN, NAN, NAN, 0);

	printf("ok 2 - next\n");

	/*
	 * Tests where x is an ordinary normalized number
	 */
	testboth(1.0, 2.0, 1.0 + DBL_EPSILON, 0, );
	testboth(1.0, -INFINITY, 1.0 - DBL_EPSILON/2, 0, );
	testboth(1.0, 2.0, 1.0 + FLT_EPSILON, 0, f);
	testboth(1.0, -INFINITY, 1.0 - FLT_EPSILON/2, 0, f);
	testboth(1.0, 2.0, 1.0 + ldbl_eps, 0, l);
	testboth(1.0, -INFINITY, 1.0 - ldbl_eps/2, 0, l);

	testboth(-1.0, 2.0, -1.0 + DBL_EPSILON/2, 0, );
	testboth(-1.0, -INFINITY, -1.0 - DBL_EPSILON, 0, );
	testboth(-1.0, 2.0, -1.0 + FLT_EPSILON/2, 0, f);
	testboth(-1.0, -INFINITY, -1.0 - FLT_EPSILON, 0, f);
	testboth(-1.0, 2.0, -1.0 + ldbl_eps/2, 0, l);
	testboth(-1.0, -INFINITY, -1.0 - ldbl_eps, 0, l);

	/* Cases where nextafter(...) != nexttoward(...) */
	test(nexttoward(1.0, 1.0 + ldbl_eps), 1.0 + DBL_EPSILON, 0);
	testf(nexttowardf(1.0, 1.0 + ldbl_eps), 1.0 + FLT_EPSILON, 0);
	testl(nexttowardl(1.0, 1.0 + ldbl_eps), 1.0 + ldbl_eps, 0);

	printf("ok 3 - next\n");

	/*
	 * Tests at word boundaries, normalization boundaries, etc.
	 */
	testboth(0x1.87654ffffffffp+0, INFINITY, 0x1.87655p+0, 0, );
	testboth(0x1.87655p+0, -INFINITY, 0x1.87654ffffffffp+0, 0, );
	testboth(0x1.fffffffffffffp+0, INFINITY, 0x1p1, 0, );
	testboth(0x1p1, -INFINITY, 0x1.fffffffffffffp+0, 0, );
	testboth(0x0.fffffffffffffp-1022, INFINITY, 0x1p-1022, 0, );
	testboth(0x1p-1022, -INFINITY, 0x0.fffffffffffffp-1022, ex_under, );

	testboth(0x1.fffffep0f, INFINITY, 0x1p1, 0, f);
	testboth(0x1p1, -INFINITY, 0x1.fffffep0f, 0, f);
	testboth(0x0.fffffep-126f, INFINITY, 0x1p-126f, 0, f);
	testboth(0x1p-126f, -INFINITY, 0x0.fffffep-126f, ex_under, f);

#if LDBL_MANT_DIG == 53
	testboth(0x1.87654ffffffffp+0L, INFINITY, 0x1.87655p+0L, 0, l);
	testboth(0x1.87655p+0L, -INFINITY, 0x1.87654ffffffffp+0L, 0, l);
	testboth(0x1.fffffffffffffp+0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.fffffffffffffp+0L, 0, l);
	testboth(0x0.fffffffffffffp-1022L, INFINITY, 0x1p-1022L, 0, l);
	testboth(0x1p-1022L, -INFINITY, 0x0.fffffffffffffp-1022L, ex_under, l);
#elif LDBL_MANT_DIG == 64 && !defined(__i386)
	testboth(0x1.87654321fffffffep+0L, INFINITY, 0x1.87654322p+0L, 0, l);
	testboth(0x1.87654322p+0L, -INFINITY, 0x1.87654321fffffffep+0L, 0, l);
	testboth(0x1.fffffffffffffffep0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.fffffffffffffffep0L, 0, l);
	testboth(0x0.fffffffffffffffep-16382L, INFINITY, 0x1p-16382L, 0, l);
	testboth(0x1p-16382L, -INFINITY,
	    0x0.fffffffffffffffep-16382L, ex_under, l);
#elif LDBL_MANT_DIG == 113
	testboth(0x1.876543210987ffffffffffffffffp+0L, INFINITY,
	    0x1.876543210988p+0, 0, l);
	testboth(0x1.876543210988p+0L, -INFINITY,
	    0x1.876543210987ffffffffffffffffp+0L, 0, l);
	testboth(0x1.ffffffffffffffffffffffffffffp0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.ffffffffffffffffffffffffffffp0L, 0, l);
	testboth(0x0.ffffffffffffffffffffffffffffp-16382L, INFINITY,
	    0x1p-16382L, 0, l);
	testboth(0x1p-16382L, -INFINITY,
	    0x0.ffffffffffffffffffffffffffffp-16382L, ex_under, l);
#endif

	printf("ok 4 - next\n");

	/*
	 * Overflow tests
	 */
	test(idd(nextafter(DBL_MAX, INFINITY)), INFINITY, ex_over);
	test(idd(nextafter(INFINITY, 0.0)), DBL_MAX, 0);
	test(idd(nexttoward(DBL_MAX, DBL_MAX * 2.0L)), INFINITY, ex_over);
#if LDBL_MANT_DIG > 53
	test(idd(nexttoward(INFINITY, DBL_MAX * 2.0L)), DBL_MAX, 0);
#endif

	testf(idf(nextafterf(FLT_MAX, INFINITY)), INFINITY, ex_over);
	testf(idf(nextafterf(INFINITY, 0.0)), FLT_MAX, 0);
	testf(idf(nexttowardf(FLT_MAX, FLT_MAX * 2.0)), INFINITY, ex_over);
	testf(idf(nexttowardf(INFINITY, FLT_MAX * 2.0)), FLT_MAX, 0);

	testboth(ldbl_max, INFINITY, INFINITY, ex_over, l);
	testboth(INFINITY, 0.0, ldbl_max, 0, l);

	printf("ok 5 - next\n");

	return (0);
}
Ejemplo n.º 26
0
int
main (void)
{
  int result = 0;

  float i = INFINITY;
  float m = FLT_MAX;
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafterf (m, i) != i)
    {
      puts ("nextafterf+ failed");
      ++result;
    }
  if (fetestexcept (FE_OVERFLOW) == 0)
    {
      puts ("nextafterf+ did not overflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafterf (-m, -i) != -i)
    {
      puts ("nextafterf- failed");
      ++result;
    }
  if (fetestexcept (FE_OVERFLOW) == 0)
    {
      puts ("nextafterf- did not overflow");
      ++result;
    }

  i = 0;
  m = FLT_MIN;
  feclearexcept (FE_ALL_EXCEPT);
  i = nextafterf (m, i);
  if (i < 0 || i >= FLT_MIN)
    {
      puts ("nextafterf+ failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterf+ did not underflow");
      ++result;
    }
  i = 0;
  feclearexcept (FE_ALL_EXCEPT);
  i = nextafterf (-m, -i);
  if (i > 0 || i <= -FLT_MIN)
    {
      puts ("nextafterf- failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterf- did not underflow");
      ++result;
    }
  i = -INFINITY;
  feclearexcept (FE_ALL_EXCEPT);
  m = nextafterf (zero, inf);
  if (m < 0.0 || m >= FLT_MIN)
    {
      puts ("nextafterf+ failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterf+ did not underflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafterf (m, i) != 0.0)
    {
      puts ("nextafterf+ failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterf+ did not underflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  m = nextafterf (copysignf (zero, -1.0), -inf);
  if (m > 0.0 || m <= -FLT_MIN)
    {
      puts ("nextafterf- failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterf- did not underflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafterf (m, -i) != 0.0)
    {
      puts ("nextafterf- failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterf- did not underflow");
      ++result;
    }

  double di = INFINITY;
  double dm = DBL_MAX;
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafter (dm, di) != di)
    {
      puts ("nextafter+ failed");
      ++result;
    }
  if (fetestexcept (FE_OVERFLOW) == 0)
    {
      puts ("nextafter+ did not overflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafter (-dm, -di) != -di)
    {
      puts ("nextafter failed");
      ++result;
    }
  if (fetestexcept (FE_OVERFLOW) == 0)
    {
      puts ("nextafter- did not overflow");
      ++result;
    }

  di = 0;
  dm = DBL_MIN;
  feclearexcept (FE_ALL_EXCEPT);
  di = nextafter (dm, di);
  if (di < 0 || di >= DBL_MIN)
    {
      puts ("nextafter+ failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafter+ did not underflow");
      ++result;
    }
  di = 0;
  feclearexcept (FE_ALL_EXCEPT);
  di = nextafter (-dm, -di);
  if (di > 0 || di <= -DBL_MIN)
    {
      puts ("nextafter- failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafter- did not underflow");
      ++result;
    }
  di = -INFINITY;
  feclearexcept (FE_ALL_EXCEPT);
  dm = nextafter (zero, inf);
  if (dm < 0.0 || dm >= DBL_MIN)
    {
      puts ("nextafter+ failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafter+ did not underflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafter (dm, di) != 0.0)
    {
      puts ("nextafter+ failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafter+ did not underflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  dm = nextafter (copysign (zero, -1.0), -inf);
  if (dm > 0.0 || dm <= -DBL_MIN)
    {
      puts ("nextafter- failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafter- did not underflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafter (dm, -di) != 0.0)
    {
      puts ("nextafter- failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafter- did not underflow");
      ++result;
    }

#ifndef NO_LONG_DOUBLE
  long double li = INFINITY;
  long double lm = LDBL_MAX;
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafterl (lm, li) != li)
    {
      puts ("nextafterl+ failed");
      ++result;
    }
  if (fetestexcept (FE_OVERFLOW) == 0)
    {
      puts ("nextafterl+ did not overflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafterl (-lm, -li) != -li)
    {
      puts ("nextafterl failed");
      ++result;
    }
  if (fetestexcept (FE_OVERFLOW) == 0)
    {
      puts ("nextafterl- did not overflow");
      ++result;
    }

  li = 0;
  lm = LDBL_MIN;
  feclearexcept (FE_ALL_EXCEPT);
  li = nextafterl (lm, li);
  if (li < 0 || li >= LDBL_MIN)
    {
      puts ("nextafterl+ failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterl+ did not underflow");
      ++result;
    }
  li = 0;
  feclearexcept (FE_ALL_EXCEPT);
  li = nextafterl (-lm, -li);
  if (li > 0 || li <= -LDBL_MIN)
    {
      puts ("nextafterl- failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterl- did not underflow");
      ++result;
    }
  li = -INFINITY;
  feclearexcept (FE_ALL_EXCEPT);
  lm = nextafterl (zero, inf);
  if (lm < 0.0 || lm >= LDBL_MIN)
    {
      puts ("nextafterl+ failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterl+ did not underflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafterl (lm, li) != 0.0)
    {
      puts ("nextafterl+ failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterl+ did not underflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  lm = nextafterl (copysign (zero, -1.0), -inf);
  if (lm > 0.0 || lm <= -LDBL_MIN)
    {
      puts ("nextafterl- failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterl- did not underflow");
      ++result;
    }
  feclearexcept (FE_ALL_EXCEPT);
  if (nextafterl (lm, -li) != 0.0)
    {
      puts ("nextafterl- failed");
      ++result;
    }
  if (fetestexcept (FE_UNDERFLOW) == 0)
    {
      puts ("nextafterl- did not underflow");
      ++result;
    }
#endif

  return result;
}
__attribute__((weak)) float nexttowardf(float f, long double td) {
  return nextafterf(f, (float)td);
}
Ejemplo n.º 28
0
/* NEAREST - return the nearest different machine representable number in a 
 * 		given direction s for 32-bit and 64-bit values.  Returns
 * 		the argument x if s = zero.  The result is undefined in f90
 * 		when s = zero.
 */
_f_real4
_NEAREST_4(_f_real4 x, _f_real4 s)
{
#ifdef KEY /* Bug 10771 */
  /* Previous approach (in "elif") didn't treat infinity correctly and didn't
   * signal exceptions correctly. Let's try using the C library functions in
   * hopes that they know what they're doing.
   */
   if (s == (_f_real4) 0.0) {
	   _lerror (_LELVL_ABORT, FENEARZS);
   }
  _f_int4 infinity =
    signbit(s) ? (0x80000000 | IEEE_32_INFINITY) : IEEE_32_INFINITY;
  _f_real4 result = nextafterf(x, * (_f_real4 *) &infinity);
  return result;
#elif 0 /* KEY Bug 3399 */
	/*
	 * We want "nearest(nearest(x, s), -s) == x" to be true so long as
	 * IEEE infinity and NaN aren't involved. We do allow largest/smallest
	 * number to turn into infinity, but we don't allowe infinity to turn
	 * back into largest/smallest number.
	 *
	 * Here's a summary of the unsigned bit patterns for IEEE floating
	 * point:
	 *
	 * 1 11-11 11------11	"Largest magnitude negative" NaN
	 * 1 11-11 00------01	"Smallest magnitude negative" NaN
	 * 1 11-11 00------00	Negative infinity
	 * 1 11-10 11------11	Largest-magnitude negative normalized
	 * 1 00-01 00------00	Smallest-magnitude negative normalized
	 * 1 00-00 11------11	Largest-magnitude negative denorm
	 * 1 00-00 00------01	Smallest-magnitude negative denorm
	 * 1 00-00 00------00	Negative zero
	 * 0 11-11 11------11	"Largest positive" NaN
	 * 0 11-11 00------01	"Smallest positive" NaN
	 * 0 11-11 00------00   Positive infinity
	 * 0 11-10 11------11	Largest-magnitude positive normalized
	 * 0 00-01 00------00	Smallest-magnitude positive normalized
	 * 0 00-00 11------11	Largest-magnitude positive denorm
	 * 0 00-00 00------01   Smallest-magnitude positive denorm
	 * 0 00-00 00------00	Zero
	 *
	 * Our strategy is:
	 * 1. s == 0 is a fatal error
	 * 2. if x == infinity or NaN, return it unchanged
	 * 3. if x == +0 or -0, return smallest-magnitude denorm whose sign
	 *    matches that of s
	 * 4. if the signs of x and s match, add 1 to bit pattern of x
	 *    (increasing its floating-point magnitude); else subtract 1 from
	 *    bit pattern of x (decreasing its magnitude)
	 */
	REGISTER_4 x_reg;
	int positive_s = (s > (_f_real4) 0.0);

	if (s == (_f_real4) 0.0) {
		_lerror (_LELVL_ABORT, FENEARZS);
	}

	x_reg.f = x;

	if (IEEE_32_EXPO_ALL_ONES(x_reg.ui)) {
		return x;
	}

	if (x == (_f_real4) 0.0) { /* either +0.0 or -0.0 */
		x_reg.ui = positive_s ? 1 : (IEEE_32_SIGN_BIT | 1);
	} else {
		int increment = (positive_s == (x > (_f_real4) 0.0)) ? 1 : -1;
		x_reg.ui += increment;
	}

	return x_reg.f;
#else
	REGISTER_4 s1, s2, s3;
	s1.f = x;
	if (s == (_f_real4) 0.0) {
		_lerror (_LELVL_ABORT, FENEARZS);
	}
#if defined (_CRAY1) && defined(_CRAYIEEE)
	s3.ui = s1.ui & ~(IEEE_64_SIGN_BIT);
	s2.ui = (s1.f > 0) ? LL_CONST(0x20000000) : -(LL_CONST(0x20000000));
	if ((_f_real4) TINY_REAL4_F90 > s3.f)
		s1.f = 0.0;
#else
	s2.ui = (s1.f > 0) ? 0x1 : -(0x1);
#endif
	if (s1.f == (_f_real4) 0.0) {
		s1.f = (s > (_f_real4) 0.0) ?
		   (_f_real4) TINY_REAL4_F90 : (_f_real4) -TINY_REAL4_F90;
	} else if (s > (_f_real4) 0.0) {
		s1.ui += s2.ui;
	} else {
		s1.ui -= s2.ui;
	}
#if defined (_CRAY1) && defined(_CRAYIEEE)
	if (isnormal64(s1.ui))
#else
	if (isnormal32(s1.ui))
#endif
		return s1.f;
	if (x > 1.0 || x < -1.0)
		return (s1.f);
	return (0.0);
#endif /* KEY */
}
Ejemplo n.º 29
0
float epsF(float x) {
   x = copysignf(x, 1.0);
   float y = nextafterf(x, INFINITY);
   return y-x;
}
Ejemplo n.º 30
0
// FIXME: Generate this function.
void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, StyleResolverState& state, const AnimatableValue* value)
{
    ASSERT(CSSPropertyMetadata::isAnimatableProperty(property));
    if (value->isUnknown()) {
        StyleBuilder::applyProperty(property, state, toAnimatableUnknown(value)->toCSSValue().get());
        return;
    }
    RenderStyle* style = state.style();
    switch (property) {
    case CSSPropertyBackgroundColor:
        style->setBackgroundColor(toAnimatableColor(value)->color());
        return;
    case CSSPropertyBackgroundImage:
        setOnFillLayers<CSSPropertyBackgroundImage>(style->accessBackgroundLayers(), value, state);
        return;
    case CSSPropertyBackgroundPositionX:
        setOnFillLayers<CSSPropertyBackgroundPositionX>(style->accessBackgroundLayers(), value, state);
        return;
    case CSSPropertyBackgroundPositionY:
        setOnFillLayers<CSSPropertyBackgroundPositionY>(style->accessBackgroundLayers(), value, state);
        return;
    case CSSPropertyBackgroundSize:
        setOnFillLayers<CSSPropertyBackgroundSize>(style->accessBackgroundLayers(), value, state);
        return;
    case CSSPropertyBorderBottomColor:
        style->setBorderBottomColor(toAnimatableColor(value)->color());
        return;
    case CSSPropertyBorderBottomLeftRadius:
        style->setBorderBottomLeftRadius(animatableValueToLengthSize(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyBorderBottomRightRadius:
        style->setBorderBottomRightRadius(animatableValueToLengthSize(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyBorderBottomWidth:
        style->setBorderBottomWidth(animatableValueRoundClampTo<unsigned>(value));
        return;
    case CSSPropertyBorderImageOutset:
        style->setBorderImageOutset(animatableValueToBorderImageLengthBox(value, state));
        return;
    case CSSPropertyBorderImageSlice:
        style->setBorderImageSlices(animatableValueToLengthBox(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyBorderImageSource:
        style->setBorderImageSource(state.styleImage(property, toAnimatableImage(value)->toCSSValue()));
        return;
    case CSSPropertyBorderImageWidth:
        style->setBorderImageWidth(animatableValueToBorderImageLengthBox(value, state));
        return;
    case CSSPropertyBorderLeftColor:
        style->setBorderLeftColor(toAnimatableColor(value)->color());
        return;
    case CSSPropertyBorderLeftWidth:
        style->setBorderLeftWidth(animatableValueRoundClampTo<unsigned>(value));
        return;
    case CSSPropertyBorderRightColor:
        style->setBorderRightColor(toAnimatableColor(value)->color());
        return;
    case CSSPropertyBorderRightWidth:
        style->setBorderRightWidth(animatableValueRoundClampTo<unsigned>(value));
        return;
    case CSSPropertyBorderTopColor:
        style->setBorderTopColor(toAnimatableColor(value)->color());
        return;
    case CSSPropertyBorderTopLeftRadius:
        style->setBorderTopLeftRadius(animatableValueToLengthSize(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyBorderTopRightRadius:
        style->setBorderTopRightRadius(animatableValueToLengthSize(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyBorderTopWidth:
        style->setBorderTopWidth(animatableValueRoundClampTo<unsigned>(value));
        return;
    case CSSPropertyBottom:
        style->setBottom(animatableValueToLength(value, state));
        return;
    case CSSPropertyBoxShadow:
    case CSSPropertyWebkitBoxShadow:
        style->setBoxShadow(toAnimatableShadow(value)->shadowList());
        return;
    case CSSPropertyClip:
        style->setClip(animatableValueToLengthBox(value, state));
        return;
    case CSSPropertyColor:
        style->setColor(toAnimatableColor(value)->color());
        return;
    case CSSPropertyFlexGrow:
        style->setFlexGrow(clampTo<float>(toAnimatableDouble(value)->toDouble(), 0));
        return;
    case CSSPropertyFlexShrink:
        style->setFlexShrink(clampTo<float>(toAnimatableDouble(value)->toDouble(), 0));
        return;
    case CSSPropertyFlexBasis:
        style->setFlexBasis(animatableValueToLength(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyFontSize:
        style->setFontSize(clampTo<float>(toAnimatableDouble(value)->toDouble(), 0));
        return;
    case CSSPropertyFontStretch:
        style->setFontStretch(animatableValueToFontStretch(value));
        return;
    case CSSPropertyFontWeight:
        style->setFontWeight(animatableValueToFontWeight(value));
        return;
    case CSSPropertyHeight:
        style->setHeight(animatableValueToLength(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyLeft:
        style->setLeft(animatableValueToLength(value, state));
        return;
    case CSSPropertyLineHeight:
        if (value->isLength())
            style->setLineHeight(animatableValueToLength(value, state, ValueRangeNonNegative));
        else
            style->setLineHeight(Length(clampTo<float>(toAnimatableDouble(value)->toDouble(), 0), Percent));
        return;
    case CSSPropertyLetterSpacing:
        style->setLetterSpacing(clampTo<float>(toAnimatableDouble(value)->toDouble()));
        return;
    case CSSPropertyMarginBottom:
        style->setMarginBottom(animatableValueToLength(value, state));
        return;
    case CSSPropertyMarginLeft:
        style->setMarginLeft(animatableValueToLength(value, state));
        return;
    case CSSPropertyMarginRight:
        style->setMarginRight(animatableValueToLength(value, state));
        return;
    case CSSPropertyMarginTop:
        style->setMarginTop(animatableValueToLength(value, state));
        return;
    case CSSPropertyMaxHeight:
        style->setMaxHeight(animatableValueToLength(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyMaxWidth:
        style->setMaxWidth(animatableValueToLength(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyMinHeight:
        style->setMinHeight(animatableValueToLength(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyMinWidth:
        style->setMinWidth(animatableValueToLength(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyObjectPosition:
        style->setObjectPosition(animatableValueToLengthPoint(value, state));
        return;
    case CSSPropertyOpacity:
        // Avoiding a value of 1 forces a layer to be created.
        style->setOpacity(clampTo<float>(toAnimatableDouble(value)->toDouble(), 0, nextafterf(1, 0)));
        return;
    case CSSPropertyOutlineColor:
        style->setOutlineColor(toAnimatableColor(value)->color());
        return;
    case CSSPropertyOutlineOffset:
        style->setOutlineOffset(animatableValueRoundClampTo<int>(value));
        return;
    case CSSPropertyOutlineWidth:
        style->setOutlineWidth(animatableValueRoundClampTo<unsigned short>(value));
        return;
    case CSSPropertyPaddingBottom:
        style->setPaddingBottom(animatableValueToLength(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyPaddingLeft:
        style->setPaddingLeft(animatableValueToLength(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyPaddingRight:
        style->setPaddingRight(animatableValueToLength(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyPaddingTop:
        style->setPaddingTop(animatableValueToLength(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyRight:
        style->setRight(animatableValueToLength(value, state));
        return;
    case CSSPropertyTextDecorationColor:
        style->setTextDecorationColor(toAnimatableColor(value)->color());
        return;
    case CSSPropertyTextIndent:
        style->setTextIndent(animatableValueToLength(value, state));
        return;
    case CSSPropertyTextShadow:
        style->setTextShadow(toAnimatableShadow(value)->shadowList());
        return;
    case CSSPropertyTop:
        style->setTop(animatableValueToLength(value, state));
        return;
    case CSSPropertyWebkitBackgroundSize:
        setOnFillLayers<CSSPropertyWebkitBackgroundSize>(style->accessBackgroundLayers(), value, state);
        return;
    case CSSPropertyWebkitBorderHorizontalSpacing:
        style->setHorizontalBorderSpacing(animatableValueRoundClampTo<unsigned short>(value));
        return;
    case CSSPropertyWebkitBorderVerticalSpacing:
        style->setVerticalBorderSpacing(animatableValueRoundClampTo<unsigned short>(value));
        return;
    case CSSPropertyWebkitClipPath:
        style->setClipPath(toAnimatableClipPathOperation(value)->clipPathOperation());
        return;
    case CSSPropertyFilter:
        style->setFilter(toAnimatableFilterOperations(value)->operations());
        return;
    case CSSPropertyPerspective:
        style->setPerspective(clampTo<float>(toAnimatableDouble(value)->toDouble()));
        return;
    case CSSPropertyPerspectiveOrigin: {
        const AnimatableLengthPoint* animatableLengthPoint = toAnimatableLengthPoint(value);
        style->setPerspectiveOriginX(animatableValueToLength(animatableLengthPoint->x(), state));
        style->setPerspectiveOriginY(animatableValueToLength(animatableLengthPoint->y(), state));
        return;
    }
    case CSSPropertyWebkitTextStrokeColor:
        style->setTextStrokeColor(toAnimatableColor(value)->color());
        return;
    case CSSPropertyTransform: {
        const TransformOperations& operations = toAnimatableTransform(value)->transformOperations();
        // FIXME: This normalization (handling of 'none') should be performed at input in AnimatableValueFactory.
        style->setTransform(operations.size() ? operations : TransformOperations(true));
        return;
    }
    case CSSPropertyTransformOrigin: {
        const AnimatableLengthPoint3D* animatableLengthPoint3D = toAnimatableLengthPoint3D(value);
        style->setTransformOriginX(animatableValueToLength(animatableLengthPoint3D->x(), state));
        style->setTransformOriginY(animatableValueToLength(animatableLengthPoint3D->y(), state));
        style->setTransformOriginZ(clampTo<float>(toAnimatableDouble(animatableLengthPoint3D->z())->toDouble()));
        return;
    }
    case CSSPropertyWidth:
        style->setWidth(animatableValueToLength(value, state, ValueRangeNonNegative));
        return;
    case CSSPropertyWordSpacing:
        style->setWordSpacing(clampTo<float>(toAnimatableDouble(value)->toDouble()));
        return;
    case CSSPropertyVerticalAlign:
        style->setVerticalAlignLength(animatableValueToLength(value, state));
        return;
    case CSSPropertyZIndex:
        style->setZIndex(animatableValueRoundClampTo<unsigned>(value));
        return;
    default:
        ASSERT_NOT_REACHED();
    }
}