Skip to content

whiskyrelaxing/salvium-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Salvium: Fixed-Point Decimal Type for Cryptocurrency

Design Principles

No silent failures: Arithmetic operations throw on overflow/underflow instead of clamping. This surfaces bugs immediately rather than corrupting balances silently.

Integer-based storage: Stores values as uint64_t atomic units (dusties or 1e-8 Salvium), eliminating floating-point rounding errors entirely. 8 decimal places matches Salvium's precision requirements.

Type-safe: The type system itself prevents negative values (unsigned backing type) rather than relying on runtime checks. You cannot construct an invalid state.

Explicit bounds checking: Operations that could overflow check before executing, making resource limits visible in the code.

Why This Works for Crypto

  1. Precision: Fixed-point arithmetic with integer backing guarantees exact results. No floating-point rounding corruption.

  2. Atomicity: Works directly with atomic units (dusties), which is how blockchains actually store values.

  3. Auditability: Failed operations throw; you know immediately when something went wrong. No silently-clamped balance errors.

  4. No negative values by design: Uses unsigned integers, not runtime validation that can fail.

Usage

// From atomic units
Salvium balance(500000000ULL);  // 5 Salvium

// From decimal string (no floating-point involved)
Salvium amount = Salvium::from_string("1.5");

// Arithmetic throws on overflow/underflow
balance += amount;
balance -= amount;  // throws if amount > balance

// Get values back
uint64_t atomic = balance.to_atomic();
std::string display = balance.to_salvium_string();

This is what crypto needs.

About

Fixed-point decimal type for Salvium with explicit overflow checking and no floating-point arithmetic.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages