c

Why does my abs function return an integer when I'm using doubles?


I wrote some C code in Visual Studio:

Mask1 = abs(Area1 * 2 + Area2 * -2);

Area1, Area2 and Mask1 are three double variables (e.g. 3.00556, 34.3333). My problem is that abs returns an integer value (e.g 30) instead of doubles.

What do I need to do to fix it so that it returns doubles?


Solution

  • Use fabs if you want to preserve the double type. abs is only for integers.