瀏覽代碼

Added math examples.

woollybah 6 年之前
父節點
當前提交
a3dced10f0

+ 15 - 0
math.mod/doc/acos.bmx

@@ -0,0 +1,15 @@
+'inverse cosine example
+
+SuperStrict
+
+For Local x:Double = - 1 To 1 Step 0.5
+	Print "Arccos("+x+")="+ACos(x)+" degrees"
+Next
+
+' ===================
+' Output
+' Arccos(-1.0000000000000000)=180.00000000000000 degrees
+' Arccos(-0.50000000000000000)=120.00000000000001 degrees
+' Arccos(0.00000000000000000)=90.000000000000000 degrees
+' Arccos(0.50000000000000000)=60.000000000000007 degrees
+' Arccos(1.0000000000000000)=0.00000000000000000 degrees

+ 15 - 0
math.mod/doc/asin.bmx

@@ -0,0 +1,15 @@
+'inverse sine example
+
+SuperStrict
+
+For Local x:Double = - 1 To 1 Step 0.5
+	Print "ArcSine("+x+")="+ASin(x)+" degrees"
+Next
+
+' ===================
+' Output
+' ArcSine(-1.0000000000000000)=-90.000000000000000 degrees
+' ArcSine(-0.50000000000000000)=-30.000000000000004 degrees
+' ArcSine(0.00000000000000000)=0.00000000000000000 degrees
+' ArcSine(0.50000000000000000)=30.000000000000004 degrees
+' ArcSine(1.0000000000000000)=90.000000000000000 degrees

+ 15 - 0
math.mod/doc/atan.bmx

@@ -0,0 +1,15 @@
+'Inverse Tangent example
+
+SuperStrict
+
+For Local x:Double = -1 To 1 Step 0.5
+	Print "ATan("+x+")="+ATan(x)+" degrees"
+Next
+
+' ===================
+' Output
+' ATan(-1.0000000000000000)=-45.000000000000000 degrees
+' ATan(-0.50000000000000000)=-26.565051177077990 degrees
+' ATan(0.00000000000000000)=0.00000000000000000 degrees
+' ATan(0.50000000000000000)=26.565051177077990 degrees
+' ATan(1.0000000000000000)=45.000000000000000 degrees

+ 18 - 0
math.mod/doc/atan2.bmx

@@ -0,0 +1,18 @@
+'atan2 is a two-argument function that computes the arctangent of y / x 
+'given y And x, but with a range of ( - p,p].
+
+SuperStrict
+
+Graphics 640 , 480
+Local x:Float
+Local y:Float
+Repeat
+	
+	Cls
+	x = MouseX()
+	y = MouseY()
+	DrawLine 320, 240, x, y
+	DrawText "Angle to mouse cursor=" + ATan2(y-240,x-320),10,10
+	Flip
+	
+Until KeyDown(KEY_ESCAPE) Or AppTerminate()

+ 15 - 0
math.mod/doc/atan2_1.bmx

@@ -0,0 +1,15 @@
+'
+' ATan2
+'
+' returns the angle in degrees between two points by giving the width and height between then.
+'
+SuperStrict
+
+Print ATan2(4,4)
+'4^|    / (45 degrees)
+'  |   / 
+'  |  /
+'  | /
+'  |/
+'  +-----
+'       4>

+ 5 - 0
math.mod/doc/ceil.bmx

@@ -0,0 +1,5 @@
+SuperStrict
+
+For Local t:Int=-31 To 31
+	Print "real value: "+t/10.0+" Ceil value: "+Ceil(Double(t/10.0))
+Next

+ 35 - 0
math.mod/doc/ceil_1.bmx

@@ -0,0 +1,35 @@
+SuperStrict
+
+Graphics 640,480
+
+Local x:Int,y:Int
+Local mx:Int,my:Int
+
+HideMouse
+Repeat
+	mx=MouseX()
+	my=MouseY()
+	
+	Cls
+	' draw grid
+	SetColor 90,90,90
+	For y=0 Until 480 Step 20
+		For x=0 Until 640 Step 20
+			Plot x,y
+		Next
+	Next
+	
+	'draw mouse mx,my
+	SetColor 255,255,255
+	DrawRect mx-1,my-1,3,3
+	
+	' draw ceiled and floored mouse mx,my
+	SetColor 255,255,0
+	DrawRect Float(Ceil( mx/20.0)*20-1),Float(Ceil(my/20.0)*20-1),3,3
+	
+	SetColor 0,255,255
+	DrawRect Float(Floor(mx/20.0)*20-1),Float(Floor( my/20.0)*20-1),3,3
+	
+	Flip
+	
+Until KeyDown(KEY_ESCAPE)

