mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-24 12:35:31 +00:00
few optimisations
This commit is contained in:
parent
ede6b418c5
commit
c66d8bca19
2 changed files with 23 additions and 28 deletions
|
|
@ -16,12 +16,15 @@ namespace Cosmos.System.Plugs.System {
|
||||||
//at Cosmos.Build.MSBuild.IL2CPU.Execute() in M:\source\Cosmos\source2\Build\Cosmos.Build.MSBuild\IL2CPU.cs:line 250 C:\Program Files (x86)\MSBuild\Cosmos\Cosmos.targets 32 10 Guess (source2\Demos\Guess\Guess)
|
//at Cosmos.Build.MSBuild.IL2CPU.Execute() in M:\source\Cosmos\source2\Build\Cosmos.Build.MSBuild\IL2CPU.cs:line 250 C:\Program Files (x86)\MSBuild\Cosmos\Cosmos.targets 32 10 Guess (source2\Demos\Guess\Guess)
|
||||||
|
|
||||||
// for instance ones still declare as static but add a aThis argument first of same type as target
|
// for instance ones still declare as static but add a aThis argument first of same type as target
|
||||||
public static int Parse(string s) {
|
public static int Parse(string s)
|
||||||
|
{
|
||||||
int xResult = 0;
|
int xResult = 0;
|
||||||
for (int i = s.Length - 1; i >= 0; i--) {
|
for (int i = s.Length - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
xResult = xResult * 10;
|
xResult = xResult * 10;
|
||||||
int j = Digits.IndexOf(s[i]);
|
int j = s[i] - '0';
|
||||||
if (j == -1) {
|
if (j < 0 || j > 9)
|
||||||
|
{
|
||||||
throw new Exception("Non numeric digit found in int.parse");
|
throw new Exception("Non numeric digit found in int.parse");
|
||||||
}
|
}
|
||||||
xResult = xResult + j;
|
xResult = xResult + j;
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,11 @@ namespace Cosmos.System.Plugs.System
|
||||||
|
|
||||||
public static double Abs(double value)
|
public static double Abs(double value)
|
||||||
{
|
{
|
||||||
double xResult;
|
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
{
|
return -value;
|
||||||
xResult = value - (2 * value);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return value;
|
||||||
xResult = value;
|
|
||||||
}
|
|
||||||
return xResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static float Abs(float value)
|
//public static float Abs(float value)
|
||||||
|
|
@ -56,37 +51,34 @@ namespace Cosmos.System.Plugs.System
|
||||||
|
|
||||||
public static int Abs(int value)
|
public static int Abs(int value)
|
||||||
{
|
{
|
||||||
int xResult;
|
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
{
|
return -value;
|
||||||
xResult = value - (2 * value);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return value;
|
||||||
xResult = value;
|
|
||||||
}
|
|
||||||
return xResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double Pow(double x, double y)
|
public static double Pow(double x, double y)
|
||||||
{
|
{
|
||||||
double xResult = x;
|
|
||||||
if (y == 0)
|
if (y == 0)
|
||||||
{
|
{
|
||||||
xResult = 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (y == 1)
|
else if (y == 1)
|
||||||
{
|
{
|
||||||
xResult = x;
|
return x;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
double xResult = x;
|
||||||
|
|
||||||
for (int i = 2; i <= y; i++)
|
for (int i = 2; i <= y; i++)
|
||||||
{
|
{
|
||||||
xResult = xResult * x;
|
xResult = xResult * x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return xResult;
|
||||||
}
|
}
|
||||||
return xResult;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue