-
Notifications
You must be signed in to change notification settings - Fork 11
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 computex
moduloy
asx-y*floor(x/y)
. Incmath.h
anfmod(x,y)
is defined being the floating point remainder ofx/y
which is calculated asx-n*y
withn
begingx/y
with it's fractional part truncated. Withfloor
truncating the fractional part this should befloor(x/y)
and thereby this interpretation should match the OpenGL ES spec. And asfmod
is overloaded to work withfloat
as well as withdouble
(the default), one would usefloat fmodf(float,float)
to constrain it tofloat
and onlyfloat
. For Metal (don't know if it comes with Metal or is added by DCTL)_modf
comes 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 withT
beingfloat
,double
, orlong double
that does decompose a value in its integral and fractional part, and has itsmodff
variant for single precision values.