+ 12 - 0
math.mod/doc/cos.bmx

@@ -0,0 +1,12 @@
+SuperStrict
+
+'The cosine of 0 degrees is 1
+Print Cos(0)
+
+'The cosine of 90 degrees is 0. Note rounding errors
+Print Cos(90)
+
+' ===================
+' Output
+' 1.0000000000000000
+' 2.6535848171582721e-017

+ 18 - 0
math.mod/doc/cos_1.bmx

@@ -0,0 +1,18 @@
+SuperStrict
+
+Graphics 640,480
+
+SetColor 128,128,128
+DrawRect 0,240,360,1
+
+SetColor 0,255,255
+
+For Local t:Int=0 To 359
+	Plot t,Float(240+Cos(t)*80)
+Next
+
+Flip
+
+Repeat
+	WaitKey()
+Until KeyDown(KEY_ESCAPE)

+ 21 - 0
math.mod/doc/cos_2.bmx

@@ -0,0 +1,21 @@
+'
+' How to draw a 'dotted' flower using Sin/Cos
+'
+SuperStrict
+
+Graphics 640,480
+
+Local radius:Int
+
+SetColor 0,255,255
+
+For Local t:Int=0 To 359 Step 4
+	radius=Sin(t*8)*40+80
+	Plot Float(320+Sin(t)*radius), Float(240+Cos(t)*radius)
+Next
+
+Flip
+
+Repeat
+	WaitKey()
+Until KeyDown(KEY_ESCAPE)

+ 17 - 0
math.mod/doc/cosh.bmx

@@ -0,0 +1,17 @@
+'
+' Cosh Hyperbolic Cosine
+'
+SuperStrict
+
+Graphics 640,480
+
+For Local t:Float = - 7To 7 Step .1
+	SetColor 255,0,0 'red cosh
+	Plot 100 + t * 10 , Float(240 + Cosh(t))
+	SetColor 0,255,255 
+	Plot 200 + t * 10 , Float(240 + Sinh(t))
+Next
+
+Flip
+
+Repeat Until KeyDown(KEY_ESCAPE) Or AppTerminate()

+ 15 - 0
math.mod/doc/exp.bmx

@@ -0,0 +1,15 @@
+'
+' Exponential
+'
+SuperStrict
+
+Graphics 640,480
+
+For Local t:Float = - 7 To 7 Step .1
+	Plot 100 + t * 10 , Float(240 - Exp(t))
+	Print Exp(t)
+Next
+
+Flip
+
+Repeat Until KeyDown(KEY_ESCAPE) Or AppTerminate()

+ 5 - 0
math.mod/doc/floor.bmx

@@ -0,0 +1,5 @@
+SuperStrict
+
+For Local t:Int=-31 To 31
+	Print "real value: "+t/10.0+" Floor value: "+Floor(Double(t/10.0))
+Next

+ 35 - 0
math.mod/doc/floor_1.bmx

@@ -0,0 +1,35 @@
+SuperStrict
+
+Graphics 640,480
+
+Local x:Int,y:Int
+Local mx:Int,my:Int
+
+HideMouse
+Repeat
+	mx=MouseX()
+	my=MouseY()
+	
+	Cls
+	' draw grid
+	SetColor 90,90,90
+	For y=0 Until 480 Step 20
+		For x=0 Until 640 Step 20
+			Plot x,y
+		Next
+	Next
+	
+	'draw mouse mx,my
+	SetColor 255,255,255
+	DrawRect mx-1,my-1,3,3
+	
+	' draw ceiled and floored mouse mx,my
+	SetColor 255,255,0
+	DrawRect Float(Ceil( mx/20.0)*20-1),Float(Ceil(my/20.0)*20-1),3,3
+	
+	SetColor 0,255,255
+	DrawRect Float(Floor(mx/20.0)*20-1),Float(Floor( my/20.0)*20-1),3,3
+	
+	Flip
+	
+Until KeyDown(KEY_ESCAPE)

