Reputation: 1140
I am using C as the programming language. How to ignore the sign when using float/signed int variables? For example if float/signed int f = -40 or +40 The result should be same after a mathematical operation like a+b*f
Upvotes: 1
Views: 4355
Reputation: 42025
Are you looking for absolute value?
#include<math.h>
includes abs
for integers, fabs
for floats.
Upvotes: 2
Reputation: 182073
fabsf(f)
returns the absolute value of f
: fabsf(40) == 40
and also fabsf(-40) == 40
.
Upvotes: 0
Reputation: 52549
Use abs
for ints or fabs
for floats.
a+b*abs(f)
EDIT: It's not clear wether you want -40 to be treated as 40 or vice versa, if you for some reason wan't the latter:
a+b*-abs(f)
Upvotes: 11