Numerics Library for .NET

Exact decimals, wider integers and more precise floats, all built on .NET's generic math.

What's inside

Discover the capabilities built to elevate your .NET applications.

Arbitrarily Large Decimals

BigDecimal holds decimal numbers of any size as an unscaled integer and a scale, so values like money and measurements are stored exactly rather than approximated in binary. Addition, subtraction and multiplication are exact, while division and rounding round to the scale you need with whichever MidpointRounding mode you choose.

Native to Generic Math

BigDecimal implements IFloatingPoint<T>, so it works anywhere .NET's generic math does, with the same operators, the same INumber<T> methods and the same generic algorithms as the built-in types. Its constants for E, Pi and Tau are accurate to 1,001 decimal digits.

Strict and Semantic Equality

Is 1.20 the same number as 1.2? Sometimes it is, and sometimes the scale matters. Equals compares value and scale strictly, == compares numerically, and dedicated comparers let you choose either explicitly, while ordering always follows the numeric value.

Wider Integers

Int256, UInt256, Int512 and UInt512 implement IBinaryInteger<T>, just like int and long, so they work with every generic algorithm and operator, including bitwise operations and shifts. Ordinary arithmetic wraps like the built-in types, checked arithmetic throws on overflow, and values read and write as big- or little-endian bytes.

Quadruple and Octuple Precision

Float128 and Float256 implement IEEE 754 binary128 and binary256, with 113- and 237-bit significands, for calculations where a double runs out of precision. As IBinaryFloatingPointIeee754<T> types, they bring trigonometric, hyperbolic, exponential, logarithmic, power and root functions, fused multiply-add and the rest of the standard floating-point toolkit.

Conversions on Your Terms

Moving between binary floating point and decimal is where precision quietly goes missing. ConversionMode chooses between the shortest decimal that round-trips, so 0.1 stays 0.1, and the exact binary value the float actually holds. ScaleMode decides whether an integer given a scale keeps its digits or its value, and narrowing conversions throw on overflow instead of failing silently.

NumberInfo

NumberInfo takes any decimal number apart into its unscaled value, scale, significand, exponent, precision and sign, whether it started as a built-in numeric type, a BigDecimal, a Float128 or a Float256. It's a solid foundation for numeric types of your own, and for analysing values without losing detail.

Culture-Aware Parsing and Formatting

BigDecimal, NumberInfo and the floating-point types parse and format according to the culture you give them, including currency symbols, thousands separators, negative patterns and exponents. The standard format strings work as you'd expect: currency, decimal, exponential, fixed-point, general, number, percentage, round-trip and hexadecimal.

Generic Math Helpers

Delta, Factorial, IntegerLength, MinMax, Pow and Pow10 work across numeric types through generic math. Extension methods convert integers, floats and decimals to BigDecimal, BigInteger or NumberInfo, read a decimal's unscaled value, change its scale, and check whether a value falls within a range.