In an app I'm profiling, I found that in some scenarios this function is able to take over 10% of total execution time.
MSVC++ 2008 compiler is being used, for reference... I don't recall if modf maps to a single instruction or if there is likely any way to make it faster.
see also here for similar question on sqrt function
Unlike sqrt, I don't really know how modf works. Is there an assembly operation? For instance you could do:
modf(float input,int &intPart, float &floatPart)
{
intPart= (int)input;
floatPart= input - intPart;
}
But I assume this incurs penalties from casting/conversion, etc. how does a fast implementation work?