LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Necesito saber si en CVI existe una funcion que me convierta un numero negativo a positivo es decir que el mismo numero negativo me lo convierta a positivo

Necesito saber si en CVI existe una funcion que me convierta un numero negativo a positivo es decir que el mismo numero negativo me lo convierta a positivo
0 Kudos
Message 1 of 3
(3,191 Views)
fabs() returns the absolute value of a number.
For example:

#include
void main()
{
int i, j;
float k;
i = -1;
j = 1;
k = -4.56;
printf("fabs(%d) = %f\n",i, fabs(i));
printf("fabs(%d) = %f\n",j, fabs(j));
printf("fabs(%f) = %f\n",k, fabs(k));
}

Output:
fabs(-1) = 1.000000
fabs(1) = 1.000000
fabs(-4.560000) = 4.560000
0 Kudos
Message 2 of 3
(3,191 Views)
In toolbox.h is also defined this marco:

#ifndef ABS_VAL
#define ABS_VAL(a) ((a) < 0 ? (-(a)) : (a))
#endif

Just my 2 cents.
I wonder why someone felt urged to define a macro that performs the same as a native ansi-c function?


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 3
(3,191 Views)