-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInt256Le.cs
More file actions
397 lines (369 loc) · 25 KB
/
Copy pathInt256Le.cs
File metadata and controls
397 lines (369 loc) · 25 KB
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
using System;
using System.Buffers.Binary;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Stardust.Utilities
{
/// <summary>
/// Little-endian 256-bit signed integer type (two's complement).
/// Stores bytes in little-endian order (least significant byte first, x86 native order).
/// Use this type at I/O boundaries; convert to <see cref="Int256"/> for arithmetic.
/// </summary>
[Serializable]
[TypeConverter(typeof(Int256LeTypeConverter))]
[StructLayout(LayoutKind.Explicit, Size = 32)]
public struct Int256Le : IComparable, IComparable<Int256Le>, IEquatable<Int256Le>,
IFormattable, ISpanFormattable, IParsable<Int256Le>, ISpanParsable<Int256Le>
{
// Little-endian: least-significant bits at the lowest address.
[FieldOffset(0)] internal UInt128Le lo; // bits 0-127
[FieldOffset(16)] internal UInt128Le hi; // bits 128-255 (sign bit is MSB of hi)
/// <summary>Initializes a new <see cref="Int256Le"/> from an <see cref="Int256"/> value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Int256Le(Int256 num)
{
#if BIG_ENDIAN
// On BE: each limb must be byte-swapped to land in LE order.
UInt256 u = (UInt256)num;
Unsafe.SkipInit(out this);
Span<byte> raw = MemoryMarshal.AsBytes(MemoryMarshal.CreateSpan(ref this, 1));
BinaryPrimitives.WriteUInt64LittleEndian(raw, u._p0);
BinaryPrimitives.WriteUInt64LittleEndian(raw[8..], u._p1);
BinaryPrimitives.WriteUInt64LittleEndian(raw[16..], u._p2);
BinaryPrimitives.WriteUInt64LittleEndian(raw[24..], u._p3);
#else
// On LE: Int256Le and Int256 share identical memory layout — direct copy.
Unsafe.SkipInit(out this);
Unsafe.As<Int256Le, Int256>(ref this) = num;
#endif
}
/// <summary>Initializes a new <see cref="Int256Le"/> from a read-only byte span (little-endian, least-significant byte first).</summary>
/// <exception cref="ArgumentException"><paramref name="bytes"/> has fewer than 32 bytes.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Int256Le(ReadOnlySpan<byte> bytes)
{
if (bytes.Length < 32) throw new ArgumentException("Span must have at least 32 bytes", nameof(bytes));
Unsafe.SkipInit(out this);
bytes[..32].CopyTo(MemoryMarshal.AsBytes(MemoryMarshal.CreateSpan(ref this, 1)));
}
/// <summary>
/// Initializes a new <see cref="Int256Le"/> from a read-only byte span whose byte order is specified.
/// </summary>
/// <param name="bytes">Source span (must have at least 32 bytes).</param>
/// <param name="isBigEndian">If <see langword="false"/> the source is interpreted as little-endian; if <see langword="true"/> it is interpreted as big-endian and reversed during storage.</param>
/// <exception cref="ArgumentException">If span is too short.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Int256Le(ReadOnlySpan<byte> bytes, bool isBigEndian)
{
if (bytes.Length < 32) throw new ArgumentException("Span must have at least 32 bytes", nameof(bytes));
Unsafe.SkipInit(out this);
Span<byte> dst = MemoryMarshal.AsBytes(MemoryMarshal.CreateSpan(ref this, 1));
if (isBigEndian)
{
for (int i = 0; i < 32; i++) dst[i] = bytes[31 - i];
}
else
{
bytes[..32].CopyTo(dst);
}
}
/// <summary>Initializes a new <see cref="Int256Le"/> from a read-only byte span at the given offset.</summary>
/// <param name="bytes">Source byte span (must have at least 32 bytes starting from <paramref name="offset"/>).</param>
/// <param name="offset">Starting offset in the span.</param>
/// <param name="isBigEndian">If <see langword="false"/> the source is interpreted as little-endian; if <see langword="true"/> it is interpreted as big-endian and reversed during storage.</param>
/// <exception cref="ArgumentException"><paramref name="bytes"/> is too short.</exception>
public Int256Le(ReadOnlySpan<byte> bytes, int offset, bool isBigEndian = false)
{
if (bytes.Length - offset < 32) throw new ArgumentException("Span must have at least 32 bytes", nameof(bytes));
Unsafe.SkipInit(out this);
Span<byte> dst = MemoryMarshal.AsBytes(MemoryMarshal.CreateSpan(ref this, 1));
if (isBigEndian)
{
for (int i = 0; i < 32; i++) dst[i] = bytes[offset + 31 - i];
}
else
{
bytes.Slice(offset, 32).CopyTo(dst);
}
}
/// <summary>Initializes a new <see cref="Int256Le"/> from a byte array whose byte order is specified.</summary>
/// <param name="bytes">Source byte array (must have at least 32 bytes).</param>
/// <param name="isBigEndian">If <see langword="false"/> (default) the source is interpreted as little-endian; if <see langword="true"/> it is interpreted as big-endian and reversed during storage.</param>
/// <exception cref="ArgumentException">If array is too short.</exception>
public Int256Le(byte[] bytes, bool isBigEndian = false) : this(new ReadOnlySpan<byte>(bytes), isBigEndian) { }
/// <summary>Initializes a new <see cref="Int256Le"/> from a byte array at the given offset.</summary>
/// <param name="bytes">Source byte array (must have at least 32 bytes starting from <paramref name="offset"/>).</param>
/// <param name="offset">Starting offset in the array.</param>
/// <param name="isBigEndian">If <see langword="false"/> (default) the source is interpreted as little-endian; if <see langword="true"/> it is interpreted as big-endian and reversed during storage.</param>
/// <exception cref="ArgumentException">If array is too short.</exception>
public Int256Le(byte[] bytes, int offset, bool isBigEndian = false) : this(new ReadOnlySpan<byte>(bytes), offset, isBigEndian) { }
/// <summary>Writes the value to a byte array in the specified byte order.</summary>
/// <param name="bytes">Destination byte array.</param>
/// <param name="offset">Starting offset in the array.</param>
/// <param name="isBigEndian">If <see langword="false"/> (default) bytes are written little-endian; if <see langword="true"/> they are written big-endian.</param>
[Obsolete("Use WriteTo(byte[], int, bool) instead.")]
public readonly void ToBytes(byte[] bytes, int offset = 0, bool isBigEndian = false)
=> WriteTo(new Span<byte>(bytes), offset, isBigEndian);
/// <summary>Writes the value to a destination span in the specified byte order.</summary>
/// <param name="destination">Destination span (must have at least 32 bytes starting from <paramref name="offset"/>).</param>
/// <param name="offset">Starting offset in the destination span.</param>
/// <param name="isBigEndian">If <see langword="false"/> (default) bytes are written little-endian; if <see langword="true"/> they are written big-endian.</param>
/// <exception cref="ArgumentException"><paramref name="destination"/> has fewer than 32 bytes.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void WriteTo(Span<byte> destination, int offset = 0, bool isBigEndian = false)
{
if (destination.Length - offset < 32) throw new ArgumentException("Destination span must have at least 32 bytes", nameof(destination));
ReadOnlySpan<byte> src = MemoryMarshal.AsBytes(MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef(in this), 1));
if (isBigEndian)
{
for (int i = 0; i < 32; i++) destination[offset + i] = src[31 - i];
}
else
{
src.CopyTo(destination.Slice(offset));
}
}
/// <summary>Writes the value to a byte array in the specified byte order.</summary>
/// <param name="destination">Destination byte array (must have at least 32 bytes starting from <paramref name="offset"/>).</param>
/// <param name="offset">Starting offset in the array.</param>
/// <param name="isBigEndian">If <see langword="false"/> (default) bytes are written little-endian; if <see langword="true"/> they are written big-endian.</param>
/// <exception cref="ArgumentException">If array is too short.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void WriteTo(byte[] destination, int offset = 0, bool isBigEndian = false)
=> WriteTo(new Span<byte>(destination), offset, isBigEndian);
/// <summary>Attempts to write the value to a destination span in the specified byte order.</summary>
/// <param name="destination">Destination span.</param>
/// <param name="offset">Starting offset in the destination span.</param>
/// <param name="isBigEndian">If <see langword="false"/> (default) bytes are written little-endian; if <see langword="true"/> they are written big-endian.</param>
/// <returns><see langword="true"/> if successful; <see langword="false"/> if the span is too short.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool TryWriteTo(Span<byte> destination, int offset = 0, bool isBigEndian = false)
{
if (destination.Length - offset < 32) return false;
ReadOnlySpan<byte> src = MemoryMarshal.AsBytes(MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef(in this), 1));
if (isBigEndian)
{
for (int i = 0; i < 32; i++) destination[offset + i] = src[31 - i];
}
else
{
src.CopyTo(destination.Slice(offset));
}
return true;
}
/// <summary>Attempts to write the value to a byte array in the specified byte order.</summary>
/// <param name="destination">Destination byte array.</param>
/// <param name="offset">Starting offset in the array.</param>
/// <param name="isBigEndian">If <see langword="false"/> (default) bytes are written little-endian; if <see langword="true"/> they are written big-endian.</param>
/// <returns><see langword="true"/> if successful; <see langword="false"/> if the array is too short.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool TryWriteTo(byte[] destination, int offset = 0, bool isBigEndian = false)
=> TryWriteTo(new Span<byte>(destination), offset, isBigEndian);
/// <summary>Reads an <see cref="Int256Le"/> from a read-only byte span in the specified byte order.</summary>
/// <param name="source">Source span.</param>
/// <param name="offset">Starting offset in the source span.</param>
/// <param name="isBigEndian">If <see langword="false"/> (default) the source is interpreted as little-endian; if <see langword="true"/> it is interpreted as big-endian.</param>
/// <returns>The parsed value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le ReadFrom(ReadOnlySpan<byte> source, int offset = 0, bool isBigEndian = false) => new(source, offset, isBigEndian);
/// <summary>Reads an <see cref="Int256Le"/> from a byte array in the specified byte order.</summary>
/// <param name="source">Source byte array.</param>
/// <param name="offset">Starting offset in the array.</param>
/// <param name="isBigEndian">If <see langword="false"/> (default) the source is interpreted as little-endian; if <see langword="true"/> it is interpreted as big-endian.</param>
/// <returns>The parsed value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le ReadFrom(byte[] source, int offset = 0, bool isBigEndian = false) => new(new ReadOnlySpan<byte>(source), offset, isBigEndian);
/// <summary>Parses a string into an <see cref="Int256Le"/>.</summary>
public static Int256Le Parse(string s, NumberStyles style = NumberStyles.Integer) => new(Int256.Parse(s, style));
/// <inheritdoc/>
public static Int256Le Parse(string s, IFormatProvider? provider) => new(Int256.Parse(s, provider));
/// <inheritdoc/>
public static Int256Le Parse(ReadOnlySpan<char> s, IFormatProvider? provider) => new(Int256.Parse(s, provider));
/// <inheritdoc/>
public static bool TryParse(string? s, IFormatProvider? provider, out Int256Le result)
{
if (Int256.TryParse(s, provider, out Int256 v)) { result = new(v); return true; }
result = default; return false;
}
/// <inheritdoc/>
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Int256Le result)
{
if (Int256.TryParse(s, provider, out Int256 v)) { result = new(v); return true; }
result = default; return false;
}
/// <inheritdoc/>
public override readonly string ToString() => ((Int256)this).ToString();
/// <inheritdoc/>
public readonly string ToString(string? format, IFormatProvider? formatProvider) => ((Int256)this).ToString(format, formatProvider);
/// <inheritdoc/>
public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
((Int256)this).TryFormat(destination, out charsWritten, format, provider);
/// <inheritdoc/>
public readonly int CompareTo(object? obj) { if (obj == null) throw new ArgumentException("obj is null"); return CompareTo((Int256Le)obj); }
/// <inheritdoc/>
public readonly int CompareTo(Int256Le other) => ((Int256)this).CompareTo((Int256)other);
/// <inheritdoc/>
public override readonly bool Equals(object? obj) => obj is Int256Le other && Equals(other);
/// <inheritdoc/>
public readonly bool Equals(Int256Le other) => this == other;
/// <inheritdoc/>
public override readonly int GetHashCode() => ((Int256)this).GetHashCode();
#region Operators
/// <summary>Returns the value (unary plus).</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator +(Int256Le a) => a;
/// <summary>Negates the value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator -(Int256Le a) => new(-(Int256)a);
/// <summary>Adds two values.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator +(Int256Le a, Int256Le b) => new((Int256)a + (Int256)b);
/// <summary>Subtracts two values.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator -(Int256Le a, Int256Le b) => new((Int256)a - (Int256)b);
/// <summary>Multiplies two values.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator *(Int256Le a, Int256Le b) => new((Int256)a * (Int256)b);
/// <summary>Divides two values.</summary>
/// <exception cref="DivideByZeroException">The divisor is zero.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator /(Int256Le a, Int256Le b) => new((Int256)a / (Int256)b);
/// <summary>Computes the remainder of dividing two values.</summary>
/// <exception cref="DivideByZeroException">The divisor is zero.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator %(Int256Le a, Int256Le b) => new((Int256)a % (Int256)b);
/// <summary>Computes the bitwise AND of two values.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator &(Int256Le a, Int256Le b)
{
Unsafe.As<Int256Le, ulong>(ref a) &= Unsafe.As<Int256Le, ulong>(ref b);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 1) &= Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref b), 1);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 2) &= Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref b), 2);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 3) &= Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref b), 3);
return a;
}
/// <summary>Computes the bitwise OR of two values.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator |(Int256Le a, Int256Le b)
{
Unsafe.As<Int256Le, ulong>(ref a) |= Unsafe.As<Int256Le, ulong>(ref b);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 1) |= Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref b), 1);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 2) |= Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref b), 2);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 3) |= Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref b), 3);
return a;
}
/// <summary>Computes the bitwise XOR of two values.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator ^(Int256Le a, Int256Le b)
{
Unsafe.As<Int256Le, ulong>(ref a) ^= Unsafe.As<Int256Le, ulong>(ref b);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 1) ^= Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref b), 1);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 2) ^= Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref b), 2);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 3) ^= Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref b), 3);
return a;
}
/// <summary>Computes the bitwise complement of the value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator ~(Int256Le a)
{
Unsafe.As<Int256Le, ulong>(ref a) = ~Unsafe.As<Int256Le, ulong>(ref a);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 1) = ~Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 1);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 2) = ~Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 2);
Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 3) = ~Unsafe.Add(ref Unsafe.As<Int256Le, ulong>(ref a), 3);
return a;
}
/// <summary>Arithmetic (sign-extending) right shift.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator >>(Int256Le a, int b) => new((Int256)a >> b);
/// <summary>Unsigned (logical, zero-filling) right shift.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator >>>(Int256Le a, int b) => new((Int256)a >>> b);
/// <summary>Shifts the value left.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator <<(Int256Le a, int b) => new((Int256)a << b);
/// <summary>Increments the value by one.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator ++(Int256Le a) => new((Int256)a + Int256.One);
/// <summary>Decrements the value by one.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Int256Le operator --(Int256Le a) => new((Int256)a - Int256.One);
/// <summary>Determines whether two values are equal.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Int256Le a, Int256Le b)
{
ref ulong ra = ref Unsafe.As<Int256Le, ulong>(ref a);
ref ulong rb = ref Unsafe.As<Int256Le, ulong>(ref b);
return ra == rb
&& Unsafe.Add(ref ra, 1) == Unsafe.Add(ref rb, 1)
&& Unsafe.Add(ref ra, 2) == Unsafe.Add(ref rb, 2)
&& Unsafe.Add(ref ra, 3) == Unsafe.Add(ref rb, 3);
}
/// <summary>Determines whether two values are not equal.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Int256Le a, Int256Le b) => !(a == b);
/// <summary>Determines whether the left operand is less than the right (signed comparison).</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator <(Int256Le a, Int256Le b) => (Int256)a < (Int256)b;
/// <summary>Determines whether the left operand is greater than the right (signed comparison).</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator >(Int256Le a, Int256Le b) => (Int256)a > (Int256)b;
/// <summary>Determines whether the left operand is less than or equal to the right (signed comparison).</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator <=(Int256Le a, Int256Le b) => (Int256)a <= (Int256)b;
/// <summary>Determines whether the left operand is greater than or equal to the right (signed comparison).</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator >=(Int256Le a, Int256Le b) => (Int256)a >= (Int256)b;
#endregion
#region Conversions
/// <summary>Implicitly converts an <see cref="Int256Le"/> to an <see cref="Int256"/> (host-native, signed).</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Int256(Int256Le a)
{
#if BIG_ENDIAN
// On BE: each limb must be byte-swapped back to native order.
ReadOnlySpan<byte> raw = MemoryMarshal.AsBytes(MemoryMarshal.CreateReadOnlySpan(ref a, 1));
return (Int256)new UInt256(
BinaryPrimitives.ReadUInt64LittleEndian(raw[24..]),
BinaryPrimitives.ReadUInt64LittleEndian(raw[16..]),
BinaryPrimitives.ReadUInt64LittleEndian(raw[8..]),
BinaryPrimitives.ReadUInt64LittleEndian(raw));
#else
// On LE: Int256Le and Int256 share identical memory layout — zero-cost reinterpret.
return Unsafe.As<Int256Le, Int256>(ref a);
#endif
}
/// <summary>Implicitly converts an <see cref="Int256"/> to an <see cref="Int256Le"/>.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Int256Le(Int256 a) => new(a);
/// <summary>Widening sign-extending conversion from a 128-bit little-endian signed value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Int256Le(Int128Le a) => new((Int256)(Int128)a);
/// <summary>Widening sign-extending conversion from a 64-bit little-endian signed value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Int256Le(Int64Le a) => new((Int256)(long)a);
/// <summary>Widening sign-extending conversion from a 32-bit little-endian signed value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Int256Le(Int32Le a) => new((Int256)(int)a);
/// <summary>Narrowing conversion to a 128-bit little-endian signed value (truncates to low 128 bits).</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Int128Le(Int256Le a) => (Int128Le)(Int128)(Int256)a;
/// <summary>Narrowing conversion to a 64-bit little-endian signed value (truncates to low 64 bits).</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Int64Le(Int256Le a) => (Int64Le)(long)(Int256)a;
/// <summary>Narrowing conversion to a 32-bit little-endian signed value (truncates to low 32 bits).</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Int32Le(Int256Le a) => (Int32Le)(int)(Int256)a;
/// <summary>Explicitly reinterprets the bit pattern as an unsigned <see cref="UInt256Le"/>.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator UInt256Le(Int256Le a) => new((UInt256)(Int256)a);
/// <summary>Explicitly reinterprets the bit pattern of a <see cref="UInt256Le"/> as a signed <see cref="Int256Le"/>.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Int256Le(UInt256Le a) => new((Int256)(UInt256)a);
/// <summary>Explicitly converts to a host-native <see cref="UInt256"/> (bit-reinterpret, no sign extension).</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator UInt256(Int256Le a) => new UInt256((UInt128)a.hi, (UInt128)a.lo);
#endregion
}
}