-
Notifications
You must be signed in to change notification settings - Fork 12
mod()
A stumbling block in the conversion arises with the modulo function. The _fmod() provided by DCTL unfortunately behaves a little differently than the one in WebGL. So it is sometimes absolutely necessary to use the replacement:
#define mod_f(a,b) (a-b*_floor(a/b))
OpenGL ES defines
mod(x,y)to computexmoduloyasx-y*floor(x/y). Incmath.hanfmod(x,y)is defined being the floating point remainder ofx/ywhich is calculated asx-n*ywithnbegingx/ywith it's fractional part truncated. Withfloortruncating the fractional part this should befloor(x/y)and thereby this interpretation should match the OpenGL ES spec. And asfmodis overloaded to work withfloatas well as withdouble(the default), one would usefloat fmodf(float,float)to constrain it tofloatand onlyfloat. For Metal (don't know if it comes with Metal or is added by DCTL)_modfcomes as the type generic macro#define _modf(X, INTVAL) modf((X), (INTVAL))- and here it even works for the vector types. Furthermore you should know that in the C standard library there also is aT modf(T,T*)function defined withTbeingfloat,double, orlong doublethat does decompose a value in its integral and fractional part, and has itsmodffvariant for single precision values.