Skip to content

NetFabric/NetFabric.Numerics / .agents/skills/angles-and-circular-arithmetic

angles-and-circular-arithmetic

Verified

Abstract math for angle measurement, unit systems, and circular arithmetic. USE FOR: implementing angle types; converting between degrees/radians/gradians/revolutions; reducing angles to canonical range [0, Full); computing reference angles and quadrants; implementing safe modular arithmetic with negative inputs; angle addition and subtraction; classifying angles by sign and size. DO NOT USE FOR: trigonometric functions (use trigonometric-functions); coordinate conversions (use coordinate-system-conversions); interpolation (use interpolation-on-manifolds).

FileKindSize
SKILL.mdskill md2.3 KB
references/formulas.mdmarkdown2.4 KB
references/numerical-stability.mdmarkdown2.1 KB

references/numerical-stability.md

View on GitHub
# Angles — Numerical Stability

## Negative-Input Modulo (Critical)

In many languages, `%` is truncating remainder, not mathematical modulo:

| Language | `−30 % 360` | Correct? |
|----------|-------------|----------|
| C/C++/C# | −30 | No |
| Java | −30 | No |
| Python | 330 | Yes |
| JavaScript | −30 | No |

**Fix**: use floor-based formula:
```csharp
double reduced = angle - full * Math.Floor(angle / full);
```

Or equivalently: `((angle % full) + full) % full` — but this loses precision for large angles.

## Precision Loss in Unit Conversion

π is irrational; `Math.PI` is only a double approximation (~15 significant digits).

**Chain conversion amplifies error:** degrees → radians → degrees does NOT give the original value exactly.

**Round-trip rule**: convert directly between source and target unit; do not chain through radians as an intermediate unless required by the API.

**Example of accumulated error:**
```
360° → radians → gradians ≠ 400
```
The chain `degrees * (π/180) * (200/π)` has two floating-point multiplications vs. one for `degrees * (10/9)`. Use the direct factor.

## Large-Angle Reduction

When θ >> Full (e.g., angle accumulated over many rotations):

```csharp
// Catastrophic cancellation: θ = 1e15°, Full = 360
// floor(1e15 / 360) ≈ 2.78e12  — OK
// 1e15 − 360 * 2.78e12  — subtraction of nearly equal numbers loses low bits
```

For accumulated angles, carry a "full rotation counter" separately and reduce only the fractional part.

## Equality Comparison

`θ₁ == θ₂` using floating-point exact comparison fails at boundaries:
- 360.0 and 0.0 are mathematically equivalent after reduction but not bit-equal before it.
- Always reduce before comparing angles for angular equivalence.
- For approximate equality, use `|θ₁ − θ₂| < ε` on reduced values.

## IEEE 754 Special Values

| Input | Behavior |
|-------|---------|
| NaN | NaN propagates; reduction of NaN is NaN |
| +Inf / −Inf | `floor(Inf / Full)` is Inf; reduction of Inf is NaN |
| −0.0 | `floor(−0.0 / Full) = 0.0`; reduction gives 0.0 correctly |

Always guard for `IsFinite(θ)` before reducing.
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall