Sdcb.Arithmetic
A modern .NET library that can PInvoke to gmp and mpfr, that enable both high performance and best .NET convenience.
Install / Use
/learn @sdcb/Sdcb.ArithmeticREADME
Sdcb.Arithmetic

Sdcb.Arithmetic is a modern .NET library that can PInvoke to gmp and mpfr, that enable both high performance and best .NET convenience.
Known classes in Sdcb.Arithmetic:
| Class | Native name | Library | | ----------- | --------------- | -------------------- | | GmpInteger | mpz_t | Sdcb.Arithmetic.Gmp | | GmpFloat | mpf_t | Sdcb.Arithmetic.Gmp | | GmpRational | mpq_t | Sdcb.Arithmetic.Gmp | | GmpRandom | gmp_randstate_t | Sdcb.Arithmetic.Gmp | | MpfrFloat | mpfr_t | Sdcb.Arithmetic.Mpfr |
NuGet Packages
libgmp
| Package Id | Version | License | Notes |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ------- | ------------------------- |
| Sdcb.Arithmetic.Gmp | | MIT | .NET binding for
libgmp |
| Sdcb.Arithmetic.Gmp.runtime.win-x64 | | LGPL | native lib in Windows x64 |
| Sdcb.Arithmetic.Gmp.runtime.win-x86 |
| LGPL | native lib in Windows x86 |
| Sdcb.Arithmetic.Gmp.runtime.linux-x64 |
| LGPL | native lib in Linux x64 |
| Sdcb.Arithmetic.Gmp.runtime.linux-x86 |
| LGPL | native lib in Linux x86 |
| Sdcb.Arithmetic.Gmp.runtime.linux-arm |
| LGPL | native lib in Linux ARM |
| Sdcb.Arithmetic.Gmp.runtime.linux-arm64 |
| LGPL | native lib in Linux ARM64 |
| Sdcb.Arithmetic.Gmp.runtime.linux-musl-x64 |
| LGPL | native lib in Linux Musl x64 |
| Sdcb.Arithmetic.Gmp.runtime.linux-musl-arm64 |
| LGPL | native lib in Linux Musl ARM64 |
| Sdcb.Arithmetic.Gmp.runtime.osx-arm64 |
| LGPL | native lib in macOS ARM64 |
| Sdcb.Arithmetic.Gmp.runtime.osx-x64 |
| LGPL | native lib in macOS x64 |
| Sdcb.Arithmetic.Gmp.runtime.android-arm |
| LGPL | native lib in Android ARM |
| Sdcb.Arithmetic.Gmp.runtime.android-arm64 |
| LGPL | native lib in Android ARM64 |
| Sdcb.Arithmetic.Gmp.runtime.android-x86 |
| LGPL | native lib in Android x86 |
| Sdcb.Arithmetic.Gmp.runtime.android-x64 |
| LGPL | native lib in Android x64 |
Update: This library also tested and works good in Loongarch64(龙芯)
mpfr
| Package Id | Version | License | Notes |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ------- | -------------------------- |
| Sdcb.Arithmetic.Mpfr | | MIT | .NET binding for
libmpfr |
| Sdcb.Arithmetic.Mpfr.runtime.win-x64 | | LGPL | native lib in Windows x64 |
| Sdcb.Arithmetic.Mpfr.runtime.win-x86 |
| LGPL | native lib in Windows x86 |
| Sdcb.Arithmetic.Mpfr.runtime.linux-x64 |
| LGPL | native lib in Linux x64 |
| Sdcb.Arithmetic.Mpfr.runtime.linux-x86 |
| LGPL | native lib in Linux x86 |
| Sdcb.Arithmetic.Mpfr.runtime.linux-arm |
| LGPL | native lib in Linux ARM |
| Sdcb.Arithmetic.Mpfr.runtime.linux-arm64 |
| LGPL | native lib in Linux ARM64 |
| Sdcb.Arithmetic.Mpfr.runtime.linux-musl-x64 |
| LGPL | native lib in Linux Musl x64 |
| Sdcb.Arithmetic.Mpfr.runtime.linux-musl-arm64|
| LGPL | native lib in Linux Musl ARM64 |
| Sdcb.Arithmetic.Mpfr.runtime.osx-arm64 |
| LGPL | native lib in macOS ARM64 |
| Sdcb.Arithmetic.Mpfr.runtime.osx-x64 |
| LGPL | native lib in macOS x64 |
| Sdcb.Arithmetic.Mpfr.runtime.android-arm |
| LGPL | native lib in Android ARM |
| Sdcb.Arithmetic.Mpfr.runtime.android-arm64 |
| LGPL | native lib in Android ARM64 |
| Sdcb.Arithmetic.Mpfr.runtime.android-x86 |
| LGPL | native lib in Android x86 |
| Sdcb.Arithmetic.Mpfr.runtime.android-x64 |
| LGPL | native lib in Android x64 |
Native dynamic library name mapping
Defined in GmpNativeLoader.cs and MpfrNativeLoader.cs
| OS | gmp dynamic lib | mpfr dynamic lib | | ------- | --------------- | ---------------- | | Windows | libgmp-10.dll | libmpfr-6.dll | | Linux | libgmp.so.10 | libmpfr.so.6 | | MacOS | libgmp.10.dylib | libmpfr.6.dylib | | Android | libgmp.so | libmpfr.so | | Others | gmp.10 | mpfr.6 |
Examples
Calculate 1,000,000 length of π using Sdcb.Arithmetic.Gmp:
// Install NuGet package: Sdcb.Arithmetic.Gmp
// Install NuGet package: Sdcb.Arithmetic.Gmp.runtime.win-x64(for windows)
using Sdcb.Arithmetic.Gmp;
Console.WriteLine(CalcPI().ToString("N1000000"));
GmpFloat CalcPI(int inputDigits =
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
