Which is faster in Mobile platform: floor or frac?

which is faster in Mobile platform: floor or frac ?

fract uses floor, floor returns the number without the decimal and fract just returns the decimal part. in the reference pages you can see the calculation when using fract here fract - OpenGL 4 Reference Pages. But to answer your question it would be floor because fract has an extra subtraction. They both return different things though so just keep that in mind.

If you want something faster than floor. you can just simply cast to an int if you know your values are going to be bigger than 0.

or you can do something like this

float custom_floor(float x) 
    return float(int(x+MAX_NUMBER) - int(MAX_NUMBER)); 

but if you can’t guarentee any min/max i would just use the floor().

1 Like

will the following function faster than intrinsic floor() in openGL ES?
int int_floor(float x) { return int(x) - int(x < 0.0); }

if I was being honest probably no measurable difference. I would use floor() as its implementation is vendor specific. but if you are really curious you could set up some sort of bench mark and test for yourself but most likely there isn’t any difference.

1 Like