Hey Guys
I have a simple wrapper for an Mersenne twister random number generator. The purpose is to scale the number returned by the generator (between 0 and 1) to between argument defined limits (begin and end).
So my function is
inline float xlRandomFloat(float begin, float end) {return (begin+((end-begin)*genrand_real2()));}
I don't believe the implementation of genrand_real2() function is important, but if I am wrong it can be found here
The problem is the function does not return the translated result. The scaling (multiplying by (begin-end) seems to work correctly, but the addition of begin does not seem to be returned.
So if I call xlRandomFloat(5,10) - I get values between 0 and 5.
If I debug with GDB, and use the print function then it shows the correct result. So then I tried separating things into lines to see what happens
inline float xlRandomFloat(float begin, float end) {
float ret;
ret=(((end-begin)*genrand_real2()));
ret+=begin;
return ret;};
When debugging, it jumped straight from the first line into the genrand_real2() function and skipped out every thing else entirely. That was really confusing so I thought it may have something to do with the inlining. I moved the file from this .hpp file to the .cpp and removed the inline keyword and everything works correctly.
But why does this behavior occur, and how can I inline this function? Also, I am not sure if this is relevant, but often when I made changes to the sources, my Make compilation would say there is nothing to be done. Which is unusual since normally I expect make to pick up on changes in the sources and rebuild accordingly.
Any ideas.
Thanks
Zenna