0
# Mathematical Constants & Types
1
2
Core mathematical constants, type definitions, and utility types used throughout the @thi.ng/math library.
3
4
## Capabilities
5
6
### Mathematical Constants
7
8
Pre-defined mathematical constants for common values used in calculations.
9
10
```typescript { .api }
11
/** Mathematical constant π (pi) */
12
const PI: number;
13
14
/** Mathematical constant τ (tau) = 2π */
15
const TAU: number;
16
17
/** Half of π */
18
const HALF_PI: number;
19
20
/** Third of π */
21
const THIRD_PI: number;
22
23
/** Quarter of π */
24
const QUARTER_PI: number;
25
26
/** Sixth of π */
27
const SIXTH_PI: number;
28
29
/** Inverse of π (1/π) */
30
const INV_PI: number;
31
32
/** Inverse of τ (1/τ) */
33
const INV_TAU: number;
34
35
/** Inverse of π/2 (2/π) */
36
const INV_HALF_PI: number;
37
38
/** Degrees to radians conversion factor (π/180) */
39
const DEG2RAD: number;
40
41
/** Radians to degrees conversion factor (180/π) */
42
const RAD2DEG: number;
43
44
/** Golden ratio φ = (1 + √5) / 2 */
45
const PHI: number;
46
47
/** Square root of 2 */
48
const SQRT2: number;
49
50
/** Square root of 3 */
51
const SQRT3: number;
52
53
/** Square root of 2 divided by 2 */
54
const SQRT2_2: number;
55
56
/** Square root of 3 divided by 2 */
57
const SQRT3_2: number;
58
59
/** One third (1/3) */
60
const THIRD: number;
61
62
/** Two thirds (2/3) */
63
const TWO_THIRD: number;
64
65
/** One sixth (1/6) */
66
const SIXTH: number;
67
68
/** Default epsilon value for floating-point comparisons */
69
let EPS: number;
70
```
71
72
**Usage Examples:**
73
74
```typescript
75
import { PI, TAU, PHI, DEG2RAD, EPS } from "@thi.ng/math/api";
76
77
// Circle calculations
78
const circumference = TAU * radius;
79
const area = PI * radius ** 2;
80
81
// Golden ratio applications
82
const goldenRectangleRatio = PHI; // 1.618...
83
84
// Angle conversions
85
const radians = 45 * DEG2RAD; // π/4
86
87
// Floating-point comparisons
88
const isZero = Math.abs(value) < EPS;
89
```
90
91
### Type Definitions
92
93
Type definitions used across the math library for type safety and API clarity.
94
95
```typescript { .api }
96
/**
97
* Classification of line crossing relationships
98
*/
99
type Crossing =
100
/** Lines A & B are equal */
101
| "equal"
102
/** Lines A & B are flat (all same values) */
103
| "flat"
104
/** Line A crossed under B */
105
| "under"
106
/** Line A crossed over B */
107
| "over"
108
/** Other crossing relationship */
109
| "other";
110
111
/**
112
* Numeric array type (imported from @thi.ng/api)
113
* Union of typed array types for numerical computations
114
*/
115
type NumericArray =
116
| number[]
117
| Float32Array
118
| Float64Array
119
| Int8Array
120
| Int16Array
121
| Int32Array
122
| Uint8Array
123
| Uint16Array
124
| Uint32Array
125
| Uint8ClampedArray;
126
```
127
128
**Usage Examples:**
129
130
```typescript
131
import { classifyCrossing, type Crossing } from "@thi.ng/math/crossing";
132
import { type NumericArray } from "@thi.ng/math/api";
133
134
// Crossing type usage
135
const classification: Crossing = classifyCrossing(1, 3, 2, 4);
136
// Returns "over" since line A crosses over line B
137
138
// NumericArray type usage
139
const processArray = (data: NumericArray): number => {
140
// Function can accept any numeric array type
141
return data.reduce((sum, val) => sum + val, 0);
142
};
143
144
processArray([1, 2, 3]); // Works with regular arrays
145
processArray(new Float32Array([1.5, 2.5, 3.5])); // Works with typed arrays
146
```