On 12/14/07, <b class="gmail_sendername">Emmanuel Christophe</b> <<a href="mailto:emmanuel.christophe@gmail.com">emmanuel.christophe@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br><br>I don't know what is ITK policy for this, but I wouldn't have done it<br>exactly this way:<br> - always converting to double can be costly in term of processing<br>time (especially when this is done on each pixel)
<br> - as the ITK user is programming in C++ he should expect the division<br>to be an integer division if both numerator and denominator are int<br>and the division to be a real division if at least one of the<br>numerator or denominator is real.
<br><br>Given these points why not just cast on the result: static_cast<<br>ValueType > (m_Data[i] / s ) ?</blockquote><div><br>That should read <br> static_cast< ValueType >( static_cast< RealValueType >(m_Data[i]) / static_cast< RealValueType >(s) );
<br><br>Math operations should as far as possible be performed in the highest available precision, (definitely when you run a chance of an under/overflow) and hence they use NumericTraits::RealType. static_cast is a compile time cast and is the fastest cast possible (as fast as C style casts). Sure it adds a line or two more of machine code... but its not much of a concern.
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">The same modifications should also be applied to the operator* and *= I think.
</blockquote><div><br>Yes <br></div><br>Thanks<br></div>-- <br>Karthik Krishnan<br>R&D Engineer,<br>Kitware Inc.