Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: add math.pow #836

Closed
wants to merge 16 commits into from
Closed
1 change: 1 addition & 0 deletions src/Neo.Compiler.CSharp/MethodConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4182,6 +4182,7 @@ private bool TryProcessSystemMethods(SemanticModel model, IMethodSymbol symbol,
AddInstruction(OpCode.SIGN);
return true;
case "System.Numerics.BigInteger.Pow(System.Numerics.BigInteger, int)":
case "System.Math.Pow(double, double)":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we haven't got double or float compatibility

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes and no. yes it uses double and neo does not support double. no it is c#, and it compiles and works well. truth is, we can not prevent developer from using double at all, it actually works in neo, c# convert them implecitly into int or other types, we cant prevent it, we cant detect it, we even 'support' it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will do some study on this, maybe ban those key words from source level.

if (arguments is not null)
PrepareArgumentsForMethod(model, symbol, arguments, CallingConvention.StdCall);
AddInstruction(OpCode.POW);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Numerics;

namespace Neo.Compiler.CSharp.UnitTests.TestClasses
{
Expand All @@ -23,5 +24,10 @@ public static int abs(int a)
{
return Math.Abs(a);
}

public static double pow(int a, int b)
{
return Math.Pow(a, b);
}
}
}
22 changes: 22 additions & 0 deletions tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,27 @@ public void abs_test()
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(0, result.Pop().GetInteger());
}

[TestMethod]
public void pow_test()
{
_engine.Reset();
var result = _engine.ExecuteTestCaseStandard("pow", 10, 10);

Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(10000000000, result.Pop().GetInteger());

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("pow", 10, 0);

Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Pop().GetInteger());

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("pow", 100, 1);

Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(100, result.Pop().GetInteger());
}
}
}