Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Negative numbers and absolute value


1. Negative numbers and absolute value

2. Math: Negative numbers
A negative number is often used as either a mathematical convenience or as a way to represent the direction of flow.

Fact: Absolute negative numbers do not exist in the real world.


You can never look into a field of grazing cows and see a negative cow.

If you get a negative number representing a concrete object, something is wrong.

3. Concrete objects
Negative numbers can be used to indicate direction, such as However the physical water, money, or whatever, must always be a nonnegative quantity.

4. Absolute negative numbers
Absolute negative numbers do not exist in the real world. In general, negative numbers are used for the following.

5. Math: Absolute value
One meaning of the term absolute is not changing.

Negative numbers do not exist in the real world (reality).

But negative numbers can be used to indicate direction, etc.

The absolute value of a negative number is the positive value of that negative number (e.g., without the direction, etc.). In math, the absolute value of an integer is the positive (unchanging) value of that integer. So, In math notation, the absolute value is indicated using vertical bars around the quantity.
   | +1 | = 1    | 0 | = 0    | -1 | = 1


6. Example code
The following program inputs an integer value and then outputs the absolute value of that value. Here is the C code.


7. Examples of input and output
Here are some examples of input and output for the above program code.

Here is an example input.

For the above example input, here is the expected output.

Here is an example input.

For the above example input, here is the expected output.

Here is an example input.

For the above example input, here is the expected output.


8. Data flow programming
In data flow programming, or functional programming, it is best never to change a variable value once it is given a value (e.g., via input or assignment) since the destructive update of a memory location is a source of many programming errors.

This is not always possible (unless using functional programming techniques) but is a goal. In the above code, rather then change variable i1 to the absolute value of i1, a new variable, i2, is used.

9. Programming comparisons
In imperative, or command-based, programming (such as in C), there are commands for destructive update of variables.

In (pure) functional programming systems, variables cannot be changed once assigned a value.

10. End of page

11. Multiple choice questions for this page