# Arduino Reference - abs()

Just looking at the reference section for the abs() function and it tells me that abs() does the following;

Description Computes the absolute value of a number. Parameters x: the number Returns x: if x is greater than or equal to 0. -x: if x is less than 0.

Well, blow me down, I'm guessing the return value just returns the original value of x, regardless if it was less than zero. I do not recall abs() would ever return a negative value. Should this instead read something along the lines of;

Returns the absolute value of x |x| = abs(x)

example: abs(12) = 12 abs(-14) = 14

And while I'm at it, the link where it mentions the following;

Corrections, suggestions, and new documentation should be posted to the Forum.

The link on the word 'Forum' is to the 'Arduino Forum :: Development :: Other Software Development', why on Earth there I ask?

Paul

Thanks Telecommando you are right, of course, and I should have seen that. Note to self: spend time away from computer(s), breathe in the fresh air of the forest outside :blush:

Paul

Yes, I made that mistake too a long time ago. But did not post. Which - considering that I have use the ABS function in other languages since mid 1970'ies - is not that I do not know or understand what the function does, but that the explanation is needlessly "mathematical" in nature, escpecially considering that that the documentation is aimed at newcommers in this field.

hello!

i have a doubt about the case abs(0) (absolute value of zero); in this piece of code for example:

step = ((frequency - frequencyOld) / 20);
step = abs(step);

when both frequencies are the same, then step = 0, the code freezes.

is there any know problem in the implementation of absolute value? abs(0) = 0 as far as wikipedia says, but the reference does not explicits the case for argument = zero.

Duh? abs() is welbehaved and should not have any edge conditions. Certainly this works

``````int z = 0; float zz = 0.0 ;
void setup() {
Serial.begin(9600) ;
zz =abs(z) ;  Serial.println(z) ;
zz =abs(zz) ;  Serial.println(zz) ;
}
``````

So start a new thread for discovering why your code hangs if the expression `((frequency - frequencyOld) / 20)` returns zero. I guess that whatever code you do something with a step-size of zero has a logical flaw

x: if x is greater than or equal to 0.

-x: if x is less than 0.

so if x = “-5”

then -x = “–5”

and “–5” is “+5”

note that 0/0 is not allowed it doesnt go wrong on abs() its the line before it.

torna0:
if (abs(A[i, K]) > abs(A[L, K])) {
L = i;
}

if (i < N) {
i = i++; //i=i+1
goto torna0;
}

were is my mistache ? Sed me that there are two element but for me A[i,K] or A[L,K] are two element to work

thank you Leonardo

@leonardo50: Check first the correct syntax for an array access.
Then check here
(Also not sure what this has to do with the website or forum)