BlitzMax/Modules/Math/Math

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Functions[edit | edit source]

IsNan[edit | edit source]

Function IsNan( x:Double )

Description: Check if a value is NAN

Returns: True if x is 'not a number' (e.g.: Sqr(-1))

Example:

Local a:Float = Sqr(-1)

Local b:Int = IsNan(a)	'b will equal True in this example, because the square root of -1 is 'not a number'

IsInf[edit | edit source]

Function IsInf( x:Double )

Description: Check if a value is infinite (e.g.: 1.0/0.0)

Returns: True if x is infinite

Example:

Local a:Float = 1.0 / 0.0

Local b:Int = IsInf(a)	'b will equal True in this example, because 1.0 divided by 0.0 is infinite

Sqr[edit | edit source]

Function Sqr:Double( x:Double )

Description: Square root of x

Example:

Local a:Int = 4
Local b:Int = Sqr(a)

Sin[edit | edit source]

Function Sin:Double( x:Double )

Description: Sine of x degrees

Cos[edit | edit source]

Function Cos:Double( x:Double )

Description: Cosine of x degrees

Tan[edit | edit source]

Function Tan:Double( x:Double )

Description: Tangent of x degrees

ASin[edit | edit source]

Function ASin:Double( x:Double )

Description: Inverse Sine of x

Comments: The inverse sine can determine the remaining angles of a right triangle when the lengths of the sides are known. For instance, an angle may be calculated using the length of the opposite side and the hypotenuse.

Example:

Local alpha:Double = ASin(length_opposite / length_hypotenuse)

ACos[edit | edit source]

Function ACos:Double( x:Double )

Description: Inverse Cosine of x

Comments: The inverse cosine can determine the remaining angles of a right triangle when the lengths of the sides are known. For instance, an angle may be calculated using the length of the adjacent side and the hypotenuse.

Example:

Local alpha:Double = ACos(length_adjacent / length_hypotenuse)

ATan[edit | edit source]

Function ATan:Double( x:Double )

Description: Inverse Tangent of x

Comments: The inverse tangent can determine the remaining angles of a right triangle when the lengths of the sides are known. For instance, an angle may be calculated using the length of the opposite side and the adjacent side.

Example:

Local alpha:Double = ATan(length_opposite / length_adjacent)

ATan2[edit | edit source]

Function ATan2:Double( y:Double,x:Double )

Description: Inverse Tangent of two variables x , y

Comments: ATan2 is similar to ATan. However, it makes use of the two arguments signs to determine the angle of a imaginary vector (x,y) relatively to the x-axis (counterclockwise). This is very useful, for example in determining the direction from one point to another.

Example:

Local ax:Float = -1, ay:Float =- 2	'Point A
Local bx:Float = 3, by:Float = 2	'Point B

'Notice how the variables we are using are Float's, BlitzMax will automatically
'convert them into Double's when we call ATan2()
Local angle:Float = ATan2(by - ay, bx - ax)	'Angle from A to B

Sinh[edit | edit source]

Function Sinh:Double( x:Double )

Description: Hyperbolic sine of x

Cosh[edit | edit source]

Function Cosh:Double( x:Double )

Description: Hyperbolic cosine of x

Tanh[edit | edit source]

Function Tanh:Double( x:Double )

Description: Hyperbolic tangent of x

Exp[edit | edit source]

Function Exp:Double( x:Double )

Description: Exponential function

Log[edit | edit source]

Function Log:Double( x:Double )

Description: Natural logarithm

Log10[edit | edit source]

Function Log10:Double( x:Double )

Description: Base 10 logarithm

Ceil[edit | edit source]

Function Ceil:Double( x:Double )

Description: Smallest integral value not less than x

Floor[edit | edit source]

Function Floor:Double( x:Double )

Description: Largest integral value not greater than x

Comments: Ceil() will round a variable up, whereas Floor() will round it down.

Example:

Local a:Float = 3.5

Local round_up:Float = Ceil(a)		'Becomes 4.0
Local round_down:Float = Floor(a)	'Becomes 3.0