+ 16 - 0
math.mod/doc/isinf.bmx

@@ -0,0 +1,16 @@
+SuperStrict
+
+For Local f:Float=-0.4 Until 0.4 Step 0.2
+    If IsInf(1.0 / f) = True Then
+       Print "Divide by Zero"
+    Else
+       Print "inverse of "+f+" = "+String(1.0/f)
+    EndIf
+Next
+
+' ===================
+' Output
+' inverse of -0.400000006 = -2.50000000
+' inverse of -0.200000003 = -5.00000000
+' Divide by Zero
+' inverse of 0.200000003 = 5.00000000

+ 18 - 0
math.mod/doc/isinf_1.bmx

@@ -0,0 +1,18 @@
+SuperStrict
+
+For Local f:Float = - 0.4 Until 0.4 Step 0.2
+	If IsInf(Log(f) ) Then
+		Print "Log(" + f + ")=Infinity "+Log(f)
+	Else If IsNan(Log(f) ) Then
+		Print "Log(" + f + ") is not a real number "+Log(f)
+	Else
+		Print "Log(" + f + ")=" + Log(f) 
+   End If
+Next
+
+' ===================
+' Output
+' Log(-0.400000006) is not a real number -1.#IND000000000000
+' Log(-0.200000003) is not a real number -1.#IND000000000000
+' Log(0.000000000)=Infinity -1.#INF000000000000
+' Log(0.200000003)=-1.6094378975329393

+ 16 - 0
math.mod/doc/isnan.bmx

@@ -0,0 +1,16 @@
+SuperStrict
+
+For Local f:Float=-0.4 Until 0.4 Step 0.2
+    If IsNan(Sqr(f)) = True Then
+       Print "Square Root of "+f+" is not a real number"
+    Else
+       Print "Square Root of  "+f+" = "+Sqr(f)
+    EndIf
+Next
+
+' ===================
+' Output
+' Square Root of -0.400000006 is not a real number
+' Square Root of -0.200000003 is not a real number
+' Square Root of  0.000000000 = 0.00000000000000000
+' Square Root of  0.200000003 = 0.44721359883195888

+ 18 - 0
math.mod/doc/isnan_1.bmx

@@ -0,0 +1,18 @@
+SuperStrict
+
+For Local f:Float = - 0.4 Until 0.4 Step 0.2
+	If IsInf(Log(f) ) Then
+		Print "Log(" + f + ")=Infinity "+Log(f)
+	Else If IsNan(Log(f) ) Then
+		Print "Log(" + f + ") is not a real number "+Log(f)
+	Else
+		Print "Log(" + f + ")=" + Log(f) 
+   End If
+Next
+
+' ===================
+' Output
+' Log(-0.400000006) is not a real number -1.#IND000000000000
+' Log(-0.200000003) is not a real number -1.#IND000000000000
+' Log(0.000000000)=Infinity -1.#INF000000000000
+' Log(0.200000003)=-1.6094378975329393

+ 18 - 0
math.mod/doc/log.bmx

@@ -0,0 +1,18 @@
+SuperStrict
+
+For Local f:Float = - 0.4 Until 0.4 Step 0.2
+	If IsInf(Log(f) ) Then
+	Print "Log(" + f + ")=Infinity "+Log(f)
+	Else If IsNan(Log(f) ) Then
+		Print "Log(" + f + ") is not a real number "+Log(f)
+	Else
+		Print "Log(" + f + ")=" + Log(f) 
+   End If
+Next
+
+' ===================
+' Output
+' Log(-0.400000006) is not a real number -1.#IND000000000000
+' Log(-0.200000003) is not a real number -1.#IND000000000000
+' Log(0.000000000)=Infinity -1.#INF000000000000
+' Log(0.200000003)=-1.6094378975329393

+ 19 - 0
math.mod/doc/log10.bmx

