1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
use super::ExponentConstants;
use super::FractionConstants;
use crate::Circle;
pub trait CircleConstants {
/// Maximum finite value that can be represented by this type of Circle.
const MAX: Self;
/// Minimum finite value that can be represented by this type of Circle.
const MIN: Self;
/// The smallest positive value that can be represented by this type of Circle.
const MIN_POS: Self;
/// Smallest magnitude negative value that can be represented by this type of Circle.
const MAX_NEG: Self;
/// Granularity between 1 and 2
const POS_NORMAL_EPSILON: Self;
/// Granularity between -1 and -2
const NEG_NORMAL_EPSILON: Self;
/// The maximum value that maintains integer contiguity with its neighboring values.
/// This is one less than MAX_FRACTION to ensure the value connects to both its
/// predecessor and successor in the representable sequence (a+1!=a).
const MAX_CONTIGUOUS: Self;
/// The minimum value that maintains integer contiguity with its neighboring values.
/// This is one more than MIN_FRACTION to ensure the value connects to both its
/// predecessor and successor in the representable sequence (a-1!=a).
const MIN_CONTIGUOUS: Self;
/// Actual Zero, the real deal. Exploded * 0 = 0
const ZERO: Self;
/// Mathematical infinity - the result of division by Zero (1/0).
/// Unlike IEEE-754's signed infinities, this represents a singular infinity
/// where the sign is indeterminate. Represented by all fraction bits set (11111111)
/// with an ambiguous exponent, creating symmetry with ZERO (00000000).
/// Used for results where magnitude is infinite and direction is ambiguous.
const INFINITY: Self;
/// Exactly one.
const ONE: Self;
/// Exactly negative one.
const NEG_ONE: Self;
/// Effectively one (the largest value smaller than one).
const EFFECTIVELY_POS_ONE: Self;
/// Effectively negative one (the closest value to -1 with magnitude less than 1).
const EFFECTIVELY_NEG_ONE: Self;
/// Exactly two.
const TWO: Self;
/// Exactly 1/2.
const HALF: Self;
/// The imaginary unit (i).
const POS_I: Self;
/// Negative imaginary unit (-i).
const NEG_I: Self;
/// Approximately Pi (π ≈ 3.14159265358979323846...)
const PI: Self;
/// Approximately negative Pi (-π ≈ -3.14159265358979323846...)
const NEG_PI: Self;
/// Approximately Tau (2π ≈ 6.28318530717958647693...)
const TAU: Self;
/// Approximately negative Tau (-2π ≈ -6.28318530717958647693...)
const NEG_TAU: Self;
/// Alternative name for TAU (2π)
const TWO_PI: Self;
/// Pi divided by two (π/2 ≈ 1.57079632679489661923...)
const PI_OVER_TWO: Self;
/// Negative Pi divided by two (-π/2 ≈ -1.57079632679489661923...)
const NEG_PI_OVER_TWO: Self;
/// Pi divided by three (π/3 ≈ 1.04719755119659774615...)
const PI_OVER_THREE: Self;
/// Pi divided by four (π/4 ≈ 0.78539816339744830962...)
const PI_OVER_FOUR: Self;
/// Pi divided by six (π/6 ≈ 0.52359877559829887308...)
const PI_OVER_SIX: Self;
/// Pi divided by eight (π/8 ≈ 0.39269908169872415481...)
const PI_OVER_EIGHT: Self;
/// One divided by pi (1/π ≈ 0.31830988618379067154...)
const ONE_OVER_PI: Self;
/// Two divided by pi (2/π ≈ 0.63661977236758134308...)
const TWO_OVER_PI: Self;
/// Approximately Euler's number (e ≈ 2.71828182845904523536...)
const E: Self;
/// Approximately natural logarithm of two (ln(2) ≈ 0.69314718055994530942...)
const LN_TWO: Self;
/// Binary logarithm of e (log(e,2) ≈ 1.44269504088896340736...)
const LB_E: Self;
/// Approximately square root of two (√2 ≈ 1.41421356237309504880...)
const SQRT_TWO: Self;
}
macro_rules! impl_circle_constants {
($($f:ty, $e:ty);*) => {
$(
impl Circle<$f, $e> {
/// Maximum finite value that can be represented by this type of Circle.
pub const MAX: Self = Self {
real: <$f>::MAX_FRACTION,
imaginary: 0,
exponent: <$e>::MAX_EXPONENT,
};
/// Minimum finite value that can be represented by this type of Circle.
pub const MIN: Self = Self {
real: <$f>::MIN_FRACTION,
imaginary: 0,
exponent: <$e>::MAX_EXPONENT,
};
/// The smallest positive value that can be represented by this type of Circle.
pub const MIN_POS: Self = Self {
real: <$f>::POS_ONE_FRACTION,
imaginary: 0,
exponent: <$e>::MIN_EXPONENT,
};
/// Smallest magnitude negative value that can be represented by this type of Circle.
pub const MAX_NEG: Self = Self {
real: <$f>::NEG_ONE_FRACTION,
imaginary: 0,
exponent: <$e>::MIN_EXPONENT,
};
/// Granularity between 1/2 and 1
pub const POS_NORMAL_EPSILON: Self = Self {
real: <$f>::POS_ONE_FRACTION,
imaginary: 0,
exponent: (2isize.wrapping_sub(<$f>::FRACTION_BITS as isize)) as $e,
};
/// Granularity between -1 and -1/2
pub const NEG_NORMAL_EPSILON: Self = Self {
real: <$f>::NEG_ONE_FRACTION,
imaginary: 0,
exponent: (1isize.wrapping_sub(<$f>::FRACTION_BITS as isize)) as $e,
};
/// The maximum value that maintains integer contiguity with its neighboring values.
/// This is one less than MAX_FRACTION to ensure the value connects to both its
/// predecessor and successor in the representable sequence (a+1!=a).
pub const MAX_CONTIGUOUS: Self = Self {
real: <$f>::MAX_FRACTION.wrapping_sub(1),
imaginary: 0,
exponent: ((<$e>::FRACTION_BITS).wrapping_add(<$e>::EXPONENT_BITS).wrapping_sub(1)) as $e,
};
/// The minimum value that maintains integer contiguity with its neighboring values.
/// This is one more than MIN_FRACTION to ensure the value connects to both its
/// predecessor and successor in the representable sequence (a-1!=a).
pub const MIN_CONTIGUOUS: Self = Self {
real: <$f>::MIN_FRACTION.wrapping_add(1),
imaginary: 0,
exponent: ((<$e>::FRACTION_BITS).wrapping_add(<$e>::EXPONENT_BITS).wrapping_sub(1)) as $e,
};
/// Actual Zero, the real deal. Exploded * 0 = 0
pub const ZERO: Self = Self {
real: 0,
imaginary: 0,
exponent: <$e>::AMBIGUOUS_EXPONENT,
};
/// Mathematical infinity - the result of division by Zero (1/0).
/// Unlike IEEE-754's signed infinities, this represents a singular infinity
/// where the sign is indeterminate. Represented by all fraction bits set (11111111)
/// with an ambiguous exponent, creating symmetry with ZERO (00000000).
/// Used for results where magnitude is infinite and direction is ambiguous.
pub const INFINITY: Self = Self {
real: -1,
imaginary: -1,
exponent: <$e>::AMBIGUOUS_EXPONENT,
};
/// Exactly one.
pub const ONE: Self = Self {
real: <$f>::POS_ONE_FRACTION,
imaginary: 0,
exponent: 1,
};
/// Exactly negative one.
pub const NEG_ONE: Self = Self {
real: <$f>::MIN_FRACTION,
imaginary: 0,
exponent: 0,
};
/// Effectively one (the largest value smaller than one).
pub const EFFECTIVELY_POS_ONE: Self = Self {
real: <$f>::MAX_FRACTION,
imaginary: 0,
exponent: 0,
};
/// Effectively negative one (the closest value to -1 with magnitude less than 1).
pub const EFFECTIVELY_NEG_ONE: Self = Self {
real: <$f>::MIN_FRACTION.wrapping_add(1),
imaginary: 0,
exponent: 0,
};
/// Exactly two.
pub const TWO: Self = Self {
real: <$f>::POS_ONE_FRACTION,
imaginary: 0,
exponent: 2,
};
/// Exactly 1/2.
pub const HALF: Self = Self {
real: <$f>::POS_ONE_FRACTION,
imaginary: 0,
exponent: 0,
};
/// Imaginary unit (i).
pub const POS_I: Self = Self {
real: 0,
imaginary: <$f>::POS_ONE_FRACTION,
exponent: 1,
};
/// Negative imaginary unit (-i).
pub const NEG_I: Self = Self {
real: 0,
imaginary: <$f>::MIN_FRACTION,
exponent: 0,
};
/// Approximately Pi (π ≈ 3.14159265358979323846...)
pub const PI: Self = Self {
real: (0x6487ED5110B4611A62633145C06E0E69i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 2,
};
/// Approximately negative Pi (-π ≈ -3.14159265358979323846...)
pub const NEG_PI: Self = Self {
real: (-0x6487ED5110B4611A62633145C06E0E69i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 2,
};
/// Approximately Tau (2π ≈ 6.28318530717958647693...)
pub const TAU: Self = Self {
real: (0x6487ED5110B4611A62633145C06E0E69i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 3,
};
/// Approximately negative Tau (-2π ≈ -6.28318530717958647693...)
pub const NEG_TAU: Self = Self {
real: (-0x6487ED5110B4611A62633145C06E0E68i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 3,
};
/// Alternative name for TAU (2π)
pub const TWO_PI: Self = Self::TAU;
/// Pi divided by two (π/2 ≈ 1.57079632679489661923...)
pub const PI_OVER_TWO: Self = Self {
real: (0x6487ED5110B4611A62633145C06E0E69i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 1,
};
/// Negative Pi divided by two (-π/2 ≈ -1.57079632679489661923...)
pub const NEG_PI_OVER_TWO: Self = Self {
real: (-0x6487ED5110B4611A62633145C06E0E68i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 1,
};
/// Pi divided by three (π/3 ≈ 1.04719755119659774615...)
pub const PI_OVER_THREE: Self = Self {
real: (0x430548E0B5CD961196ECCB83D59EB446i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 1,
};
/// Pi divided by four (π/4 ≈ 0.78539816339744830962...)
pub const PI_OVER_FOUR: Self = Self {
real: (0x6487ED5110B4611A62633145C06E0E69i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 0,
};
/// Pi divided by six (π/6 ≈ 0.52359877559829887308...)
pub const PI_OVER_SIX: Self = Self {
real: (0x430548E0B5CD961196ECCB83D59EB446i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 0,
};
/// Pi divided by eight (π/8 ≈ 0.39269908169872415481...)
pub const PI_OVER_EIGHT: Self = Self {
real: (0x6487ED5110B4611A62633145C06E0E69i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: -1,
};
/// One divided by pi (1/π ≈ 0.31830988618379067154...)
pub const ONE_OVER_PI: Self = Self {
real: (0x517CC1B727220A94FE13ABE8FA9A6EE0i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: -1,
};
/// Two divided by pi (2/π ≈ 0.63661977236758134308...)
pub const TWO_OVER_PI: Self = Self {
real: (0x517CC1B727220A94FE13ABE8FA9A6EE0i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 0,
};
/// Approximately Euler's number (e ≈ 2.71828182845904523536...)
pub const E: Self = Self {
real: (0x56FC2A2C515DA54D57EE2B10139E9E79i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 2,
};
/// Approximately natural logarithm of two (ln(2) ≈ 0.69314718055994530942...)
pub const LN_TWO: Self = Self {
real: (0x58B90BFBE8E7BCD5E4F1D9CC01F97B57i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 0,
};
/// Binary logarithm of e (log₂(e) ≈ 1.44269504088896340736...)
pub const LB_E: Self = Self {
real: (0x5C551D94AE0BF85DDF43FF68348E9F44i128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 1,
};
/// Approximately square root of two (√2 ≈ 1.41421356237309504880...)
pub const SQRT_TWO: Self = Self {
real: (0x5A827999FCEF32422CBEC4D9BAA55F4Fi128 >> (128isize.wrapping_sub(<$f>::FRACTION_BITS))) as $f,
imaginary: 0,
exponent: 1,
};
}
impl CircleConstants for Circle<$f, $e> {
const MAX: Self = Self::MAX;
const MIN: Self = Self::MIN;
const MIN_POS: Self = Self::MIN_POS;
const MAX_NEG: Self = Self::MAX_NEG;
const POS_NORMAL_EPSILON: Self = Self::POS_NORMAL_EPSILON;
const NEG_NORMAL_EPSILON: Self = Self::NEG_NORMAL_EPSILON;
const MAX_CONTIGUOUS: Self = Self::MAX_CONTIGUOUS;
const MIN_CONTIGUOUS: Self = Self::MIN_CONTIGUOUS;
const ZERO: Self = Self::ZERO;
const INFINITY: Self = Self::INFINITY;
const ONE: Self = Self::ONE;
const NEG_ONE: Self = Self::NEG_ONE;
const EFFECTIVELY_POS_ONE: Self = Self::EFFECTIVELY_POS_ONE;
const EFFECTIVELY_NEG_ONE: Self = Self::EFFECTIVELY_NEG_ONE;
const TWO: Self = Self::TWO;
const HALF: Self = Self::HALF;
const POS_I: Self = Self::POS_I;
const NEG_I: Self = Self::NEG_I;
const PI: Self = Self::PI;
const NEG_PI: Self = Self::NEG_PI;
const TAU: Self = Self::TAU;
const NEG_TAU: Self = Self::NEG_TAU;
const TWO_PI: Self = Self::TWO_PI;
const PI_OVER_TWO: Self = Self::PI_OVER_TWO;
const NEG_PI_OVER_TWO: Self = Self::NEG_PI_OVER_TWO;
const PI_OVER_THREE: Self = Self::PI_OVER_THREE;
const PI_OVER_FOUR: Self = Self::PI_OVER_FOUR;
const PI_OVER_SIX: Self = Self::PI_OVER_SIX;
const PI_OVER_EIGHT: Self = Self::PI_OVER_EIGHT;
const ONE_OVER_PI: Self = Self::ONE_OVER_PI;
const TWO_OVER_PI: Self = Self::TWO_OVER_PI;
const E: Self = Self::E;
const LN_TWO: Self = Self::LN_TWO;
const LB_E: Self = Self::LB_E;
const SQRT_TWO: Self = Self::SQRT_TWO;
}
)*
}
}
impl_circle_constants!(
i8, i8;
i16, i8;
i32, i8;
i64, i8;
i128, i8;
i8, i16;
i16, i16;
i32, i16;
i64, i16;
i128, i16;
i8, i32;
i16, i32;
i32, i32;
i64, i32;
i128, i32;
i8, i64;
i16, i64;
i32, i64;
i64, i64;
i128, i64;
i8, i128;
i16, i128;
i32, i128;
i64, i128;
i128, i128
);