Pages: [1]   Go Down
Author Topic: Error in abs() documentation?  (Read 407 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The reference docs say that abs():

"Returns

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

-x: if x is less than 0. "

That's not the definition of absolute value as I understand it. I'm pretty sure it should be:

"Returns

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

x: if x is less than 0."
Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If x is -1 then -x is -(-1) which is 1.

--Phil.
Logged

Las Vegas, NV
Offline Offline
God Member
*****
Karma: 0
Posts: 507
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
"Returns

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

x: if x is less than 0."

This reduces to:

returns x

which would be fairly useless.
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My apologies, you're right--they mean the -(-1) = 1 formulation. It's just somewhat obscure and ambiguous phrasing for a very straightforward concept. But I suppose that's computer science for you ;-)
Logged

Las Vegas, NV
Offline Offline
God Member
*****
Karma: 0
Posts: 507
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It's basically the standard mathematical way to express what absolute value means.  The other way is |x| = sqrt(x^2).
Logged


Pages: [1]   Go Up
Jump to: