Hundred Days Society FLASH AS3.0-- Mathematical Functions

Math.abs () calculate the absolute value.
Math.acos () computes the inverse cosine.
Math.asin () calculated radians.
Math.atan () calculation of arctangent.
Math.atan2 () calculated from the x axis the point of view.
Math.ceil () to figure rounded up to the nearest whole number.
Math.cos () calculated cosine.
Math.exp () calculated index value.
Math.floor () will be the number rounded down to the nearest whole number.
Math.log () calculated the natural logarithm.
Math.max () returns the larger of two integers a.
Math.min () returns the smaller of two integers.
Math.pow () calculated the y x th power.
Math.random () returns a between 0.0 and 1.0, pseudo-random number.
Math.round () rounded to the nearest whole number.
Math.sin () calculation of sine.
Math.sqrt () calculate the square root.
Math.tan () calculated tangent.

1, Math.abs () formula for calculating the absolute value, then what is the absolute value of it? This should not be a problem, we all know the number of positive and negative numbers, we calculated the results also have positive and negative, this function to negative values into positive values, while positive values unchanged. We can verify this by the following statement:

x = 5

y =- 5

x = Math.abs (x)

trace (x)

/ / Output 5

y = Math.abs (y)

trace (y)

/ / Output 5

2, Math.ceil () to obtain a specified number or expression of the maximum integer value, which is higher than that specified number of large integer. Piece of code can be verified by the following:

x = 5.45
x = Math.ceil (x)
trace (x) / / output 6

Note that for negative, is the greater absolute value, the smaller the value, so use the Math.ceil () to obtain the integer value is that a number of absolute value smaller than that of negative integers. The following code illustrates:

x =- 5.45
x = Math.ceil (x)
trace (x) / / output -5

3, Math.floor () This function Math.ceil () is just the opposite, get a number or expression of a lower integer value, thus obtaining the integer value is smaller than that specified by an integer number. Note: negative numbers quickly adapt and Math.ceil () to quickly adapt the same, just to get a large absolute value of an integer. Can verify the following:

x = 5.45
x = Math.floor (x)
trace (x) / / output 5

x =- 5.45
x = Math.floor (x)
trace (x) / / output -6

4, Math.round () method used by this function should be our most familiar, and rounded, and an expression or figure to obtain the nearest integer. We look at the code to test ~!

x = 5.45
x = Math.round (x)
trace (x) / / output 5

x =- 5.45
x = Math.round (x)
trace (x) / / output -5

x =- 5.55
x = Math.round (x)
trace (x) / / output -6

But here found a problem to your attention, if

x = 5.50
x = Math.round (x)
trace (x) / / output 6

However, if x =- 5.50

x =- 5.50
x = Math.round (x)
trace (x) / / output -5 need to take note ~!

5, Math.random () random function, to obtain a range between 0 and 1, a number 0 <= x <1 such a number of decimal places as a decimal 14. Use, he could get some different digit figures. Here we use him and we have studied the above function, for a random four-digit.

x = Math.random ()
x = 10000 * x
x = Math.round (x)
trace (x) / / output 4478

Of course, flash is also providing a random function random (value), he could get a random integer, the integer between 0 and value-1 an integer between, on its use, is available online a detailed description no more was said here, the following piece of code used to verify what ~!

x = random (5)
trace (x)
/ / Output, 0,1,2,3,4 a value into any ~

6, Math.max () two numbers or expressions in the calculation of the maximum value, and returns this value.

x = Math.max (5,4)
trace (x) / / output 5
x = 10
y = 20
x = Math.max (x, y)
trace (x) / / output is 20

7, Math.min () returns the smallest two numbers, or a value expression

x = Math.min (5,4)
trace (x) / / output 4
x = 10
y = 20
x = Math.min (x, y)
trace (x) / / output 10

8, Math.pow () parameter x, y using the Math.pow (x, y) x, y th power calculation, calculation of results returned.

x = Math.pow (2,3) / / calculate 2 3 power
trace (x) / / output 8
x = 3
y = 4
z = Math.pow (x, y) / / calculate x, y-th power
trace (z) / / output 81

9, Math.sqrt () calculating a number or an expression of the square root, Note that the expression should be a number greater than or equal to 0.

x = Math.sqrt (2) / / 2 of the 3 power calculation
trace (x) / / output 1.4142135623731
x = 3
x = Math.sqrt (x) / / calculate x, y-th power
trace (x) / / output 1.73205080756888

分类:Flash 时间:2010-07-08 人气:185
分享到:
blog comments powered by Disqus

相关文章

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.395 (s). 12 q(s)