main print math.e // LOG: 2.71828182856552302837371826171875
Math includes trigonometrical functions as well as other mathematical functions.
Return the mathematical constant e = 2.71828?18..., which is the base of the natural logarithm and also called Euler's number. Since e is irrational, or infinite, its value cannot be given exactly but truncated to our fixed.
main print math.e // LOG: 2.71828182856552302837371826171875
Return the mathematical constant pi = 3.1415863... whose value is the ratio of a circle's area to the square of its radius. Pi is an irrational number, which means that its value cannot be expressed exactly but rounded to our fixed.
main print math.pi // LOG: 3.14159265370108187198638916015625
Return the sine of an angle 'f'.
main fixed f f = math.sin 0.0 print f // LOG: 0.0 f = math.sin (math.pi / 8.0) print f // LOG: 0.3826834261417388916015625 f = math.sin (math.pi / 4.0) print f // LOG: 0.707106769084930419921875 f = math.sin (math.pi / 2.0) print f // LOG: 1.0 f = math.sin math.pi print f // LOG: 0.0 f = math.sin (3.0 * math.pi / 2.0) print f // LOG: -1.0
Return the cosine of an angle 'f'.
main fixed f f = math.cos 0.0 print f // LOG: 1.0 f = math.cos (math.pi / 4.0) print f // LOG: 0.707106769084930419921875 f = math.cos (math.pi / 2.0) print f // LOG: 0.0 f = math.cos math.pi print f // LOG: -1.0 f = math.cos (2.0 * math.pi) print f // LOG: 1.0
Return the tangent of an angle 'f'.
main
fixed f
f = math.tan 0.0
print f // LOG: 0.0
f = math.tan (math.pi / 4.0)
print f // LOG: 1.0
f = math.tan (math.pi / 3.0)
print f // LOG: 1.7279674732126295566558837890625
try
math.tan (math.pi / 2.0)
catch throwable t
print "Catched" // LOG: Catched
Return the angle whose sine is 'f'. In trigonometry this is defined as the arc sine i.e. the inverse function of sine.
main fixed f f = math.asin -1.0 print f // LOG: -1.570796326734125614166259765625 (-pi/2) f = math.asin -0.5 print f // LOG: -0.52359877526760101318359375 f = math.asin 0.0 print f // LOG: 0.0 f = math.asin 0.5 print f // LOG: 0.52359877526760101318359375 f = math.asin 1.0 print f // LOG: 1.570796326734125614166259765625 (pi/2)
Return the angle whose cosine is 'f'. In trigonometry this is defined as the arc cosine i.e. the inverse function of cosine.
main fixed f f = math.acos -1.0 print f // LOG: 3.14159265346825122833251953125 (pi) f = math.acos -0.5 print f // LOG: 2.094395102001726627349853515625 (3.0*pi/2.0) f = math.acos 0.0 print f // LOG: 1.570796326734125614166259765625 (pi/2.0) f = math.acos 0.5 print f // LOG: 1.047197551466524600982666015625 (pi/4.0) f = math.acos 1.0 print f // LOG: 0.0
Return the angle whose tangent is 'f'. In trigonometry this is defined as the arc tangent i.e. the inverse function of tangent.
main fixed f f = math.atan (fixed.minimum value + 1.0) print f // LOG: -1.570796326734125614166259765625 (-pi/2) v = math.atan 0.0 print v // LOG: 0.0 v = math.atan (fixed.maximum value - 1.0) print v // LOG: 1.570796326734125614166259765625 (pi/2)
Return the angle 'f' as radians.
main f = math.degrees 45.0 to radians print f // LOG: 0.78539810865186154842376708984375 (pi/8) f = math.degrees -180.0 to radians print f // LOG: -3.14159267791546881198883056640625 (-pi)
Return the angle 'f' as degrees.
main f = math.radians math.pi/2.0 to degrees print f.as string with 1 decimals // LOG: 90.0 f = math.radians -math.pi to degrees print f.as string with 1 decimals // LOG: -180.0
Return a random number between 'min' and 'max'.
main
// Example 1
int v = math.get random int from 2 to 10
print v // LOG: 8
// Example 2 - Let's check how even the distribution is
// 1) Generte randoms integers in a table
int[] iv = new int[] from 0 size 10
int i = 0
while i < 1000
v = math.get random int from 0 to 9
iv[v]++
i++
// 2) Print the distribution as a percentage of occurrences
i = 0
while i < 10
fixed f = iv[i] / 10.0
print f.as string with 1 decimals & "% had value " & i
i++
// LOG: 10.8% had value 0
// LOG: 10.9% had value 1
// LOG: 10.8% had value 2
// LOG: 8.4% had value 3
// LOG: 11.4% had value 4
// LOG: 8.5% had value 5
// LOG: 10.1% had value 6
// LOG: 8.4% had value 7
// LOG: 11.2% had value 8
// LOG: 9.5% had value 9
Return a random number between 'min' and 'max'.
main fixed f = math.get random fixed from 5.5 to 5.6 print f // LOG: 5.50030628661625087261199951171875
Return the minimum of 'a' and 'b'.
main byte a byte b a = 5.truncate b = 2.truncate byte min = math.min a, b print min // LOG: 2 a = (-1).truncate b = 13.truncate min = math.min a, b print min // LOG: -1 a = byte.minimum value b = byte.maximum value min = math.min a, b print min // LOG: -128
Return the minimum of 'a' and 'b'.
main int a int b a = 5 b = 2 int min = math.min a, b print min // LOG: 2 a = -1 b = 13 min = math.min a, b print min // LOG: -1 a = int.minimum value b = int.maximum value min = math.min a, b print min // LOG: -2147483648
Return the minimum of 'a' and 'b'.
main fixed a fixed b a = 5.3554 b = 5.3555 fixed min = math.min a, b print min // LOG: 5.3553999997675418853759765625 a = -1.13 b = -1.47 min = math.min a, b print min // LOG: -1.46999999997206032276153564453125 a = fixed.minimum value b = fixed.maximum value min = math.min a, b print min // LOG: -2147483648.0
Return the maximum of 'a' and 'b'.
main byte a byte b a = 2.truncate b = 5.truncate byte max = math.max a, b print max // LOG: 5 a = (-1).truncate b = (-13).truncate max = math.max a, b print max // LOG: -1 a = byte.minimum value b = byte.maximum value max = math.max a, b print max // LOG: 127
Return the maximum of 'a' and 'b'.
main int a int b a = 2 b = 5 int max = math.max a, b print max // LOG: 5 a = -1 b = -1000 max = math.max a, b print max // LOG: -1 a = int.minimum value b = int.maximum value max = math.max a, b print max // LOG: 2147483647
Return the maximum of 'a' and 'b'.
main fixed a fixed b a = 5.3554 b = 5.3555 fixed max = math.max a, b print max // LOG: 5.35549999983049929141998291015625 a = -1.13 b = -1.47 max = math.max a, b print max // LOG: -1.129999999888241291046142578125 a = fixed.minimum value b = fixed.maximum value max = math.max a, b print max // LOG: 2147483647.99999999976716935634613037109375
Return the the natural logarithm of 'f'.
main
fixed f
f = math.ln 0.1
print f // LOG: -2.30258509353734552860260009765625
f = math.ln 1.0
print f // LOG: 0.0
f = math.ln 100.0
print f // LOG: 4.6051701842807233333587646484375
// Natural logarithm grows exponentially slow
f = math.ln fixed.maximum value
print f // LOG: 21.48756259121000766754150390625
try
math.ln 0.0
catch throwable t
print "Catced" // LOG: Catched
Return logarithm for value 'f' with base 'base'
main fixed f f = math.log 25.0 base 5.0 print f // LOG: 2.0 f = math.log 100.0 base 10.0 print f // LOG: 2.0 f = math.log 1000.0 base 10.0 print f // LOG: 3.0 f = math.log 9.0 base 3.0 print f // LOG: 2.0 f = math.log 256.0 base 2.0 print f // LOG: 8.0 f = math.log 5.0 base 25.0 print f // LOG: 0.5 f = math.log 1.0 base 12345.0 print f // LOG: 0.0 // Note that ln 10 == log 10 base math.e f = math.log 10.0 base math.e print f // LOG: 2.3025850928388535976409912109375 f = math.ln 10.0 print f // LOG: 2.30258509214036166667938232421875
Return the the square root of 'f'.
main fixed f f = math.sqrt 0.0 print f // LOG: 0.0 f = math.sqrt 1.0 print f // LOG: 1.0 // Note the slight inaccuracy f = math.sqrt 9.0 print f // LOG: 2.99999999930150806903839111328125 (3.0) f = math.sqrt 0.64 print f // LOG: 0.799999999813735485076904296875 (0.8)