Go Down

Topic: Arduino reference ABS(x) (Read 1 time) previous topic - next topic

oh1kh

Hi!
This was the site that Reference corrections link moved me.

I think there is an error with abs(x):


Reference   Language | Libraries | Comparison | Changes
abs(x)
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.          <-------------------Here     
Warning



Compared to c++ reference:   if x is less than 0, means negative number, returns x. (Not -x ! )


--
Saku

spycatcher2k

A negative of a negative number is a positive number, so the statement is correct.
-=-
http://www.uk-pcb.co.uk - UK Based PCB Fab Company
I will code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

erikjo

I agree to oh1kh post. It's wrong.

x = abs(-x)
-x = -abs(x)

But the expression in reference manual is just confusing.

AWOL

Congratulations!
You are the 106th person to bring up this non-error.

Quote
Compared to c++ reference:   if x is less than 0, means negative number, returns x.
If x is negative, then returning x is obviously the wrong thing to do.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

robtillaart

The ultimate proof is to code a test sketch that shows the behavior.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up