   If negative, return 1
  Is there a function that would return 1 if the number is negative, and if positive, just return the number?   
float f(float a){  if(a>=0)    return a ;  return 1 ;};  Couldnt you just write the function yourself?   ;  ?!?   ;  return number < 0 ? 1 : number;;  There is no such function, because it's not really that useful.You can express it, though:1if x < 0f(x) = {xotherwiseAlternately, if you feel in a funny mood, you can express it using either khi (characteristical) functions:f(x) = χ<0(x) + x χ>0(x)Or, to be really nasty, as the prolonged version of:f(x) = (x + |x|) / 2 + (x - |x|) / 2 |x|;  yes, but I've been trying to optimize my code.  I was wondering if there was a math function that basically did the same thing so I could just say abs(value) and be done.   ;  There is no standard C/C++ function for that, nor any mathematical operator than I am aware of.Such a function would exist if you wrote it yourself, which is trivial as Dave Hunt's suggestion demonstrates:int function(int value) {    return value < 0 ? 1 : value;}Edit:In comparison an integer abs function that doesn't want to perform casting might be implemented as:int abs(int value) {    return value < 0 ? -value : value;}Don't confuse them they do two different things.   ;Quote:Original post by subnet_rxyes, but I've been trying to optimize my code.  I was wondering if there was a math function that basically did the same thing so I could just say abs(value) and be done.What is that function anyway?   ;Quote:Original post by ToohrVykThere is no such function, because it's not really that useful.You can express it, though:1if x < 0f(x) = {xotherwiseAlternately, if you feel in a funny mood, you can express it using either khi (characteristical) functions:f(x) = χ<0(x) + x χ>0(x)Or, to be really nasty, as the prolonged version of:f(x) = (x + |x|) / 2 + (x - |x|) / 2 |x|google didn't help with the khi. please elaborate.i'm making the guess that it's just a function that returns 1 if the subscript is true and 0 otherwise?   