-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSYMath.bi
84 lines (70 loc) · 2.03 KB
/
CSYMath.bi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#IFNDEF __CSY_MATH_BI__
#DEFINE __CSY_MATH_BI__
const pi = 3.14159265358979323846
function ceil(Byval Param1 as double) as longint
'Always rounds up
return int(Param1 + .999999999)
end function
function remainder(Byval Param1 as double, Byval Param2 as double) as double
'Returns the remainder of a division.
if Param2 = 0 then
return 1e+300
else
return Param1-(int(Param1/Param2)*Param2)
end if
end function
function exLog(Byval Param1 as double, Byval Param2 as double) as double
'Allows logarithms of any base to be used.
return (log(Param1)/log(Param2))
end function
function commaSep(InValue as longint) as string
dim as string FullStr
dim as byte ExtraCommas
FullStr = str(InValue)
if InValue >= 1000 then
for KID as ubyte = 1 to len(str(InValue))
if KID mod 3 = len(str(InValue)) mod 3 AND KID <= len(str(InValue)) - 3 then
FullStr = left(FullStr,KID+ExtraCommas)+","+right(FullStr,len(FullStr)-KID-ExtraCommas)
ExtraCommas += 1
end if
next KID
end if
return FullStr
end function
function degtorad(Amount as double) as double
return Amount*pi/180
end function
function radtodeg(Amount as double) as double
return Amount*180/pi
end function
function irandom(Minimum as integer, Maximum as integer) as integer
return int(rnd * ((Maximum - Minimum) + 1 - 1e-100)) + Minimum
end function
#IFNDEF max
function max(ValueA as double, ValueB as double) as double
return iif(ValueA > ValueB,ValueA,ValueB)
end function
function min(ValueA as double, ValueB as double) as double
return iif(ValueA > ValueB,ValueB,ValueA)
end function
#ENDIF
function trunc(Amount as double) as integer
if Amount > 0 then
return int(Amount)
else
return -int(-Amount)
end if
end function
function convertIP(InIP as integer) as string
dim as string LongString, ShortString(4), OutString
LongString = str(hex(InIP,8))
for ID as ubyte = 1 to 4
ShortString(ID) = mid(LongString,ID*2-1,2)
if ID > 1 then
OutString += "."
end if
OutString += str(valint("&h"+ShortString(ID)))
next ID
return OutString
end function
#ENDIF