Code cleanup: use sqrtf when input and output are float

This commit is contained in:
Campbell Barton 2014-03-28 14:53:37 +11:00
parent e6e7438181
commit 7199e2288f
20 changed files with 41 additions and 39 deletions

View File

@ -2689,7 +2689,7 @@ static void stretchto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
switch (data->volmode) {
/* volume preserving scaling */
case VOLUME_XZ:
scale[0] = 1.0f - (float)sqrt(data->bulge) + (float)sqrt(data->bulge * (data->orglength / dist));
scale[0] = 1.0f - sqrtf(data->bulge) + sqrtf(data->bulge * (data->orglength / dist));
scale[2] = scale[0];
break;
case VOLUME_X:

View File

@ -1931,8 +1931,8 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si
{
float t01, t02, x3, y3;
t01 = (float)sqrt(x1 * x1 + y1 * y1);
t02 = (float)sqrt(x2 * x2 + y2 * y2);
t01 = sqrtf(x1 * x1 + y1 * y1);
t02 = sqrtf(x2 * x2 + y2 * y2);
if (t01 == 0.0f)
t01 = 1.0f;
if (t02 == 0.0f)
@ -1960,7 +1960,7 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si
y3 = -x1;
}
else {
t01 = (float)sqrt(x3 * x3 + y3 * y3);
t01 = sqrtf(x3 * x3 + y3 * y3);
x3 /= t01;
y3 /= t01;
}

View File

@ -678,8 +678,10 @@ static void gamtabs(float gamma)
val = a;
val /= 65535.0f;
if (gamma == 2.0f) val = sqrt(val);
else if (gamma != 1.0f) val = pow(val, igamma);
if (gamma == 2.0f)
val = sqrtf(val);
else if (gamma != 1.0f)
val = powf(val, igamma);
gamtab[a] = (65535.99f * val);
}
@ -1443,7 +1445,7 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f
temp1 = xo * (1 - facf0 / 2) - xo * facf0 / 2;
temp2 = yo * (1 - facf0 / 2) - yo * facf0 / 2;
pointdist = sqrt(temp1 * temp1 + temp2 * temp2);
pointdist = sqrtf(temp1 * temp1 + temp2 * temp2);
if (b2 < b1 && b2 < b3) {
if (hwidth < pointdist)
@ -1500,9 +1502,9 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f
hwidth = width * 0.5f;
temp1 = (halfx - (halfx) * facf0);
pointdist = sqrt(temp1 * temp1 + temp1 * temp1);
pointdist = sqrtf(temp1 * temp1 + temp1 * temp1);
temp2 = sqrt((halfx - x) * (halfx - x) + (halfy - y) * (halfy - y));
temp2 = sqrtf((halfx - x) * (halfx - x) + (halfy - y) * (halfy - y));
if (temp2 > pointdist) output = in_band(hwidth, fabsf(temp2 - pointdist), 0, 1);
else output = in_band(hwidth, fabsf(temp2 - pointdist), 1, 1);

View File

@ -1244,7 +1244,7 @@ static bool getLowestRoot(const float a, const float b, const float c, const flo
if (determinant >= 0.0f) {
/* calculate the two roots: (if determinant == 0 then
* x1==x2 but lets disregard that slight optimization) */
float sqrtD = (float)sqrt(determinant);
float sqrtD = sqrtf(determinant);
float r1 = (-b - sqrtD) / (2.0f * a);
float r2 = (-b + sqrtD) / (2.0f * a);
@ -2974,8 +2974,8 @@ void lookat_m4(float mat[4][4], float vx, float vy, float vz, float px, float py
dy = py - vy;
dz = pz - vz;
hyp = dx * dx + dz * dz; /* hyp squared */
hyp1 = (float)sqrt(dy * dy + hyp);
hyp = (float)sqrt(hyp); /* the real hyp */
hyp1 = sqrtf(dy * dy + hyp);
hyp = sqrtf(hyp); /* the real hyp */
if (hyp1 != 0.0f) { /* rotate X */
sine = -dy / hyp1;
@ -3097,7 +3097,7 @@ void map_to_sphere(float *r_u, float *r_v, const float x, const float y, const f
if (x == 0.0f && y == 0.0f) *r_u = 0.0f; /* othwise domain error */
else *r_u = (1.0f - atan2f(x, y) / (float)M_PI) / 2.0f;
*r_v = 1.0f - (float)saacos(z / len) / (float)M_PI;
*r_v = 1.0f - saacos(z / len) / (float)M_PI;
}
else {
*r_v = *r_u = 0.0f; /* to avoid un-initialized variables */

View File

@ -1011,7 +1011,7 @@ static void mat3_to_eul2(float tmat[3][3], float eul1[3], float eul2[3])
copy_m3_m3(mat, tmat);
normalize_m3(mat);
cy = (float)sqrt(mat[0][0] * mat[0][0] + mat[0][1] * mat[0][1]);
cy = sqrtf(mat[0][0] * mat[0][0] + mat[0][1] * mat[0][1]);
if (cy > 16.0f * FLT_EPSILON) {

View File

@ -494,7 +494,7 @@ void reflect_v3_v3v3(float out[3], const float v1[3], const float v2[3])
void ortho_basis_v3v3_v3(float v1[3], float v2[3], const float v[3])
{
const float f = (float)sqrt(v[0] * v[0] + v[1] * v[1]);
const float f = sqrtf(v[0] * v[0] + v[1] * v[1]);
if (f < 1e-35f) {
// degenerate case

View File

@ -203,7 +203,7 @@ int nextLengthSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int st
c = dot_v3v3(off, off) - (lengthLimit * lengthLimit);
f = (-b + (float)sqrt(b * b - 4 * a * c)) / (2 * a);
f = (-b + sqrtf(b * b - 4 * a * c)) / (2 * a);
//printf("a %f, b %f, c %f, f %f\n", a, b, c, f);

View File

@ -4142,7 +4142,7 @@ static bool ui_numedit_but_NORMAL(uiBut *but, uiHandleButtonData *data,
if (mrad < radsq) { /* inner circle */
fp[0] = dx;
fp[1] = dy;
fp[2] = sqrt(radsq - dx * dx - dy * dy);
fp[2] = sqrtf(radsq - dx * dx - dy * dy);
}
else { /* outer circle */
@ -4155,7 +4155,7 @@ static bool ui_numedit_but_NORMAL(uiBut *but, uiHandleButtonData *data,
if (mrad < radsq) {
fp[0] = dx;
fp[1] = dy;
fp[2] = -sqrt(radsq - dx * dx - dy * dy);
fp[2] = -sqrtf(radsq - dx * dx - dy * dy);
}
}
normalize_v3(fp);

View File

@ -1132,7 +1132,7 @@ static void ui_item_rna_size(uiLayout *layout, const char *name, int icon, Point
if (ELEM(subtype, PROP_LAYER, PROP_LAYER_MEMBER))
h += 2 * UI_UNIT_Y;
else if (subtype == PROP_MATRIX)
h += ceil(sqrt(len)) * UI_UNIT_Y;
h += ceilf(sqrtf(len)) * UI_UNIT_Y;
else
h += len * UI_UNIT_Y;
}

View File

@ -892,7 +892,7 @@ static void ui_do_animate(const bContext *C, Panel *panel)
float fac;
fac = (PIL_check_seconds_timer() - data->starttime) / ANIMATION_TIME;
fac = min_ff(sqrt(fac), 1.0f);
fac = min_ff(sqrtf(fac), 1.0f);
/* for max 1 second, interpolate positions */
if (uiAlignPanelStep(sa, ar, fac, false)) {

View File

@ -1944,7 +1944,7 @@ static void widget_softshadow(const rcti *rect, int roundboxalign, const float r
glEnableClientState(GL_VERTEX_ARRAY);
for (step = 1; step <= (int)radout; step++) {
float expfac = sqrt(step / radout);
float expfac = sqrtf(step / radout);
round_box_shadow_edges(wtb.outer_v, &rect1, radin, UI_CNR_ALL, (float)step);

View File

@ -1456,7 +1456,7 @@ static void bgl_sphere_project(float ax, float az)
float dir[3], sine, q3;
sine = 1.0f - ax * ax - az * az;
q3 = (sine < 0.0f) ? 0.0f : (float)(2.0 * sqrt(sine));
q3 = (sine < 0.0f) ? 0.0f : (2.0f * sqrtf(sine));
dir[0] = -az * q3;
dir[1] = 1.0f - 2.0f * sine;
@ -2393,7 +2393,7 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base
/* draw from first frame of range to last */
for (CFRA = (int)start; CFRA < end; CFRA += (int)stepsize) {
colfac = (end - (float)CFRA) / range;
UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
BKE_pose_where_is(scene, ob);
@ -2473,7 +2473,7 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base *
/* draw from first frame of range to last */
for (ak = keys.first, i = 0; ak; ak = ak->next, i++) {
colfac = i / range;
UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
CFRA = (int)ak->cfra;
@ -2543,7 +2543,7 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
for (cur = stepsize; cur < range; cur += stepsize) {
ctime = cur - (float)fmod(cfrao, stepsize); /* ensures consistent stepping */
colfac = ctime / range;
UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
/* only within action range */
if (actframe + ctime >= start && actframe + ctime <= end) {
@ -2558,7 +2558,7 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
ctime = cur + (float)fmod((float)cfrao, stepsize) - stepsize + 1.0f; /* ensures consistent stepping */
colfac = ctime / range;
UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
/* only within action range */
if ((actframe - ctime >= start) && (actframe - ctime <= end)) {

View File

@ -492,9 +492,9 @@ static void calctrackballvec(const rcti *rect, int mx, int my, float vec[3])
y = BLI_rcti_cent_y(rect) - my;
y /= (float)(BLI_rcti_size_y(rect) / 2);
d = sqrt(x * x + y * y);
d = sqrtf(x * x + y * y);
if (d < radius * (float)M_SQRT1_2) { /* Inside sphere */
z = sqrt(radius * radius - d * d);
z = sqrtf(radius * radius - d * d);
}
else { /* On hyperbola */
t = radius / (float)M_SQRT2;

View File

@ -1818,7 +1818,7 @@ void calculatePropRatio(TransInfo *t)
td->factor = 3.0f * dist * dist - 2.0f * dist * dist * dist;
break;
case PROP_ROOT:
td->factor = (float)sqrt(dist);
td->factor = sqrtf(dist);
break;
case PROP_LIN:
td->factor = dist;
@ -1827,7 +1827,7 @@ void calculatePropRatio(TransInfo *t)
td->factor = 1.0f;
break;
case PROP_SPHERE:
td->factor = (float)sqrt(2 * dist - dist * dist);
td->factor = sqrtf(2 * dist - dist * dist);
break;
case PROP_RANDOM:
td->factor = BLI_frand() * dist;

View File

@ -68,7 +68,7 @@ static void InputSpring(TransInfo *UNUSED(t), MouseInput *mi, const int mval[2],
dx = (float)(mi->center[0] - mval[0]);
dy = (float)(mi->center[1] - mval[1]);
precise_ratio = (float)sqrt(dx * dx + dy * dy);
precise_ratio = sqrtf(dx * dx + dy * dy);
ratio = (ratio + (precise_ratio - ratio) / 10.0f) / mi->factor;
}

View File

@ -253,7 +253,7 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob,
fac = 3.0f * fac * fac - 2.0f * fac * fac * fac;
break;
case eWarp_Falloff_Root:
fac = (float)sqrt(fac);
fac = sqrtf(fac);
break;
case eWarp_Falloff_Linear:
/* pass */
@ -262,7 +262,7 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob,
fac = 1.0f;
break;
case eWarp_Falloff_Sphere:
fac = (float)sqrt(2 * fac - fac * fac);
fac = sqrtf(2 * fac - fac * fac);
break;
}

View File

@ -94,10 +94,10 @@ void weightvg_do_map(int num, float *new_w, short falloff_type, CurveMapping *cm
fac = 3.0f * fac * fac - 2.0f * fac * fac * fac;
break;
case MOD_WVG_MAPPING_ROOT:
fac = (float)sqrt(fac);
fac = sqrtf(fac);
break;
case MOD_WVG_MAPPING_SPHERE:
fac = (float)sqrt(2 * fac - fac * fac);
fac = sqrtf(2 * fac - fac * fac);
break;
case MOD_WVG_MAPPING_RANDOM:
fac = BLI_rng_get_float(rng) * fac;

View File

@ -621,7 +621,7 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
for (x = 0; x < vec_size; x++) {
norm += tvec[x] * tvec[x];
}
norm = (float) sqrt(norm);
norm = sqrtf(norm);
for (x = 0; x < vec_size; x++) {
tvec[x] /= norm;
}
@ -742,7 +742,7 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
for (x = 0; x < vec_size; x++) {
norm += tvec[x] * tvec[x];
}
norm = (float) sqrt(norm);
norm = sqrtf(norm);
for (x = 0; x < vec_size; x++) {
tvec[x] /= norm;
}

View File

@ -1702,7 +1702,7 @@ static int point_behind_strand(const float p[3], BSPFace *face)
rc[0]= pt[0]-p[0];
rc[1]= pt[1]-p[1];
dist= (float)sqrt(rc[0]*rc[0]+ rc[1]*rc[1]);
dist= sqrtf(rc[0]*rc[0]+ rc[1]*rc[1]);
if (dist < face->radline) {
float zval= face->vec1[2] + lambda*face->rc[2];

View File

@ -4106,7 +4106,7 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even
delta[1] /= zoom[1];
}
dist = sqrt(delta[0] * delta[0] + delta[1] * delta[1]);
dist = len_v2(delta);
/* calculate new value and apply snapping */
switch (rc->subtype) {