|
From: James W. <ja...@fr...> - 2007-03-02 23:25:50
|
Jose' Cruanyes wrote: > Il giorno 01/mar/07, alle ore 18:33, James W. Walker ha scritto: > >> or we could change E3Num_Max to be a function template defined >> exactly like std::max. >> > > taked... I'm leaving now (CET here) if tomorrow is still to do, I'll > do it. So, where did you get that template implementation? It's not the one used in Xcode or in CodeWarrior. Those reference casts looked suspicious, so I tried it out... float res1 = E3Num_Max( 23, 1.0f ); float res2 = E3Num_Max( 23, 100.0f ); float res3 = E3Num_Max( 1.0f, 23 ); float res4 = E3Num_Max( 100.0f, 23 ); The results I saw were 1e+9, 1e+9, 1.0, and 100.0 respectively. Not good. The answer to my original question "what is the advantage of using E3Num_Max rather than std::max?" seems to be: std::max does not allow operands of mixed type. Not only can you not mix int and float, you can't mix int and unsigned long. See <http://www.aristeia.com/Papers/C++ReportColumns/jan95.pdf> for a discussion of these issues. When I tried a more standard definition of E3Num_Max and E3Num_Min, I was surprised to find that we weren't using them directly with mixed types, the only problem was with E3Num_Clamp. So, I wrote a template version of E3Num_Clamp that casts its second and third parameters to match the type of the first parameter. I've committed an update to E3Utils.h with the new template definitions. -- James W. Walker, Innoventive Software LLC <http://www.frameforge3d.com/> |