-
Notifications
You must be signed in to change notification settings - Fork 102
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
Closed
Add: add math.pow #836
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a8bf28c
add math.pow
Jim8y 7e2a289
add UT
Jim8y 4e59d26
Merge branch 'master' into math.pow
Jim8y a657696
Merge branch 'master' into math.pow
Jim8y 38a3eea
add Math of our own
Jim8y 4dbe5fc
Merge branch 'master' into math.pow
Jim8y 9029232
add UT tests
Jim8y b9750bf
Merge branch 'math.pow' of github.com:Liaojinghui/neo-devpack-dotnet …
Jim8y c9ee7e2
Update src/Neo.SmartContract.Framework/Math.cs
shargon 6a0d22b
Update src/Neo.SmartContract.Framework/Math.cs
shargon 60bbfb7
Merge branch 'master' into math.pow
shargon 6506918
remove system convert and ensure that new Math methods still generate…
Jim8y 6aa388a
Merge branch 'master' into math.pow
Jim8y 87bbaaf
recover System.Math
Jim8y 6468ad0
Merge branch 'master' into math.pow
Jim8y 7cfdafc
use neo math
Jim8y File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4513,44 +4513,16 @@ private bool TryProcessSystemMethods(SemanticModel model, IMethodSymbol symbol, | |
PrepareArgumentsForMethod(model, symbol, arguments); | ||
Call(NativeContract.StdLib.Hash, "atoi", 1, true); | ||
return true; | ||
case "System.Math.Abs(sbyte)": | ||
case "System.Math.Abs(short)": | ||
case "System.Math.Abs(int)": | ||
case "System.Math.Abs(long)": | ||
case "System.Numerics.BigInteger.Abs(System.Numerics.BigInteger)": | ||
if (arguments is not null) | ||
PrepareArgumentsForMethod(model, symbol, arguments); | ||
AddInstruction(OpCode.ABS); | ||
return true; | ||
case "System.Math.Sign(sbyte)": | ||
case "System.Math.Sign(short)": | ||
case "System.Math.Sign(int)": | ||
case "System.Math.Sign(long)": | ||
if (arguments is not null) | ||
PrepareArgumentsForMethod(model, symbol, arguments); | ||
AddInstruction(OpCode.SIGN); | ||
return true; | ||
case "System.Math.Max(byte, byte)": | ||
case "System.Math.Max(sbyte, sbyte)": | ||
case "System.Math.Max(short, short)": | ||
case "System.Math.Max(ushort, ushort)": | ||
case "System.Math.Max(int, int)": | ||
case "System.Math.Max(uint, uint)": | ||
case "System.Math.Max(long, long)": | ||
case "System.Math.Max(ulong, ulong)": | ||
case "System.Numerics.BigInteger.Max(System.Numerics.BigInteger, System.Numerics.BigInteger)": | ||
if (arguments is not null) | ||
PrepareArgumentsForMethod(model, symbol, arguments); | ||
AddInstruction(OpCode.MAX); | ||
return true; | ||
case "System.Math.Min(byte, byte)": | ||
case "System.Math.Min(sbyte, sbyte)": | ||
case "System.Math.Min(short, short)": | ||
case "System.Math.Min(ushort, ushort)": | ||
case "System.Math.Min(int, int)": | ||
case "System.Math.Min(uint, uint)": | ||
case "System.Math.Min(long, long)": | ||
case "System.Math.Min(ulong, ulong)": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this part should be in another PR, @Jim8y . It is a good point to discuss There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, will move it to another pr. |
||
case "System.Numerics.BigInteger.Min(System.Numerics.BigInteger, System.Numerics.BigInteger)": | ||
if (arguments is not null) | ||
PrepareArgumentsForMethod(model, symbol, arguments); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright (C) 2015-2023 The Neo Project. | ||
// | ||
// The Neo.SmartContract.Framework is free software distributed under the MIT | ||
// software license, see the accompanying file LICENSE in the main directory | ||
// of the project or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Neo.SmartContract.Framework.Attributes; | ||
using System.Numerics; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Neo.SmartContract.Framework | ||
{ | ||
public class Math | ||
{ | ||
[CallingConvention(CallingConvention.StdCall)] | ||
[OpCode(OpCode.POW)] | ||
public static extern BigInteger Pow(BigInteger x, BigInteger y); | ||
[CallingConvention(CallingConvention.StdCall)] | ||
[OpCode(OpCode.POW)] | ||
public static extern BigInteger Pow(long x, long y); | ||
[CallingConvention(CallingConvention.StdCall)] | ||
[OpCode(OpCode.POW)] | ||
public static extern BigInteger Pow(int x, int y); | ||
[CallingConvention(CallingConvention.StdCall)] | ||
[OpCode(OpCode.POW)] | ||
public static extern BigInteger Pow(ulong x, ulong y); | ||
[CallingConvention(CallingConvention.StdCall)] | ||
[OpCode(OpCode.POW)] | ||
public static extern BigInteger Pow(uint x, uint y); | ||
[CallingConvention(CallingConvention.StdCall)] | ||
[OpCode(OpCode.POW)] | ||
public static extern BigInteger Pow(short x, short y); | ||
[CallingConvention(CallingConvention.StdCall)] | ||
[OpCode(OpCode.POW)] | ||
public static extern BigInteger Pow(ushort x, ushort y); | ||
[CallingConvention(CallingConvention.StdCall)] | ||
[OpCode(OpCode.POW)] | ||
public static extern BigInteger Pow(byte x, byte y); | ||
shargon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[CallingConvention(CallingConvention.StdCall)] | ||
[OpCode(OpCode.POW)] | ||
public static extern BigInteger Pow(sbyte x, sbyte y); | ||
|
||
[OpCode(OpCode.ABS)] | ||
public static extern sbyte Abs(sbyte x); | ||
[OpCode(OpCode.ABS)] | ||
public static extern short Abs(short x); | ||
[OpCode(OpCode.ABS)] | ||
public static extern int Abs(int x); | ||
[OpCode(OpCode.ABS)] | ||
public static extern long Abs(long x); | ||
|
||
[OpCode(OpCode.SIGN)] | ||
public static extern sbyte Sign(sbyte x); | ||
[OpCode(OpCode.SIGN)] | ||
public static extern short Sign(short x); | ||
[OpCode(OpCode.SIGN)] | ||
public static extern int Sign(int x); | ||
[OpCode(OpCode.SIGN)] | ||
public static extern long Sign(long x); | ||
|
||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MAX)] | ||
public static extern byte Max(byte x, byte y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MAX)] | ||
public static extern sbyte Max(sbyte x, sbyte y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MAX)] | ||
public static extern short Max(short x, short y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MAX)] | ||
public static extern ushort Max(ushort x, ushort y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MAX)] | ||
public static extern int Max(int x, int y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MAX)] | ||
public static extern uint Max(uint x, uint y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MAX)] | ||
public static extern long Max(long x, long y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MAX)] | ||
public static extern ulong Max(ulong x, ulong y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MAX)] | ||
public static extern BigInteger Max(BigInteger x, BigInteger y); | ||
|
||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MIN)] | ||
public static extern byte Min(byte x, byte y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MIN)] | ||
public static extern sbyte Min(sbyte x, sbyte y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MIN)] | ||
public static extern short Min(short x, short y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MIN)] | ||
public static extern ushort Min(ushort x, ushort y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MIN)] | ||
public static extern int Min(int x, int y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MIN)] | ||
public static extern uint Min(uint x, uint y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MIN)] | ||
public static extern long Min(long x, long y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MIN)] | ||
public static extern ulong Min(ulong x, ulong y); | ||
[CallingConvention(CallingConvention.Cdecl)] | ||
[OpCode(OpCode.MIN)] | ||
public static extern BigInteger Min(BigInteger x, BigInteger y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid confusion, use
Neo.Math
everywhere instead ofSystem.Math
. Otherwise you will have twoMath
system.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to use native
C#
. This may why developers can't program inC#
(I guess). No internet search will tell them to useNeo.math
, unless theNC
error says to.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @cschuchardt88
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't, many of them use
double
, i think you know what the issue is @shargon.And I do not think using C# native is a good idea, this is neo C#, instead of dotnet C#, using dotnet C# causes confusion as people do not know what can be done and what can not.
We use C# syntax, its good, but using C# native framwork is another story as it has double, float, decimal and tons of other types and methods that can not be supported by neo, are we going to tell them one by one this is not supported and that is not supported? Though the analyzer can do that, but having our own to strickly and accurately tell them would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you know what method is supported by neo @cschuchardt88? only at compile time right? how does it feel? every time you use something, you know if it works only if you compile it......
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understandable, Maybe we should phase out all native
dotnet
APIs
and only haveNeo
types & functions. For example,Neo.Math.Abs
,Neo.String
and etcThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly what i have in mind.