Repository navigation
Expand file tree
/
Copy pathCustomMathLibrary.cs
More file actions
130 lines (114 loc) · 3.64 KB
/
Copy pathCustomMathLibrary.cs
File metadata and controls
130 lines (114 loc) · 3.64 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System.Diagnostics;
//If you are NOT using Unity, adjust it.
namespace Common
{
public static class CustomMath
{
public static float LimitFloat(float min, float value, float max) // x < y < z
{
if (value < min) { value = min; return value; }
if (value > max) { value = max; return value; }
return value;
}
public static int LimitInt(int min, int value, int max) // x < y < z
{
if (value < min) { value = min; return value; }
if (value > max) { value = max; return value; }
return value;
}
public static int AddInt(params int[] numbers)
{
int result = 0;
foreach (int intnumber in numbers) { result += intnumber; }
return result;
}
public static float AddFloat(params float[] numbers)
{
float result = 0f;
foreach (float floatnum in numbers) { result += floatnum; }
return result;
}
public static int SubInt(params int[] numbers)
{
int result = numbers[0];
foreach (int intnumber in numbers) { result -= intnumber; }
return result;
}
public static float SubFloat(params float[] numbers)
{
float result = numbers[0];
foreach (float floatnum in numbers) { result -= floatnum; }
return result;
}
public static int MultiInt(params int[] numbers)
{
int result = 1;
foreach (int intnumber in numbers) { result *= intnumber; }
return result;
}
public static float MultiFloat(params float[] rudiismyidol)
{
float result = 1;
foreach (float number in rudiismyidol) { result *= number; }
return result;
}
public static int PowerInt(int value, int uppernumber) //Limit = 2^31 = 0x80000000
{
int result = 1;
for (int i = 0; i < uppernumber; i++)
{
result *= value;
}
return result;
}
public static float PowerFloat(float value, float uppernumber) //0x4F000000
{
float result = 1f;
for (float i = 0; i < uppernumber; i++)
{
result *= value;
}
return result;
}
public static float DivisionFloat(float Dividend, float Divisor)
{
if (Divisor == 0f)
{
Console.WriteLine("Divisor cannot be 0");
return 0f;
}
return Dividend / Divisor;
}
public static int DivisionInt(int Dividend, int Divisor)
{
if (Divisor == 0)
{
Console.WriteLine("Divisor cannot be 0");
return 0;
}
return Dividend / Divisor;
}
public static int Absolute(int value)
{
if (value < 0)
{
return value *= -1;
}
return value;
}
public static float AbsoluteFloat(float value)
{
if (value < 0)
{
return value *= -1;
}
return value;
}
public static float Average(params float[] numbers)
{
if (numbers.Length == 0) return 0f;
float total = AddFloat(numbers);
return total / numbers.Length;
}
}
}