static inline Math::Vector3<double> Vector3Orthonormalize(const double &eps, const Math::Vector3<double> &u, const Math::Vector3<double> &v) { Math::Vector3<double> p; double D = __builtin_sqrt(v.x * v.x + v.y * v.y + v.z * v.z); if( __builtin_fabs( D - 1.0 ) > eps ) { double N = u.x * v.x + u.y * v.y + u.z * v.z; double Q = N / D; p.x = u.x - Q * v.x; p.y = u.y - Q * v.y; p.z = u.z - Q * v.z; double L = 1.0 / __builtin_sqrt(p.x * p.x + p.y * p.y + p.z * p.z); p.x *= L; p.y *= L; p.z *= L; } // if return p; } // Vector3Orthonormalize
/* sqrt(x) < y is x >= 0 && x != +Inf, when y is large. */ double fn2 (void) { double r; r = __builtin_sqrt (E) < __builtin_inf (); return r; }
/* sqrt(x) < c is the same as x >= 0 && x < c*c. */ double fn3 (void) { double r; r = __builtin_sqrt (E) < 1.3; return r; }
double sqrt(double x) { #ifndef __clang__ return __builtin_sqrt(x); #else return 0.0f; #endif }
double foo (S *a1, S *a2) { return __builtin_sqrt ((a1->x - a2->x) * (a1->x - a2->x) + (a1->y - a2->y) * (a1->y - a2->y) + (a1->z - a2->z) * (a1->z - a2->z)); }
void test_double_sqrt (void) { int i; for (i = 0; i < SIZE; i++) d1[i] = __builtin_sqrt (d2[i]); }
void bar (S *p, S *q, S *r, double &x, double &y, double &z) { if (foo (p, q) == 0.0) { x = r->x; y = r->y; z = r->z; return; } if (foo (p, r) == 0.0) { x = r->x; y = r->y; z = r->z; return; } if (foo (q, r) == 0.0) { x = r->x; y = r->y; z = r->z; return; } double a1, b1, c1, d1, e1; double dx, dy, dz, dw, dv; a1 = q->x - p->x; b1 = q->y - p->y; c1 = q->z - p->z; e1 = __builtin_sqrt (a1 * a1 + b1 * b1 + c1 * c1); a1 = a1 / e1; b1 = b1 / e1; c1 = c1 / e1; dx = p->x - r->x; dy = p->y - r->y; dz = p->z - r->z; dw = dx * dx + dy * dy + dz * dz; dv = 2.0 * dx * a1 + 2.0 * dy * b1 + 2.0 * dz * c1; d1 = -dv / 2.0; x = p->x + (a1 * d1); y = p->y + (b1 * d1); z = p->z + (c1 * d1); return; }
static inline Math::Vector2<double> Vector2Normalize(const double eps, const Math::Vector2<double> &v) { Math::Vector2<double> p(v); double L = __builtin_sqrt(v.x * v.x + v.y * v.y); if( __builtin_fabs( L - 1.0 ) > eps ) { L = 1.0/L; p.x *= L; p.y *= L; } // if return p; } // Vector2Normalize
double __hide_ieee754_asin(double x) { double t=0.0,w,p,q,c,r,s; int hx,ix; hx = GET_HI(x); ix = hx&0x7fffffff; if(ix>= 0x3ff00000) { /* |x|>= 1 */ if(((ix-0x3ff00000)|GET_LO(x))==0) /* asin(1)=+-pi/2 with inexact */ return x*pio2_hi+x*pio2_lo; return __builtin_nan(""); /* asin(|x|>1) is NaN */ } else if (ix<0x3fe00000) { /* |x|<0.5 */ if(ix<0x3e400000) { /* if |x| < 2**-27 */ if(huge+x>one) return x;/* return x with inexact if x!=0*/ } else t = x*x; p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); w = p/q; return x+x*w; } /* 1> |x|>= 0.5 */ w = one-__builtin_fabs(x); t = w*0.5; p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); s = __builtin_sqrt(t); if(ix>=0x3FEF3333) { /* if |x| > 0.975 */ w = p/q; t = pio2_hi-(2.0*(s+s*w)-pio2_lo); } else { w = s; SET_LOW_WORD(w, 0); c = (t-w*w)/(s+w); r = p/q; p = 2.0*s*r-(pio2_lo-2.0*c); q = pio4_hi-2.0*w; t = pio4_hi-(p-q); } if(hx>0) return t; else return -t; }
double Math::inorm(const Math::Vector2<double> &v) { return 1.0 / __builtin_sqrt(v.x * v.x + v.y * v.y); } // inorm
double foo (double a) { double tmp = 1.0f / __builtin_sqrt (a); return tmp * tmp; }
double f3(double x) { return __builtin_sqrt(x); }
double rsqrt_d (double a) { return 1.0 / __builtin_sqrt (a); }
double Math::norm(const Math::Vector3<double> &v) { return __builtin_sqrt(v.x * v.x + v.y * v.y + v.z * v.z); } // norm
double test1(double x) { return __builtin_sqrt(x); }
void test2(double x, double y) { if (-tan(x-y) != tan(y-x)) link_error (); if (-sin(x-y) != sin(y-x)) link_error (); if (cos(-x*y) != cos(x*y)) link_error (); if (cos(x*-y) != cos(x*y)) link_error (); if (cos(-x/y) != cos(x/y)) link_error (); if (cos(x/-y) != cos(x/y)) link_error (); if (cos(-fabs(tan(x/-y))) != cos(tan(x/y))) link_error (); if (cos(y<10 ? -x : y) != cos(y<10 ? x : y)) link_error (); if (cos(y<10 ? x : -y) != cos(y<10 ? x : y)) link_error (); if (cos(y<10 ? -fabs(x) : tan(x<20 ? -x : -fabs(y))) != cos(y<10 ? x : tan(x<20 ? x : y))) link_error (); if (cos((y*=3, -x)) != cos((y*=3,x))) link_error (); if (cos((y*=2, -fabs(tan(x/-y)))) != cos((y*=2,tan(x/y)))) link_error (); if (cos(copysign(x,y)) != cos(x)) link_error (); if (cos(copysign(-fabs(x),y*=2)) != cos((y*=2,x))) link_error (); if (hypot (x, 0) != fabs(x)) link_error (); if (hypot (0, x) != fabs(x)) link_error (); if (hypot (x, x) != fabs(x) * __builtin_sqrt(2)) link_error (); if (hypot (-x, y) != hypot (x, y)) link_error (); if (hypot (x, -y) != hypot (x, y)) link_error (); if (hypot (-x, -y) != hypot (x, y)) link_error (); if (hypot (fabs(x), y) != hypot (x, y)) link_error (); if (hypot (x, fabs(y)) != hypot (x, y)) link_error (); if (hypot (fabs(x), fabs(y)) != hypot (x, y)) link_error (); if (hypot (-fabs(-x), -fabs(fabs(fabs(-y)))) != hypot (x, y)) link_error (); if (hypot (-x, 0) != fabs(x)) link_error (); if (hypot (-x, x) != fabs(x) * __builtin_sqrt(2)) link_error (); if (hypot (pure(x), -pure(x)) != fabs(pure(x)) * __builtin_sqrt(2)) link_error (); if (hypot (tan(-x), tan(-fabs(y))) != hypot (tan(x), tan(y))) link_error (); if (fmin (fmax(x,y),y) != y) link_error (); if (fmin (fmax(y,x),y) != y) link_error (); if (fmin (x,fmax(x,y)) != x) link_error (); if (fmin (x,fmax(y,x)) != x) link_error (); if (fmax (fmin(x,y),y) != y) link_error (); if (fmax (fmin(y,x),y) != y) link_error (); if (fmax (x,fmin(x,y)) != x) link_error (); if (fmax (x,fmin(y,x)) != x) link_error (); if ((__complex__ double) x != -(__complex__ double) (-x)) link_error (); if (x*1i != -(-x*1i)) link_error (); if (x+(x-y)*1i != -(-x+(y-x)*1i)) link_error (); if (x+(x-y)*1i != -(-x-(x-y)*1i)) link_error (); if (ccos(tan(x)+sin(y)*1i) != ccos(-tan(-x)+-sin(-y)*1i)) link_error (); if (ccos(tan(x)+sin(x-y)*1i) != ccos(-tan(-x)-sin(y-x)*1i)) link_error (); if (-5+x*1i != -~(5+x*1i)) link_error (); if (tan(x)+tan(y)*1i != -~(tan(-x)+tan(y)*1i)) link_error (); }
double foo (double a) { return __builtin_sqrt (a); }
Math::Vector2<double> Math::proj(const Math::Vector2<double> &u, const Math::Vector2<double> &v) { return v * ((u * v) / __builtin_sqrt(v * v)); } // proj
double __ieee754_sqrt (double d) { return __builtin_sqrt (d); }
// CHECK-LABEL: define void @test_float_builtin_ops void test_float_builtin_ops(float F, double D, long double LD) { volatile float resf; volatile double resd; volatile long double resld; resf = __builtin_fmodf(F,F); // CHECK: frem float resd = __builtin_fmod(D,D); // CHECK: frem double resld = __builtin_fmodl(LD,LD); // CHECK: frem x86_fp80 resf = __builtin_fabsf(F); resd = __builtin_fabs(D); resld = __builtin_fabsl(LD); // CHECK: call float @llvm.fabs.f32(float // CHECK: call double @llvm.fabs.f64(double // CHECK: call x86_fp80 @llvm.fabs.f80(x86_fp80 resf = __builtin_canonicalizef(F); resd = __builtin_canonicalize(D); resld = __builtin_canonicalizel(LD); // CHECK: call float @llvm.canonicalize.f32(float // CHECK: call double @llvm.canonicalize.f64(double // CHECK: call x86_fp80 @llvm.canonicalize.f80(x86_fp80 resf = __builtin_fminf(F, F); // CHECK: call float @llvm.minnum.f32 resd = __builtin_fmin(D, D); // CHECK: call double @llvm.minnum.f64 resld = __builtin_fminl(LD, LD); // CHECK: call x86_fp80 @llvm.minnum.f80 resf = __builtin_fmaxf(F, F); // CHECK: call float @llvm.maxnum.f32 resd = __builtin_fmax(D, D); // CHECK: call double @llvm.maxnum.f64 resld = __builtin_fmaxl(LD, LD); // CHECK: call x86_fp80 @llvm.maxnum.f80 resf = __builtin_fabsf(F); // CHECK: call float @llvm.fabs.f32 resd = __builtin_fabs(D); // CHECK: call double @llvm.fabs.f64 resld = __builtin_fabsl(LD); // CHECK: call x86_fp80 @llvm.fabs.f80 resf = __builtin_copysignf(F, F); // CHECK: call float @llvm.copysign.f32 resd = __builtin_copysign(D, D); // CHECK: call double @llvm.copysign.f64 resld = __builtin_copysignl(LD, LD); // CHECK: call x86_fp80 @llvm.copysign.f80 resf = __builtin_ceilf(F); // CHECK: call float @llvm.ceil.f32 resd = __builtin_ceil(D); // CHECK: call double @llvm.ceil.f64 resld = __builtin_ceill(LD); // CHECK: call x86_fp80 @llvm.ceil.f80 resf = __builtin_floorf(F); // CHECK: call float @llvm.floor.f32 resd = __builtin_floor(D); // CHECK: call double @llvm.floor.f64 resld = __builtin_floorl(LD); // CHECK: call x86_fp80 @llvm.floor.f80 resf = __builtin_sqrtf(F); // CHECK: call float @llvm.sqrt.f32( resd = __builtin_sqrt(D); // CHECK: call double @llvm.sqrt.f64( resld = __builtin_sqrtl(LD); // CHECK: call x86_fp80 @llvm.sqrt.f80 resf = __builtin_truncf(F); // CHECK: call float @llvm.trunc.f32 resd = __builtin_trunc(D); // CHECK: call double @llvm.trunc.f64 resld = __builtin_truncl(LD); // CHECK: call x86_fp80 @llvm.trunc.f80 resf = __builtin_rintf(F); // CHECK: call float @llvm.rint.f32 resd = __builtin_rint(D); // CHECK: call double @llvm.rint.f64 resld = __builtin_rintl(LD); // CHECK: call x86_fp80 @llvm.rint.f80 resf = __builtin_nearbyintf(F); // CHECK: call float @llvm.nearbyint.f32 resd = __builtin_nearbyint(D); // CHECK: call double @llvm.nearbyint.f64 resld = __builtin_nearbyintl(LD); // CHECK: call x86_fp80 @llvm.nearbyint.f80 resf = __builtin_roundf(F); // CHECK: call float @llvm.round.f32 resd = __builtin_round(D); // CHECK: call double @llvm.round.f64 resld = __builtin_roundl(LD); // CHECK: call x86_fp80 @llvm.round.f80 }
double Math::abs(const Math::Vector2<double> &v) { return __builtin_sqrt(v.x * v.x + v.y * v.y); } // abs