Skip to content

Commit 17309ac

Browse files
committed
styling
1 parent a8a5840 commit 17309ac

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

  • content/stellar-contracts/utils/math

content/stellar-contracts/utils/math/wad.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ of floating-point arithmetic in smart contracts.
4444

4545
## 1. Why 18 Decimals?
4646

47-
**18 decimals was chosen for several reasons:**
47+
18 decimals was chosen for several reasons:
4848

4949
- **Battle-Tested Standard**: Most DeFi protocols on use 18 decimals
5050
- **Sufficient Precision**: Provides precision down to 10^-18, far exceeding practical financial needs
@@ -83,7 +83,7 @@ pub struct Wad(i128);
8383

8484
## 3. No `From`/`Into` Traits
8585

86-
We deliberately **do not** implement `From<i128>` or `Into<i128>` because it's ambiguous:
86+
We deliberately **DID NOT** implement `From<i128>` or `Into<i128>` because it's ambiguous:
8787

8888
```rust
8989
// What should this mean?
@@ -127,10 +127,10 @@ Operator overloading is supported across WAD and native i128 types where unambig
127127

128128
**Overflow Behavior**
129129

130-
**Just like regular Rust**, operator overloading does not include overflow checks:
130+
Just like regular Rust, operator overloading does not include overflow checks:
131131

132-
- **Use `checked_*` methods** (`checked_add()`, `checked_sub()`, `checked_mul()`, etc.) when handling user inputs or when overflow is possible. These return `Option<Wad>` for safe error handling.
133-
- **Use operator overloads** (`+`, `-`, `*`, `/`) when you want to save gas by skipping overflow checks, or when you're confident the operation cannot overflow.
132+
- Use `checked_*` methods (`checked_add()`, `checked_sub()`, `checked_mul()`, etc.) when handling user inputs or when overflow is possible. These return `Option<Wad>` for safe error handling.
133+
- Use operator overloads (`+`, `-`, `*`, `/`) when you want to save gas by skipping overflow checks, or when you're confident the operation cannot overflow.
134134

135135
This design follows Rust's standard library pattern: operators for performance, checked methods for safety.
136136

@@ -180,9 +180,9 @@ impl Div for Wad {
180180

181181
## Exponentiation
182182

183-
WAD supports raising a value to an **unsigned integer exponent** via `pow`.
183+
WAD supports raising a value to an unsigned integer exponent via `pow`.
184184

185-
- `pow(&e, exponent)` is optimized using **exponentiation by squaring** (O(log n) multiplications).
185+
- `pow(&e, exponent)` is optimized using exponentiation by squaring (O(log n) multiplications).
186186
- Each multiplication keeps WAD semantics (fixed-point multiplication and truncation toward zero).
187187
- Overflow is reported via Soroban errors.
188188

@@ -223,7 +223,7 @@ let usdc_back: i128 = wad.to_token_amount(&e, 6);
223223

224224
## Understanding Fixed-Point Precision
225225

226-
**WAD is a fixed-point math library.** Like all fixed-point arithmetic systems,
226+
WAD is a fixed-point math library. Like all fixed-point arithmetic systems,
227227
precision loss is inherent and unavoidable. The goal is not to eliminate precision errors
228228
—that's impossible— but to reduce them to a degree so minimal
229229
that they become irrelevant in practical applications.
@@ -253,7 +253,7 @@ let result2 = a * (b * c); // Truncates after inner multiplication
253253
- Errors are in the **10^-15 to 10^-18** range, far beyond practical significance
254254
- Token precision (6-8 decimals) completely absorbs these errors when converting back
255255
- Real-world financial systems round to 2-8 decimal places; WAD's 18 decimals provide a massive safety margin
256-
- This is **orders of magnitude more precise** than needed for DeFi applications
256+
- This is orders of magnitude more precise than needed for DeFi applications
257257

258258
# Usage Examples
259259

0 commit comments

Comments
 (0)