On 12/14/07, <b class="gmail_sendername">Emmanuel Christophe</b> &lt;<a href="mailto:emmanuel.christophe@gmail.com">emmanuel.christophe@gmail.com</a>&gt; 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&#39;t know what is ITK policy for this, but I wouldn&#39;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&lt;<br>ValueType &gt; (m_Data[i] /&nbsp;&nbsp;s ) ?</blockquote><div><br>That should read <br>&nbsp; static_cast&lt; ValueType &gt;( static_cast&lt; RealValueType &gt;(m_Data[i]) / static_cast&lt; RealValueType &gt;(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.&nbsp;&nbsp; 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&amp;D Engineer,<br>Kitware Inc.