BigIntegerExtender is written in C# and extends System.Numerics.BigInteger to support serialization and the calculation of square roots. It contains:
- BigIntegerSerializable: this enables you to serialize System.Numerics.BigInteger objects.
- BigIntegerExtender: it has an extension method that adds the function Sqrt to System.Numerics.BigInteger objects.
Remember to add System.Numerics.BigInteger, BigIntegerExtender and System.Xml before using this library in your projects.
using System;
using System.Numerics;
namespace Example1
{
class Program
{
static void Main(string[] args)
{
while (true)
{
BigInteger value;
do
{
Console.Write("Enter a valid number: ");
} while (!BigInteger.TryParse(Console.ReadLine(), out value));
try
{
BigInteger sqrt = value.Sqrt();
Console.WriteLine(String.Format("Sqrt of {0}: {1}\n", value, sqrt));
}
catch(ArithmeticException)
{
Console.WriteLine(String.Format("Sqrt of {0}: NaN\n", value));
}
}
}
}
}
using System;
using System.Numerics;
using System.Xml.Serialization;
namespace Example2
{
class Program
{
static void Main(string[] args)
{
while (true)
{
BigInteger value;
do
{
Console.Write("Enter a valid number: ");
} while (!BigInteger.TryParse(Console.ReadLine(), out value));
var ms = new System.IO.MemoryStream();
var serializer = new XmlSerializer(typeof(BigIntegerSerializable));
serializer.Serialize(ms, (BigIntegerSerializable)value);
Console.Write("\nXML: ");
Console.WriteLine(System.Text.Encoding.UTF8.GetString(ms.ToArray()));
Console.WriteLine("\n");
}
}
}
}
- If you want to contribute, make sure that there is a corresponding issue for your change first. If there is none, create one.
- Create a fork in GitHub.
- Create a branch off the master branch with an adequate name.
- Commit your changes and push your changes to GitHub.
- Create a pull request against the origin's master branch.
- DO follow C# Coding Conventions.
- DO run all tests in BigIntegerExtenderTests project before committing your changes. When adding new features, include adequate tests for those.
- DO run Code Analysis before committing your changes.
This project is licensed under the MIT license.