[Insight-developers] warnings in vnl_math

Bradley Lowekamp blowekamp at mail.nih.gov
Thu Mar 11 16:33:33 EST 2010


A small detail I noticed.

As char can be signed or unsigned, I am not sure that the original implementation is correct on this one. I would think it should read like the others:

inline unsigned char  vnl_math_abs(char x)       { return x < 0 ? 
static_cast<unsigned char>(-x) : static_cast<unsigned char>(x); }

Also lets hope the compilers don't start warning that "x<0" implicitly a comparison of int type.

Brad

On Mar 11, 2010, at 2:14 PM, Arnaud GELAS wrote:

> Hi Luis,
> 
> I have just compiled some stuff and I get some conversion warnings in 
> vnl_math.h (really easy to fix).
> I can fix it in itk, but I guess it should also be fixed in vnl/vxl, right?
> 
> How can I let vxl/vnl people know about it?
> 
> 
> inline unsigned char  vnl_math_abs(signed char x)   { return x < 0 ? 
> static_cast<unsigned char>(-x) : x; }
> inline unsigned char  vnl_math_abs(char x)          { return 
> static_cast<unsigned char>(x); }
> inline unsigned short vnl_math_abs(short x)         { return x < 0 ? 
> static_cast<unsigned short>(-x) : x; }
> inline unsigned short vnl_math_abs(unsigned short x){ return x; }
> inline unsigned int   vnl_math_abs(int x)           { return x < 0 ? -x 
> : x; }
> inline unsigned long  vnl_math_abs(long x)          { return x < 0L ? -x 
> : x; }
> 
> it has to be changed to
> 
> inline unsigned char  vnl_math_abs(signed char x)   { return x < 0 ? 
> static_cast<unsigned char>(-x) : static_cast<unsigned char>(x); }
> inline unsigned char  vnl_math_abs(char x)          { return 
> static_cast<unsigned char>(x); }
> inline unsigned short vnl_math_abs(short x)         { return x < 0 ? 
> static_cast<unsigned short>(-x) : static_cast<unsigned short>(x); }
> inline unsigned int   vnl_math_abs(int x)           { return x < 0 ? 
> static_cast<unsigned int>(-x) : static_cast<unsigned int>(x); }
> inline unsigned long  vnl_math_abs(long x)          { return x < 0L ? 
> static_cast<unsigned long>(-x) : static_cast<unsigned long>(x); }
> 
> 
> 
> Arnaud
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.html
> 
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-developers

========================================================
Bradley Lowekamp  
Lockheed Martin Contractor for
Office of High Performance Computing and Communications
National Library of Medicine 
blowekamp at mail.nih.gov


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20100311/c35ca027/attachment.htm>


More information about the Insight-developers mailing list