Menu

UniversalConstants: My first C++17 library with NAME(digits) syntax & dual-mode support
📰

UniversalConstants: My first C++17 library with NAME(digits) syntax & dual-mode support

DEV Community: cpp·yiqi huang·1 day ago
#PVRoObxT
Reading 0:00
15s threshold

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.h into your project for standard double -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 ) ;

//…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.