@@ -0,0 +1,19 @@
+SuperStrict
+
+For Local f:Float = - 0.4 Until 0.41 Step 0.2
+	If IsInf(Log10(f) ) Then
+	Print "Log10(" + f + ")=Infinity "+Log10(f)
+	Else If IsNan(Log10(f) ) Then
+		Print "Log10(" + f + ") is not a real number "+Log10(f)
+	Else
+		Print "Log10(" + f + ")=" + Log10(f) 
+   End If
+Next
+
+' ===================
+' Output
+' Log10(-0.400000006) is not a real number -1.#IND000000000000
+' Log10(-0.200000003) is not a real number -1.#IND000000000000
+' Log10(0.000000000)=Infinity -1.#INF000000000000
+' Log10(0.200000003)=-0.69896999786452674
+' Log10(0.400000006)=-0.39794000220054560

+ 12 - 0
math.mod/doc/sin.bmx

@@ -0,0 +1,12 @@
+SuperStrict
+
+'The sine of 0 degrees is 0
+Print Sin(0)
+
+'The sine of 90 degrees is 1
+Print Sin(90)
+
+' ===================
+' Output
+' 0.00000000000000000
+' 1.0000000000000000

+ 18 - 0
math.mod/doc/sin_1.bmx

@@ -0,0 +1,18 @@
+SuperStrict
+
+Graphics 640,480
+
+SetColor 128,128,128
+DrawRect 0,240,360,1
+
+SetColor 0,255,255
+
+For Local t:Int=0 To 359
+	Plot t,Float(240+Sin(t)*80)
+Next
+
+Flip
+
+Repeat
+	WaitKey()
+Until KeyDown(KEY_ESCAPE)

+ 17 - 0
math.mod/doc/sin_2.bmx

@@ -0,0 +1,17 @@
+SuperStrict
+
+Graphics 640,480
+
+Local radius:Int=80
+
+SetColor 0,255,255
+
+For Local t:Int=0 To 359 Step 4
+	Plot Float(320+Sin(t)*radius), Float(240+Cos(t)*radius)
+Next
+
+Flip
+
+Repeat
+	WaitKey()
+Until KeyDown(KEY_ESCAPE)

+ 14 - 0
math.mod/doc/sinh.bmx

@@ -0,0 +1,14 @@
+'
+' Sinh Hyperbolic Sine
+'
+SuperStrict
+
+Graphics 640,480
+
+For Local t:Float=-7To 7 Step .1
+	Plot 100+t*10,Float(240+Sinh(t))
+Next
+
+Flip
+
+Repeat Until KeyDown(KEY_ESCAPE) Or AppTerminate()

+ 17 - 0
math.mod/doc/sqr.bmx

@@ -0,0 +1,17 @@
+'IsNan (Not a Number)
+SuperStrict
+
+For Local f:Float=-0.4 Until 0.4 Step 0.2
+    If IsNan(Sqr(f)) = True Then
+       Print "Square Root of "+f+" is not a real number"
+    Else
+       Print "Square Root of  "+f+" = "+Sqr(f)
+    EndIf
+Next
+
+' ===================
+' Output
+' Square Root of -0.400000006 is not a real number
+' Square Root of -0.200000003 is not a real number
+' Square Root of  0.000000000 = 0.00000000000000000
+' Square Root of  0.200000003 = 0.44721359883195888

+ 15 - 0
math.mod/doc/tan.bmx

@@ -0,0 +1,15 @@
+SuperStrict
+
+For Local x:Double = 0 To 180 Step 30
+	Print "Tan("+x+" degrees)="+Tan(x)
+Next
+
+' ===================
+' Output
+' Tan(0.00000000000000000 degrees)=0.00000000000000000
+' Tan(30.000000000000000 degrees)=0.57735026918962573
+' Tan(60.000000000000000 degrees)=1.7320508075688767
+' Tan(90.000000000000000 degrees)=16331778728383844.
+' Tan(120.00000000000000 degrees)=-1.7320508075688783
+' Tan(150.00000000000000 degrees)=-0.57735026918962573
+' Tan(180.00000000000000 degrees)=-1.2246063538223773e-016

+ 16 - 0
math.mod/doc/tanh.bmx

@@ -0,0 +1,16 @@
+'
+' Tanh Hyperbolic Cosine
+'
+SuperStrict
+
+Graphics 640,480
+
+For Local t:Float = -.2 To .2 Step .001
+	SetColor 255,0,0 'red cosh
+	Plot 100 + t * 500 , Float(240 + Tanh(t)*500)
+Print t*500+":"+Tanh(t)*500
+Next
+
+Flip
+
+Repeat Until KeyDown(KEY_ESCAPE) Or AppTerminate()