Go Down

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

#### oh1kh

##### Sep 12, 2017, 07:24 pm
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

#1
##### Sep 12, 2017, 07:35 pm
A negative of a negative number is a positive number, so the statement is correct.
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & 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

#2
##### Nov 25, 2017, 02:03 pm
I agree to oh1kh post. It's wrong.

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

But the expression in reference manual is just confusing.

#### AWOL

#3
##### Nov 26, 2017, 09:20 pm
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 (who) 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

#4
##### Dec 09, 2017, 07:34 pm
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