mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-22 13:58:47 +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)
|
||||
|
||||
// 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;
|
||||
for (int i = s.Length - 1; i >= 0; i--) {
|
||||
for (int i = s.Length - 1; i >= 0; i--)
|
||||
{
|
||||
xResult = xResult * 10;
|
||||
int j = Digits.IndexOf(s[i]);
|
||||
if (j == -1) {
|
||||
int j = s[i] - '0';
|
||||
if (j < 0 || j > 9)
|
||||
{
|
||||
throw new Exception("Non numeric digit found in int.parse");
|
||||
}
|
||||
xResult = xResult + j;
|
||||
|
|
|
|||
|
|
@ -14,16 +14,11 @@ namespace Cosmos.System.Plugs.System
|
|||
|
||||
public static double Abs(double value)
|
||||
{
|
||||
double xResult;
|
||||
if (value < 0)
|
||||
{
|
||||
xResult = value - (2 * value);
|
||||
}
|
||||
else
|
||||
{
|
||||
xResult = value;
|
||||
}
|
||||
return xResult;
|
||||
if (value < 0)
|
||||
return -value;
|
||||
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
//public static float Abs(float value)
|
||||
|
|
@ -56,37 +51,34 @@ namespace Cosmos.System.Plugs.System
|
|||
|
||||
public static int Abs(int value)
|
||||
{
|
||||
int xResult;
|
||||
if (value < 0)
|
||||
{
|
||||
xResult = value - (2 * value);
|
||||
}
|
||||
return -value;
|
||||
|
||||
else
|
||||
{
|
||||
xResult = value;
|
||||
}
|
||||
return xResult;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static double Pow(double x, double y)
|
||||
{
|
||||
double xResult = x;
|
||||
{
|
||||
if (y == 0)
|
||||
{
|
||||
xResult = 1;
|
||||
return 1;
|
||||
}
|
||||
else if (y == 1)
|
||||
{
|
||||
xResult = x;
|
||||
return x;
|
||||
}
|
||||
else
|
||||
{
|
||||
double xResult = x;
|
||||
|
||||
for (int i = 2; i <= y; i++)
|
||||
{
|
||||
xResult = xResult * x;
|
||||
}
|
||||
}
|
||||
return xResult;
|
||||
|
||||
return xResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue