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
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Hundred Days Society FLASH AS3.0-- Mathematical Functions

  • AXIS Project

    apache soap is the first implementation of the soap norms, it was originally developed by IBM (later called soap4j, was later handed over to the apache, it is a very outdated SOAP implementation. it places great emphasis on WSDL, it supports rpc / en ...

  • Eclipse + axis2 + tomcat5.5 development webservice

    Originality for this article Drinking java For reprint please specify the source of First, the environment preparation 1.1 software download ready Tomcat 5.5 download address: # 5.5.20 Axis

  • javascript to avoid the floating-point bug Ways (reprint, provenance unknown)

    Recently, at a wage to do the accounting system, all at the Front Desk for all computing, it is used JS to do. After finishing, the accounting manual and found a strange problem. JS is the result calculated with the use of calculators has calculated ...

  • addSizes.js self-tagging links the size of the file

    addSizes.js self-tagging links the size of the file addSizes.js is a JS code for the link from a page where a number of large files, and automatically link in their mark next to File Size. Its authors are Nathalie Downe, applied Simon Willison's ...

  • 40 lightweight JavaScript library (b)

    COMSHARP CMS Wrote, "too numerous to mention popular JavaScript libraries, jQuery, MooTools, Prototype, Dojo, YUI. These feature-rich JavaScript library, combined with their plug-in, capable of performing almost any job, but it is there is a price, a

  • Note: careful with the use of javascript's parseInt () function!

    Used by the company are a set of antique-class R & D framework of their own, saying that he antiques, because she was born in 2002. In a variety of reasons, the framework has not been replaced, as long as we in charge of the project has been used by h

  • javascript in the form (table) to operate

    javascript in the form (table) to operate

  • Eclipse plug-in projects cited external JAR package to resolve a null pointer abnormal

    Eclipse plug-in projects cited external JAR package to resolve a null pointer abnormal

  • AJAX file upload progress of implementation of control

    dhtmlXVault User's Guide 1 Top 2 Step 13:33 Browser (41) Comments (0) Categories: ajax Related recommend Comments Comment yinxiangbing View: 1143 times Gender: From: Beijing Details book Search this blog Recent visitors xieqinghua yh_private Sky ...

  • JS charts extjs implementation tools can be combined

    OpenFlashChart brief introduction by valensoft 2009-1-10 8:29:00 OpenFlashChart is an open source Flash and Javascript to the technical foundation for the free chart, using it to create some very useful analysis of the effect of the statements of the char

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries