EuMath is a small .NET library written in C# that provides some useful math functions.
$ dotnet add package EuMathEuMath is a small .NET library written in C# that provides some useful math functions.
This library contains many functions related to prime numbers.
Prime numbers themselves are never negative and additionally, they are usually defined on the set of natural numbers, which is also non-negative.
Therefore, it is often possible to use unsigned integer types in classes and functions related to prime numbers.
This has advantages.
For example, the maximum value of an unsigned integer type is roughly twice as big as the maximum value of the corresponding signed integer type.
This means that unsigned integer types allow larger input and output values than signed integer types.
Additionally, making non-existing values (e.g., negative primes) irrepresentable by the underlying type can be useful.
However, from time to time I have seen bugs originating from unsigned integer overflow when a substraction produced a negative result.
In some cases, it took very long to find the source of the error.
Therefore, in my opinion, the advantages are just not strong enough compared to outweigh the unsigned overflow error source.
And that's why this library uses signed integer types almost everywhere.