8000 pythonnet · heartacker/CScripting@7534a93 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7534a93

Browse files
committed
pythonnet
1 parent 7b7077a commit 7534a93

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

S.System/S.System.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<PackageReleaseNotes>初始化版本。添加 hex,bin,print 函数</PackageReleaseNotes>
1919
</PropertyGroup>
2020

21+
<ItemGroup>
22+
<PackageReference Include="pythonnet" Version="3.0.1" />
23+
</ItemGroup>
24+
2125
<ItemGroup>
2226
<None Update="S.System.png">
2327
<Pack>True</Pack>

S.System/System.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.IO;
44
using System.Linq;
@@ -11,6 +11,10 @@
1111
using static System.Numerics.Complex;
1212
using static System.Numerics.BigInteger;
1313

14+
using Python.Runtime;
15+
using static Python.Runtime.Runtime;
16+
using static Python.Runtime.Py;
17+
using static Python.Runtime.PythonEngine;
1418

1519
namespace S
1620
{
@@ -133,6 +137,21 @@ public static double Abs(Complex num)
133137
return Abs(num.Magnitude);
134138
}
135139

140+
/// <summary>
141+
/// 仅支持复数类型
142+
/// </summary>
143+ /// <param name="num"></param>
144+
/// <returns></returns>
145+
public static double Abs(PyObject num)
146+
{
147+
using (GIL())
148+
{
149+
var c = num.As<Complex>();
150+
return Abs(c.Magnitude);
151+
}
152+
}
153+
154+
136155
[Obsolete("This method is deprecated, use `Abs` instead.")]
137156
public static double abs(Complex num) => Abs(num);
138157

0 commit comments

Comments
 (0)
0