Math.abs( ) Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Math.abs( ) Method Flash 5; can be used when exporting Flash 4 movies

compute the absolute value of a number
Math.abs(x)

Arguments

x

Any integer or floating-point number.

Returns

The absolute value of x (a positive number of magnitude x).

Description

The abs( ) method calculates the distance between x and 0 (i.e., the absolute value of x). It leaves zero and positive numbers unchanged and converts negative numbers into positive numbers of the same magnitude. It is useful for calculating the difference between two numbers without regard to which is larger. For example, it is useful when calculating the distance between two points, because distances are always positive.

Example

Math.abs(-5);  // Returns 5     // Calculate the difference between two numbers function diff (num1, num2) {    return Math.abs(num1-num2); }     diff(-5, 5);  // Returns 10


    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net