The Absolute value reference article from the English Wikipedia on 24-Apr-2004
(provided by Fixed Reference: snapshots of Wikipedia from wikipedia.org)

Absolute value

Sponsorship the way you would do it

x

In mathematics, the absolute value, or modulus (UK), of a number is that number without a negative sign. So, for example, 3 is the absolute value of both 3 and -3.

Table of contents
1 Definition
2 Properties
3 Algorithm

Definition

It can be defined as follows: For any real number a, the absolute value of a (denoted |a|) is equal to a itself if a ≥ 0, and to -a, if a < 0 (see also: inequality). |a| is never negative, as absolute values are always either positive or zero. In other words, the solution to |a| < 0 is that a is equal to the empty set, as there is no quantity which has a negative absolute value.

The absolute value can be regarded as the distance of a number from zero; indeed the notion of distance in mathematics is a generalisation of the properties of the absolute value. It is thus a concept useful to scientists, for whom it serves as a measure of the magnitude of any quantity, whether scalar or vector.

Properties

The absolute value has the following properties:
  1. |a| ≥ 0
  2. |a| = 0 if and only if a = 0.
  3. |ab| = |a||b|
  4. |a/b| = |a| / |b| (if b ≠ 0)
  5. |a+b| ≤ |a| + |b|
  6. |a-b| ≥ ||a| - |b||
  7. |a| ≤ b if and only if -bab

This last property is often used in solving inequalities; for example:
|x - 3| ≤ 9
-9 ≤ x-3 ≤ 9
-6 ≤ x ≤ 12

The absolute value function f(x) = |x| is
continuous everywhere and differentiable everywhere except for x = 0.

For a complex number z = a + ib, one defines the absolute value or modulus to be |z| = √(a2 + b2) = √ (z z*) (see square root and complex conjugate). This notion of absolute value shares the properties 1-6 from above. If one interprets z as a point in the plane, then |z| is the distance of z to the origin.

It is useful to think of the expression |x - y| as the distance between the two numbers x and y (on the real number line if x and y are real, and in the complex plane if x and y are complex). By using this notion of distance, both the set of real numbers and the set of complex numbers become metric spaces.

The operation is not reversible (unless |x|=0) because a negative and a positive number become the same positive number.

Algorithm

If the absolute value would not be a standard function Abs in Pascal it could be easily computed using the following code:

program absolute_value;
var n: integer;
begin
 read (n);
 if n < 0 then n := -n;
 writeln (n)
end.

In the C programming language, the abs(), labs(), llabs() (in C99), fabs(), fabsf(), and fabsl() functions compute the absolute value of an operand. Coding the integer version of the function is trivial:

  1. include
int (abs)(int i) {
   return (i < 0) ? -i : i;
}

The floating-point versions are trickier, as they have to contend with special codes for infinity and not-a-numbers.