[vtk-developers] Dashboard problems: ambiguous conversion fabs() call

Kyle Lutz kyle.lutz at kitware.com
Thu Aug 16 10:35:03 EDT 2012


On Thu, Aug 16, 2012 at 6:58 AM, David Gobbi <david.gobbi at gmail.com> wrote:
> On Thu, Aug 16, 2012 at 7:39 AM, Kyle Lutz <kyle.lutz at kitware.com> wrote:
>>
>> Also, did you mean std::abs()? std::fabs() is not overloaded for the
>> integral types and std::abs() should be preferred anyway.
>
> In code that is only meant to be used for floating-point numbers, I
> prefer std::fabs() because I _like_ the fact that it produces an error
> if an integer slips in. But for vtkTuple, where both ints and floats
> are possible, std::abs() is the clear winner.

I see your point.

However, you will not receive an error when you pass an integer to
std::fabs(). The integer will just be converted to a floating-point
type before being passed to the function.

For example try the following code:

int i = -42;
std::cout << std::fabs(i) << std::endl;

-kyle



More information about the vtk-developers mailing list