Documentation for ABS function is confusing

Hello.

On page http://www.arduino.cc/en/Reference/Abs

It says the ABS function will return:

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

-x: if x is less than 0.

This is a bit unclear! Now, I realise that if x is negative, then -x is positive, but not everyone will so this is a bit too confusing.

Why not simply say:

The abs(x) function returns the absolute value of x, that is to say it returns x without the sign.

and provide some examples :

x= 4.5 returns 4.5
x= -3.2 returns 3.2
x= 0 returns 0

Hope that can be updated. :slight_smile:

Warmest regards,

Brian

Well firstly, your chance of having anything in the tutorials/ references altered, is close to |x| = -(x2).

However the definition

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

-x: if x is less than 0.

is actually entirely accurate in terms of the function’s implementation.

You're not the first to (incorrectly IMO) report this one. ;)

Hello,

bcraigie: Hope that can be updated. :-)

Create an issue here... https://github.com/arduino/reference-en/issues

Optionally...

Fork the repository... https://github.com/arduino/reference-en

Change abs.adoc... https://github.com/arduino/reference-en/blob/master/Language/Functions/Math/abs.adoc

Commit the change. Create a pull request.

Thanks Coding Badly, I shall follow your instructions. :-)

Re: AWOL, how can it be incorrect to want to clarify or improve the documentation? :-)

Thanks everyone.

Warmest wishes,

Brian