Hi everyone! I'm excited (and a bit nervous) to share UniversalConstants (v1.0.0), my very first open-source C++ library.
Motivation
I got tired of repeatedly defining PI across different files or fighting dependency hell when switching between quick prototypes and high-precision scientific calculations. So I built a C++17 library with a unified "Parentheses Precision Syntax" NAME(digits) and Dual-Mode Support:
-
Lightweight Header-Only Mode (Zero Dependencies): Just drop
BasicConstants.hinto your project for standarddouble-precision constants (BasicConstants::PI,BasicConstants::C, etc.). - GMP Hardcore Mode (Arbitrary Precision): Powered by GMP, you specify the exact decimal digits you need inside parentheses:
#include <iostream>
#include "UniversalConstants.h"
using namespace UniversalConstants::Math;
using namespace UniversalConstants::Physics;
int main() {
// Computes 3.6 million digits of Pi on the fly using Chudnovsky binary splitting
mpf_class huge_pi = PI(3600000);
// Lossless cross-domain physics arithmetic
mpf_class qg = (H_BAR(50) * G(50)) / (C(50) * C(50) * C(50));
std::cout << "Result: " << qg << std::endl;
return 0;
}
(Note: For physical constants, values are aligned with CODATA standards and automatically zero-padded if requested digits exceed current experimental limits.)
Looking for Feedback!
- GitHub Repository: https://github.com/dongdongyiqi/UniversalConstants
Since this is my first C++ library, I know there might be rough edges, subtle bugs, or non-idiomatic CMake/C++ practices. I would genuinely appreciate any code reviews, bug reports, or architectural advice from the community! If you find the concept interesting, a ⭐ on GitHub would also mean a lot to me. Thanks for reading!
Top comments (0)