# Microsoft Small Basic

Program Listing: LNV725
' SmallBasic Version 1.2
' Program: Math_Functions (.sbsub)
' Changelog:
' Author: Nonki Takahashi
' Website: https://social.msdn.microsoft.com/Forums/en-US/95706095-0984-40d7-897f-0ec14ed58039/small-basic-subroutine-library-project
' https://gist.github.com/nonkit/e898af0f9f79726a6fba4a64d02a3a71
' ImportURL: http://smallbasic.com/program/?
' SBOnline: http://smallbasic-publicwebsite-dev.azurewebsites.net/Program/view.aspx?
' Extension:
' Comment: SmallBasicCompiler.exe Math_Functions.sb -> Math_Functions.exe
' -> rename Math_Functions.exe to Math_Functions.sbsub
' Variables:
' ToDo:
' ==============================================================================
x = "" ' or _x
y = "" ' or _y

_r = ""
_a = ""

' //////////////////// SUBs ////////////////////
Sub Math_CartesianToPolar
' Math | convert Cartesian coodinate to polar coordinate
' param x, y - Cartesian coordinate
' return _r, _a - polar Coordinate (0<=a<360)
_r = Math.SquareRoot(x * x + y * y)
If x = 0 And y > 0 Then
_a = 90 ' [degree]
ElseIf x = 0 And y < 0 Then
_a = -90
ElseIf x = 0 And y = 0 Then
_a = 0
Else
_a = Math.ArcTan(y / x) * 180 / Math.Pi
EndIf
' at this point -90<=_a<=90
If x < 0 Then
_a = _a + 180
ElseIf x >= 0 And y < 0 Then
_a = _a + 360
EndIf
' at this point 0<=_a<360
EndSub