-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
ProjectObsidian/ProtoFlux/Math/EulersTotientFunctionNode.cs
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,28 @@ | ||
using Elements.Core; | ||
using FrooxEngine.ProtoFlux; | ||
using ProtoFlux.Core; | ||
using ProtoFlux.Runtimes.Execution; | ||
|
||
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Math | ||
{ | ||
[NodeCategory("Obsidian/Math")] | ||
[NodeName("EulersTotientFunction")] | ||
public class EulersTotientFunctionNode : ValueFunctionNode<FrooxEngineContext, int> | ||
{ | ||
public ValueInput<int> Input; | ||
|
||
protected override int Compute(FrooxEngineContext context) | ||
{ | ||
var result = Input.Evaluate(context); | ||
var inputCopy = result; | ||
for (var p = 2; p * p <= inputCopy; ++p) | ||
{ | ||
if (inputCopy % p != 0) continue; | ||
while (inputCopy % p == 0) inputCopy /= p; | ||
result -= result / p; | ||
} | ||
if (inputCopy > 1) result -= result / inputCopy; | ||
return result; | ||
} | ||
} | ||
} |
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,40 @@ | ||
using Elements.Core; | ||
using FrooxEngine.ProtoFlux; | ||
using ProtoFlux.Core; | ||
using ProtoFlux.Runtimes.Execution; | ||
|
||
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Math | ||
{ | ||
[NodeCategory("Obsidian/Math")] | ||
[NodeName("IsPrimeNumber")] | ||
public class IsPrimeNumberNode : ValueFunctionNode<FrooxEngineContext, bool> | ||
{ | ||
public ValueInput<int> Input; | ||
|
||
protected override bool Compute(FrooxEngineContext context) | ||
{ | ||
var num = Input.Evaluate(context); | ||
switch (num) | ||
{ | ||
case < 2: | ||
return false; | ||
case 2: | ||
return true; | ||
default: | ||
{ | ||
if (num % 2 == 0) return false; | ||
break; | ||
} | ||
} | ||
double sqrtNum = MathX.Sqrt(num); | ||
for (var i = 3; i <= sqrtNum; i += 2) | ||
{ | ||
if (num % i == 0) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
} |