If you think back to those days at school when you were up to your neck in trigonometry and calculus,
you will probably remember having to use a scientific calculator in order to work out the tough math
questions involving scary math functions such as sine and cosine. In haXe, all such math functions are
stored in the Math class.
Fortunately, this book is not a math textbook, so much of the math theory will be left out of this chapter,
but it will show you some of the more common methods of the Math class, so you at least have some
grounding with which to work. Table 3 - 9 details the methods of the Math class.
Table 3-9
Math Field Description
NEGATIVE_INFINITY : Float Property representing a negative `divide by zero`
NaN : Float Property representing `Not a Number`
PI : Float Property representing the value of Pi
POSITIVE_INFINITY : Float Property representing a positive `divide by zero`
Table continued on following page
Part I: The Core Language
64
Math Field Description
abs(value : Float) : Float Makes a negative number into a positive number
acos(value : Float) : Float Returns the arc cosine of an angle specified in radians
asin(value : Float) : Float Returns the arc sine of an angle specified in radians
atan(value : Float) : Float Returns the arc tangent of an angle specified in radians
atan2(value1 : Float, value2 :
Float) : Float
Returns the angle of the point x / y in radians
ceil(value : Float) : Int Rounds a value up to the nearest integer
cos(value : Float) : Float Returns the cosine of an angle specified in radians
exp(value : Float) : Float Returns the base of the natural logarithm to the power of
the supplied float
floor(value : Float) : Int Rounds a value down to the nearest integer
isFinite(value : Float) : Bool Returns true if a value is not equal to POSITIVE_
INFINITY or NEGATIVE_INFINITY, otherwise false is
returned
isNaN(value : Float) : Bool Returns true if the passed value is ???Not a Number??™
(Nan)
log(value : Float) : Float Finds the logarithm of a number
max(value1 : Float, value2 :
Float) : Float
Returns the largest of two numbers
min(value1 : Float, value2 :
Float) : Float
Returns the smallest of two numbers
pow(value1 : Float, value2 :
Float) : Float
Raises the first value to the power of the second
random() : Float Returns a random floating value between 0 and 1
round(value : Float) : Int Rounds a value to the nearest integer
sin(value : Float) : Float Returns the sine of an angle specified in radians
sqrt(value : Float) : Float Returns the square root of a float
tan(value : Float) : Float Returns the tangent of an angle specified in radians
Divide by Zero Conundrum
When working with numbers in haXe, you ??™ re likely to hit a few snags that even the most seasoned
developers meet from time to time.
Pages:
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161