PDA

View Full Version : fract() behaviour



0x069
09-15-2010, 12:12 AM
Hello,

I want to ask - Why in GLSL was such design decision to make fract() function as
x-floor(x) because it gives "incorrect" fraction values for negative arguments. Correct fract() implementation should be like this:

if (x>=0.)
return x-floor(x)
else
return x-ceil(x)

Anybody knows such fract() design decision ??

Thanks in advance.

ZbuffeR
09-15-2010, 04:22 AM
Same for modulo operation, they are done differently depending on the programming language and sometimes hardware architecture :
http://en.wikipedia.org/wiki/Modulo_operation

Not sure if one is better than the other in the mathematical or design sense, anyway it will depend on what you want to do with it.