[osg-users] Please test SVN version of OpenSceneGraph

Jean-Sébastien Guay jean-sebastien.guay at polymtl.ca
Tue Sep 11 13:09:47 PDT 2007

Hello Chase,

> floorf accounts for the slight numerical error when the difference   
> between the value and the next greater integer is less than some   
> threshold.
> Try:
> std::cout << floorf(0.6/0.2) << std::endl << (int)(0.6/0.2) << std::endl;
> Both should be 3, but the cast version prints 2.  I'm not sure that   
> accuracy really matters in the context where this function is used.

OK, but if the input to floor is an int, and the result is casted back  
to an int, what's the use?

The actual code I'm talking about is:

         int width = _textureWidth;
         int height = _textureHeight;
         int numMipmapLevels = 1 +  
(int)floor(float(log2(maximum(width, height))));

If you break it down:
- width and height are ints
- they are fed to a template function 'T maximum(T, T)' which will then return
   an int
- this is fed to 'int log2(int)', which returns an int
- this is casted to a float, which I added, or else floor would  
complain (float or double when taking an int?)
- the result of floor is casted to an int again.

Couldn't this just be replaced by

int numMipmapLevels = 1 + log2(maximum(width, height));

since floor(a) if a is an int should just be a?

> For these types the parenthetical casts are equivalent.

That's what I thought... But there must be a reason why they're being  
used here instead?...


Jean-Sebastien Guay     jean-sebastien.guay at polymtl.ca

This message was sent using IMP, the Internet Messaging Program.

More information about the osg-users mailing list