Questions tagged [system.numerics]
47 questions
35
votes
5 answers
How to add a reference to System.Numerics.dll
I want to use the BigInteger class from the System.Numerics but if i want to write
using System.Numerics;
Numerics is not found. I searched the web, and I found that I have to add a reference to System.Numerics.dll, but how can I do that?

55651909-089b-4e04-9408-47c5bf
- 1,134
- 5
- 14
- 31
17
votes
7 answers
How can I generate a random BigInteger within a certain range?
Consider this method that works well:
public static bool mightBePrime(int N) {
BigInteger a = rGen.Next (1, N-1);
return modExp (a, N - 1, N) == 1;
}
Now, in order to fulfill a requirement of the class I'm taking, mightBePrime must accept a…

Trevor Dixon
- 23,216
- 12
- 72
- 109
7
votes
3 answers
SIMD string to unsigned int parsing in C# performance improvement
I've implemented a method for parsing an unsigned integer string of length <= 8 using SIMD intrinsics available in .NET as follows:
public unsafe static uint ParseUint(string text)
{
fixed (char* c = text)
{
var parsed =…

Dmitri Nesteruk
- 23,067
- 22
- 97
- 166
7
votes
1 answer
Why only Matrix3x2 and Matrix4x4?
Why does the System.Numerics namespace define types Matrix3x2 and Matrix4x4 but not offer 2x2 or 3x3 matrices? These would be at least as useful.

Colonel Panic
- 132,665
- 89
- 401
- 465
6
votes
1 answer
Completely wrong value for matrix multiplication with System.Numerics
Even though the System.Numerics.Vectors library that is obtainable via NuGet has its own functions for view and projection matrices I wanted to implement it myself and just use the vector and matrix structures.
Unfortunately I am already getting a…

Christian Ivicevic
- 10,071
- 7
- 39
- 74
6
votes
1 answer
Can C# make use of fused multiply-add?
Does the C# compiler / jitter make use of fused multiply-add operations if they are available on the hardware being used? If it does, are there any particular compiler settings I need to set in order to take advantage of it?

Paul Chernoch
- 5,275
- 3
- 52
- 73
6
votes
2 answers
Why is Vector.Count static?
I'm trying to use System.Numerics.Vector (documentation).
I wrote a simple unit test:
var v = new System.Numerics.Vector(new double[] { 12, 13, 14 });
Assert.AreEqual(3, v.Count);
But it gave me a build error:
Member 'Vector.Count'…

Colonel Panic
- 132,665
- 89
- 401
- 465
5
votes
1 answer
System.Numerics.Vector on large data sets
I am trying to boost performance for a .NET Core library by utilizing System.Numerics to perform SIMD operations on float[] arrays. System.Numerics is a bit funky right now, and I'm having a hard time seeing how it can be beneficial. I understand…

Haus
- 1,492
- 7
- 23
5
votes
2 answers
How to get the elements of a System.Numerics.Vector in C#?
I want to access the elements of a System.Numerics.Vector in C#.
I'm following the official documentation: https://learn.microsoft.com/en-us/dotnet/api/system.numerics.vector-1?view=netcore-2.2
I'm able to create different vectors with different…

Marcel Gangwisch
- 8,856
- 4
- 23
- 32
5
votes
1 answer
Pointer to struct containing System.Numerics.Vector in C#
I'm trying to make vector with 4 doubles with System.Numerics library because of SIMD. So I made this struct:
public struct Vector4D
{
System.Numerics.Vector vecXY, vecZW;
...
}
In this phase I code it for 128bit SIMD register.
It…

Sanquira Van Delbar
- 71
- 5
4
votes
1 answer
What is System.Numerics.Vector.ConditionalSelect used for?
Can anyone explain preferably with an example what/when/how System.Numerics.Vector.ConditionalSelect can be used?
I cannot understand much from the docs.

MaYaN
- 6,683
- 12
- 57
- 109
4
votes
2 answers
Sum of elements in System.Numerics.Vector in .NET 4.6
I cannot figure out a way how to get a sum of elements in a vector of System.Numerics.Vector type.
double sum(System.Numerics.Vector vect)
{
// Something like
// double sum = 0;
// foreach e in vect { sum += e; }
//…

Anton K
- 4,658
- 2
- 47
- 60
3
votes
1 answer
new vector using .Net System.Numeric fills only half of the vector length
I'm doing a digital filter and using a vector and SIMD instructions to make it faster, but during debugging I noticed that when a new vector was created it only initialized half of the items in the vector, for example when creating a vector with…

Rafael Fortes
- 41
- 2
3
votes
1 answer
Vector weak SIMD Performance
I am optimizing an algorithm and I am considering using Vector over double for a multiply and accumulate operation. The implementation the closest is obviously a Vector.dot(v1, v2);... BUT, why is my code so slow?
namespace ConsoleApp1 {
class…

Styp
- 261
- 3
- 12
3
votes
1 answer
Are System.Numerics Planes backwards?
I'm writing some geometry code using System.Numerics and I seem to have encountered a bug in the implementation of the Plane.CreateFromVertices method. The comment on Plane.D says:
The plane's distance from the origin along its normal…

Martin
- 12,469
- 13
- 64
- 128