Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Decimal.cs
Go to the documentation of this file.
11
12namespace System;
13
16[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
17public readonly struct Decimal : ISpanFormattable, IFormattable, IComparable, IConvertible, IComparable<decimal>, IEquatable<decimal>, ISerializable, IDeserializationCallback, IMinMaxValue<decimal>, ISignedNumber<decimal>, INumber<decimal>, IAdditionOperators<decimal, decimal, decimal>, IAdditiveIdentity<decimal, decimal>, IComparisonOperators<decimal, decimal>, IEqualityOperators<decimal, decimal>, IDecrementOperators<decimal>, IDivisionOperators<decimal, decimal, decimal>, IIncrementOperators<decimal>, IModulusOperators<decimal, decimal, decimal>, IMultiplicativeIdentity<decimal, decimal>, IMultiplyOperators<decimal, decimal, decimal>, ISpanParseable<decimal>, IParseable<decimal>, ISubtractionOperators<decimal, decimal, decimal>, IUnaryNegationOperators<decimal, decimal>, IUnaryPlusOperators<decimal, decimal>
18{
19 [StructLayout(LayoutKind.Explicit)]
20 private struct DecCalc
21 {
22 private struct PowerOvfl
23 {
24 public readonly uint Hi;
25
26 public readonly ulong MidLo;
27
28 public PowerOvfl(uint hi, uint mid, uint lo)
29 {
30 Hi = hi;
31 MidLo = ((ulong)mid << 32) + lo;
32 }
33 }
34
35 [StructLayout(LayoutKind.Explicit)]
36 private struct Buf12
37 {
38 [FieldOffset(0)]
39 public uint U0;
40
41 [FieldOffset(4)]
42 public uint U1;
43
44 [FieldOffset(8)]
45 public uint U2;
46
47 [FieldOffset(0)]
48 private ulong ulo64LE;
49
50 [FieldOffset(4)]
51 private ulong uhigh64LE;
52
53 public ulong Low64
54 {
55 get
56 {
57 return ulo64LE;
58 }
59 set
60 {
61 ulo64LE = value;
62 }
63 }
64
65 public ulong High64
66 {
67 get
68 {
69 return uhigh64LE;
70 }
71 set
72 {
74 }
75 }
76 }
77
78 [StructLayout(LayoutKind.Explicit)]
79 private struct Buf16
80 {
81 [FieldOffset(0)]
82 public uint U0;
83
84 [FieldOffset(4)]
85 public uint U1;
86
87 [FieldOffset(8)]
88 public uint U2;
89
90 [FieldOffset(12)]
91 public uint U3;
92
93 [FieldOffset(0)]
94 private ulong ulo64LE;
95
96 [FieldOffset(8)]
97 private ulong uhigh64LE;
98
99 public ulong Low64
100 {
101 get
102 {
103 return ulo64LE;
104 }
105 set
106 {
107 ulo64LE = value;
108 }
109 }
110
111 public ulong High64
112 {
113 get
114 {
115 return uhigh64LE;
116 }
117 set
118 {
120 }
121 }
122 }
123
124 [StructLayout(LayoutKind.Explicit)]
125 private struct Buf24
126 {
127 [FieldOffset(0)]
128 public uint U0;
129
130 [FieldOffset(4)]
131 public uint U1;
132
133 [FieldOffset(8)]
134 public uint U2;
135
136 [FieldOffset(12)]
137 public uint U3;
138
139 [FieldOffset(16)]
140 public uint U4;
141
142 [FieldOffset(20)]
143 public uint U5;
144
145 [FieldOffset(0)]
146 private ulong ulo64LE;
147
148 [FieldOffset(8)]
149 private ulong umid64LE;
150
151 [FieldOffset(16)]
152 private ulong uhigh64LE;
153
154 public ulong Low64
155 {
156 get
157 {
158 return ulo64LE;
159 }
160 set
161 {
162 ulo64LE = value;
163 }
164 }
165
166 public ulong Mid64
167 {
168 set
169 {
170 umid64LE = value;
171 }
172 }
173
174 public ulong High64
175 {
176 set
177 {
179 }
180 }
181 }
182
183 private struct Buf28
184 {
185 public Buf24 Buf24;
186
187 public uint U6;
188 }
189
190 [FieldOffset(0)]
191 private uint uflags;
192
193 [FieldOffset(4)]
194 private uint uhi;
195
196 [FieldOffset(8)]
197 private uint ulo;
198
199 [FieldOffset(12)]
200 private uint umid;
201
202 [FieldOffset(8)]
203 private ulong ulomid;
204
205 private static readonly uint[] s_powers10 = new uint[10] { 1u, 10u, 100u, 1000u, 10000u, 100000u, 1000000u, 10000000u, 100000000u, 1000000000u };
206
207 private static readonly ulong[] s_ulongPowers10 = new ulong[19]
208 {
209 10uL, 100uL, 1000uL, 10000uL, 100000uL, 1000000uL, 10000000uL, 100000000uL, 1000000000uL, 10000000000uL,
210 100000000000uL, 1000000000000uL, 10000000000000uL, 100000000000000uL, 1000000000000000uL, 10000000000000000uL, 100000000000000000uL, 1000000000000000000uL, 10000000000000000000uL
211 };
212
213 private static readonly double[] s_doublePowers10 = new double[81]
214 {
215 1.0, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, 10000000.0, 100000000.0, 1000000000.0,
216 10000000000.0, 100000000000.0, 1000000000000.0, 10000000000000.0, 100000000000000.0, 1000000000000000.0, 10000000000000000.0, 1E+17, 1E+18, 1E+19,
217 1E+20, 1E+21, 1E+22, 1E+23, 1E+24, 1E+25, 1E+26, 1E+27, 1E+28, 1E+29,
218 1E+30, 1E+31, 1E+32, 1E+33, 1E+34, 1E+35, 1E+36, 1E+37, 1E+38, 1E+39,
219 1E+40, 1E+41, 1E+42, 1E+43, 1E+44, 1E+45, 1E+46, 1E+47, 1E+48, 1E+49,
220 1E+50, 1E+51, 1E+52, 1E+53, 1E+54, 1E+55, 1E+56, 1E+57, 1E+58, 1E+59,
221 1E+60, 1E+61, 1E+62, 1E+63, 1E+64, 1E+65, 1E+66, 1E+67, 1E+68, 1E+69,
222 1E+70, 1E+71, 1E+72, 1E+73, 1E+74, 1E+75, 1E+76, 1E+77, 1E+78, 1E+79,
223 1E+80
224 };
225
226 private static readonly PowerOvfl[] PowerOvflValues = new PowerOvfl[8]
227 {
228 new PowerOvfl(429496729u, 2576980377u, 2576980377u),
229 new PowerOvfl(42949672u, 4123168604u, 687194767u),
230 new PowerOvfl(4294967u, 1271310319u, 2645699854u),
231 new PowerOvfl(429496u, 3133608139u, 694066715u),
232 new PowerOvfl(42949u, 2890341191u, 2216890319u),
233 new PowerOvfl(4294u, 4154504685u, 2369172679u),
234 new PowerOvfl(429u, 2133437386u, 4102387834u),
235 new PowerOvfl(42u, 4078814305u, 410238783u)
236 };
237
238 private uint High
239 {
240 get
241 {
242 return uhi;
243 }
244 set
245 {
246 uhi = value;
247 }
248 }
249
250 private uint Low
251 {
252 get
253 {
254 return ulo;
255 }
256 set
257 {
258 ulo = value;
259 }
260 }
261
262 private uint Mid
263 {
264 get
265 {
266 return umid;
267 }
268 set
269 {
270 umid = value;
271 }
272 }
273
274 private bool IsNegative => (int)uflags < 0;
275
276 private int Scale => (byte)(uflags >> 16);
277
278 private ulong Low64
279 {
280 get
281 {
282 return ulomid;
283 }
284 set
285 {
286 ulomid = value;
287 }
288 }
289
290 private unsafe static uint GetExponent(float f)
291 {
292 return (byte)(*(uint*)(&f) >> 23);
293 }
294
295 private unsafe static uint GetExponent(double d)
296 {
297 return (uint)(int)((ulong)(*(long*)(&d)) >> 52) & 0x7FFu;
298 }
299
300 private static ulong UInt32x32To64(uint a, uint b)
301 {
302 return (ulong)a * (ulong)b;
303 }
304
305 private static void UInt64x64To128(ulong a, ulong b, ref DecCalc result)
306 {
307 ulong num = UInt32x32To64((uint)a, (uint)b);
308 ulong num2 = UInt32x32To64((uint)a, (uint)(b >> 32));
309 ulong num3 = UInt32x32To64((uint)(a >> 32), (uint)(b >> 32));
310 num3 += num2 >> 32;
311 num += (num2 <<= 32);
312 if (num < num2)
313 {
314 num3++;
315 }
316 num2 = UInt32x32To64((uint)(a >> 32), (uint)b);
317 num3 += num2 >> 32;
318 num += (num2 <<= 32);
319 if (num < num2)
320 {
321 num3++;
322 }
323 if (num3 > uint.MaxValue)
324 {
326 }
327 result.Low64 = num;
328 result.High = (uint)num3;
329 }
330
331 private static uint Div96By32(ref Buf12 bufNum, uint den)
332 {
333 ulong high;
334 ulong num2;
335 if (bufNum.U2 != 0)
336 {
337 high = bufNum.High64;
338 num2 = (bufNum.High64 = high / den);
339 high = (high - (uint)((int)num2 * (int)den) << 32) | bufNum.U0;
340 if (high == 0L)
341 {
342 return 0u;
343 }
344 return (uint)(int)high - (bufNum.U0 = (uint)(high / den)) * den;
345 }
346 high = bufNum.Low64;
347 if (high == 0L)
348 {
349 return 0u;
350 }
351 num2 = (bufNum.Low64 = high / den);
352 return (uint)(high - num2 * den);
353 }
354
355 [MethodImpl(MethodImplOptions.AggressiveInlining)]
356 private static bool Div96ByConst(ref ulong high64, ref uint low, uint pow)
357 {
358 ulong num = high64 / pow;
359 uint num2 = (uint)(((high64 - num * pow << 32) + low) / pow);
360 if (low == num2 * pow)
361 {
362 high64 = num;
363 low = num2;
364 return true;
365 }
366 return false;
367 }
368
369 [MethodImpl(MethodImplOptions.AggressiveInlining)]
370 private static void Unscale(ref uint low, ref ulong high64, ref int scale)
371 {
372 while ((byte)low == 0 && scale >= 8 && Div96ByConst(ref high64, ref low, 100000000u))
373 {
374 scale -= 8;
375 }
376 if ((low & 0xF) == 0 && scale >= 4 && Div96ByConst(ref high64, ref low, 10000u))
377 {
378 scale -= 4;
379 }
380 if ((low & 3) == 0 && scale >= 2 && Div96ByConst(ref high64, ref low, 100u))
381 {
382 scale -= 2;
383 }
384 if ((low & 1) == 0 && scale >= 1 && Div96ByConst(ref high64, ref low, 10u))
385 {
386 scale--;
387 }
388 }
389
390 private static uint Div96By64(ref Buf12 bufNum, ulong den)
391 {
392 uint u = bufNum.U2;
393 uint num;
394 ulong low;
395 if (u == 0)
396 {
397 low = bufNum.Low64;
398 if (low < den)
399 {
400 return 0u;
401 }
402 num = (uint)(low / den);
403 low -= num * den;
405 return num;
406 }
407 uint num2 = (uint)(den >> 32);
408 if (u >= num2)
409 {
410 low = bufNum.Low64;
411 low -= den << 32;
412 num = 0u;
413 do
414 {
415 num--;
416 low += den;
417 }
418 while (low >= den);
420 return num;
421 }
422 ulong high = bufNum.High64;
423 if (high < num2)
424 {
425 return 0u;
426 }
427 num = (uint)(high / num2);
428 low = bufNum.U0 | (high - num * num2 << 32);
429 ulong num3 = UInt32x32To64(num, (uint)den);
430 low -= num3;
431 if (low > ~num3)
432 {
433 do
434 {
435 num--;
436 low += den;
437 }
438 while (low >= den);
439 }
441 return num;
442 }
443
444 private static uint Div128By96(ref Buf16 bufNum, ref Buf12 bufDen)
445 {
446 ulong high = bufNum.High64;
447 uint u = bufDen.U2;
448 if (high < u)
449 {
450 return 0u;
451 }
452 uint num = (uint)(high / u);
453 uint num2 = (uint)(int)high - num * u;
454 ulong num3 = UInt32x32To64(num, bufDen.U0);
455 ulong num4 = UInt32x32To64(num, bufDen.U1);
456 num4 += num3 >> 32;
457 num3 = (uint)num3 | (num4 << 32);
458 num4 >>= 32;
459 ulong low = bufNum.Low64;
460 low -= num3;
461 num2 -= (uint)(int)num4;
462 if (low > ~num3)
463 {
464 num2--;
465 if (num2 >= (uint)(~num4))
466 {
467 goto IL_008b;
468 }
469 }
470 else if (num2 > (uint)(~num4))
471 {
472 goto IL_008b;
473 }
474 goto IL_00b4;
475 IL_008b:
476 num3 = bufDen.Low64;
477 do
478 {
479 num--;
480 low += num3;
481 num2 += u;
482 }
483 while ((low >= num3 || num2++ >= u) && num2 >= u);
484 goto IL_00b4;
485 IL_00b4:
487 bufNum.U2 = num2;
488 return num;
489 }
490
491 private static uint IncreaseScale(ref Buf12 bufNum, uint power)
492 {
493 ulong num = UInt32x32To64(bufNum.U0, power);
494 bufNum.U0 = (uint)num;
495 num >>= 32;
496 num += UInt32x32To64(bufNum.U1, power);
497 bufNum.U1 = (uint)num;
498 num >>= 32;
499 num += UInt32x32To64(bufNum.U2, power);
500 bufNum.U2 = (uint)num;
501 return (uint)(num >> 32);
502 }
503
504 private static void IncreaseScale64(ref Buf12 bufNum, uint power)
505 {
506 ulong num = UInt32x32To64(bufNum.U0, power);
507 bufNum.U0 = (uint)num;
508 num >>= 32;
509 num += UInt32x32To64(bufNum.U1, power);
510 bufNum.High64 = num;
511 }
512
513 private unsafe static int ScaleResult(Buf24* bufRes, uint hiRes, int scale)
514 {
515 int num = 0;
516 if (hiRes > 2)
517 {
518 num = (int)(hiRes * 32 - 64 - 1);
519 num -= BitOperations.LeadingZeroCount(*(uint*)((byte*)bufRes + (long)hiRes * 4L));
520 num = (num * 77 >> 8) + 1;
521 if (num > scale)
522 {
523 goto IL_01cc;
524 }
525 }
526 if (num < scale - 28)
527 {
528 num = scale - 28;
529 }
530 if (num == 0)
531 {
532 goto IL_01ca;
533 }
534 scale -= num;
535 uint num2 = 0u;
536 uint remainder = 0u;
537 while (true)
538 {
539 num2 |= remainder;
540 uint num3 = num switch
541 {
542 1 => DivByConst((uint*)bufRes, hiRes, out var quotient, out remainder, 10u),
543 2 => DivByConst((uint*)bufRes, hiRes, out quotient, out remainder, 100u),
544 3 => DivByConst((uint*)bufRes, hiRes, out quotient, out remainder, 1000u),
545 4 => DivByConst((uint*)bufRes, hiRes, out quotient, out remainder, 10000u),
546 5 => DivByConst((uint*)bufRes, hiRes, out quotient, out remainder, 100000u),
547 6 => DivByConst((uint*)bufRes, hiRes, out quotient, out remainder, 1000000u),
548 7 => DivByConst((uint*)bufRes, hiRes, out quotient, out remainder, 10000000u),
549 8 => DivByConst((uint*)bufRes, hiRes, out quotient, out remainder, 100000000u),
550 _ => DivByConst((uint*)bufRes, hiRes, out quotient, out remainder, 1000000000u),
551 };
552 *(uint*)((byte*)bufRes + (long)hiRes * 4L) = quotient;
553 if (quotient == 0 && hiRes != 0)
554 {
555 hiRes--;
556 }
557 num -= 9;
558 if (num > 0)
559 {
560 continue;
561 }
562 if (hiRes > 2)
563 {
564 if (scale == 0)
565 {
566 break;
567 }
568 num = 1;
569 scale--;
570 continue;
571 }
572 num3 >>= 1;
573 if (num3 <= remainder && (num3 < remainder || ((*(uint*)bufRes & (true ? 1u : 0u)) | num2) != 0) && ++(*(int*)bufRes) == 0)
574 {
575 uint num4 = 0u;
576 while (++(*(int*)((byte*)bufRes + (long)(++num4) * 4L)) == 0)
577 {
578 }
579 if (num4 > 2)
580 {
581 if (scale == 0)
582 {
583 break;
584 }
585 hiRes = num4;
586 num2 = 0u;
587 remainder = 0u;
588 num = 1;
589 scale--;
590 continue;
591 }
592 }
593 goto IL_01ca;
594 }
595 goto IL_01cc;
596 IL_01cc:
598 return 0;
599 IL_01ca:
600 return scale;
601 }
602
603 [MethodImpl(MethodImplOptions.AggressiveInlining)]
604 private unsafe static uint DivByConst(uint* result, uint hiRes, out uint quotient, out uint remainder, uint power)
605 {
606 uint num = result[hiRes];
607 remainder = num - (quotient = num / power) * power;
608 uint num2 = hiRes - 1;
609 while ((int)num2 >= 0)
610 {
611 ulong num3 = result[num2] + ((ulong)remainder << 32);
612 remainder = (uint)(int)num3 - (result[num2] = (uint)(num3 / power)) * power;
613 num2--;
614 }
615 return power;
616 }
617
618 private static int OverflowUnscale(ref Buf12 bufQuo, int scale, bool sticky)
619 {
620 if (--scale < 0)
621 {
623 }
624 bufQuo.U2 = 429496729u;
625 ulong num = 25769803776uL + (ulong)bufQuo.U1;
626 num = (num - (bufQuo.U1 = (uint)(num / 10)) * 10 << 32) + bufQuo.U0;
627 uint num2 = (uint)(num - (bufQuo.U0 = (uint)(num / 10)) * 10);
628 if (num2 > 5 || (num2 == 5 && (sticky || (bufQuo.U0 & (true ? 1u : 0u)) != 0)))
629 {
631 }
632 return scale;
633 }
634
635 private static int SearchScale(ref Buf12 bufQuo, int scale)
636 {
637 uint u = bufQuo.U2;
638 ulong low = bufQuo.Low64;
639 int num = 0;
640 if (u <= 429496729)
641 {
643 if (scale > 19)
644 {
645 num = 28 - scale;
646 if (u < powerOvflValues[num - 1].Hi)
647 {
648 goto IL_00d1;
649 }
650 }
651 else if (u < 4 || (u == 4 && low <= 5441186219426131129L))
652 {
653 return 9;
654 }
655 if (u > 42949)
656 {
657 if (u > 4294967)
658 {
659 num = 2;
660 if (u > 42949672)
661 {
662 num--;
663 }
664 }
665 else
666 {
667 num = 4;
668 if (u > 429496)
669 {
670 num--;
671 }
672 }
673 }
674 else if (u > 429)
675 {
676 num = 6;
677 if (u > 4294)
678 {
679 num--;
680 }
681 }
682 else
683 {
684 num = 8;
685 if (u > 42)
686 {
687 num--;
688 }
689 }
690 if (u == powerOvflValues[num - 1].Hi && low > powerOvflValues[num - 1].MidLo)
691 {
692 num--;
693 }
694 }
695 goto IL_00d1;
696 IL_00d1:
697 if (num + scale < 0)
698 {
700 }
701 return num;
702 }
703
704 private static bool Add32To96(ref Buf12 bufNum, uint value)
705 {
706 if ((bufNum.Low64 += value) < value && ++bufNum.U2 == 0)
707 {
708 return false;
709 }
710 return true;
711 }
712
713 internal unsafe static void DecAddSub(ref DecCalc d1, ref DecCalc d2, bool sign)
714 {
715 ulong num = d1.Low64;
716 uint num2 = d1.High;
717 uint num3 = d1.uflags;
718 uint num4 = d2.uflags;
719 uint num5 = num4 ^ num3;
720 sign ^= (num5 & 0x80000000u) != 0;
721 int num7;
722 if ((num5 & 0xFF0000u) != 0)
723 {
724 uint num6 = num3;
725 num3 = (num4 & 0xFF0000u) | (num3 & 0x80000000u);
726 num7 = (int)(num3 - num6) >> 16;
727 if (num7 < 0)
728 {
729 num7 = -num7;
730 num3 = num6;
731 if (sign)
732 {
733 num3 ^= 0x80000000u;
734 }
735 num = d2.Low64;
736 num2 = d2.High;
737 d2 = d1;
738 }
739 if (num2 != 0)
740 {
741 goto IL_015f;
742 }
743 if (num > uint.MaxValue)
744 {
745 goto IL_0106;
746 }
747 if ((int)num == 0)
748 {
749 uint num8 = num3 & 0x80000000u;
750 if (sign)
751 {
752 num8 ^= 0x80000000u;
753 }
754 d1 = d2;
755 d1.uflags = (d2.uflags & 0xFF0000u) | num8;
756 return;
757 }
758 while (num7 > 9)
759 {
760 num7 -= 9;
761 num = UInt32x32To64((uint)num, 1000000000u);
762 if (num <= uint.MaxValue)
763 {
764 continue;
765 }
766 goto IL_0106;
767 }
768 num = UInt32x32To64((uint)num, s_powers10[num7]);
769 }
770 goto IL_0450;
771 IL_0106:
772 ulong num10;
773 while (true)
774 {
775 uint b = 1000000000u;
776 if (num7 < 9)
777 {
778 b = s_powers10[num7];
779 }
780 ulong num9 = UInt32x32To64((uint)num, b);
781 num10 = UInt32x32To64((uint)(num >> 32), b) + (num9 >> 32);
782 num = (uint)num9 + (num10 << 32);
783 num2 = (uint)(num10 >> 32);
784 if ((num7 -= 9) <= 0)
785 {
786 break;
787 }
788 if (num2 == 0)
789 {
790 continue;
791 }
792 goto IL_015f;
793 }
794 goto IL_0450;
795 IL_0350:
796 Buf24 value;
797 value.Low64 = num;
798 value.U2 = num2;
799 uint num11;
800 num7 = ScaleResult(&value, num11, (byte)(num3 >> 16));
801 num3 = (num3 & 0xFF00FFFFu) | (uint)(num7 << 16);
802 num = value.Low64;
803 num2 = value.U2;
804 goto IL_04b9;
805 IL_015f:
806 while (true)
807 {
808 uint b = 1000000000u;
809 if (num7 < 9)
810 {
811 b = s_powers10[num7];
812 }
813 ulong num9 = UInt32x32To64((uint)num, b);
814 num10 = UInt32x32To64((uint)(num >> 32), b) + (num9 >> 32);
815 num = (uint)num9 + (num10 << 32);
816 num10 >>= 32;
818 num7 -= 9;
819 if (num10 > uint.MaxValue)
820 {
821 break;
822 }
823 num2 = (uint)num10;
824 if (num7 > 0)
825 {
826 continue;
827 }
828 goto IL_0450;
829 }
830 Unsafe.SkipInit<Buf24>(out value);
831 value.Low64 = num;
833 num11 = 3u;
834 while (num7 > 0)
835 {
836 uint b = 1000000000u;
837 if (num7 < 9)
838 {
839 b = s_powers10[num7];
840 }
841 num10 = 0uL;
842 uint* ptr = (uint*)(&value);
843 uint num12 = 0u;
844 do
845 {
847 ptr[num12] = (uint)num10;
848 num12++;
849 num10 >>= 32;
850 }
851 while (num12 <= num11);
852 if ((uint)num10 != 0)
853 {
854 ptr[++num11] = (uint)num10;
855 }
856 num7 -= 9;
857 }
858 num10 = value.Low64;
859 num = d2.Low64;
860 uint u = value.U2;
861 num2 = d2.High;
862 if (sign)
863 {
864 num = num10 - num;
865 num2 = u - num2;
866 if (num > num10)
867 {
868 num2--;
869 if (num2 >= u)
870 {
871 goto IL_02b3;
872 }
873 }
874 else if (num2 > u)
875 {
876 goto IL_02b3;
877 }
878 }
879 else
880 {
881 num += num10;
882 num2 += u;
883 if (num < num10)
884 {
885 num2++;
886 if (num2 <= u)
887 {
888 goto IL_0312;
889 }
890 }
891 else if (num2 < u)
892 {
893 goto IL_0312;
894 }
895 }
896 goto IL_0350;
897 IL_0312:
898 uint* ptr2 = (uint*)(&value);
899 uint num13 = 3u;
900 while (++ptr2[num13++] == 0)
901 {
902 if (num11 < num13)
903 {
904 ptr2[num13] = 1u;
905 num11 = num13;
906 break;
907 }
908 }
909 goto IL_0350;
910 IL_0450:
911 ulong num14 = num;
912 uint num15 = num2;
913 if (sign)
914 {
915 num = num14 - d2.Low64;
916 num2 = num15 - d2.High;
917 if (num > num14)
918 {
919 num2--;
920 if (num2 >= num15)
921 {
922 goto IL_0394;
923 }
924 }
925 else if (num2 > num15)
926 {
927 goto IL_0394;
928 }
929 }
930 else
931 {
932 num = num14 + d2.Low64;
933 num2 = num15 + d2.High;
934 if (num < num14)
935 {
936 num2++;
937 if (num2 <= num15)
938 {
939 goto IL_03b1;
940 }
941 }
942 else if (num2 < num15)
943 {
944 goto IL_03b1;
945 }
946 }
947 goto IL_04b9;
948 IL_04b9:
949 d1.uflags = num3;
950 d1.High = num2;
951 d1.Low64 = num;
952 return;
953 IL_0394:
954 num3 ^= 0x80000000u;
955 num2 = ~num2;
956 num = 0L - num;
957 if (num == 0L)
958 {
959 num2++;
960 }
961 goto IL_04b9;
962 IL_02b3:
963 uint* ptr3 = (uint*)(&value);
964 uint num16 = 3u;
965 while (ptr3[num16++]-- == 0)
966 {
967 }
968 if (ptr3[num11] != 0 || --num11 > 2)
969 {
970 goto IL_0350;
971 }
972 goto IL_04b9;
973 IL_03b1:
974 if ((num3 & 0xFF0000) == 0)
975 {
977 }
978 num3 -= 65536;
979 ulong num17 = (ulong)num2 + 4294967296uL;
980 num2 = (uint)(num17 / 10);
981 num17 = (num17 - num2 * 10 << 32) + (num >> 32);
982 uint num18 = (uint)(num17 / 10);
983 num17 = (num17 - num18 * 10 << 32) + (uint)num;
984 num = num18;
985 num <<= 32;
986 num18 = (uint)(num17 / 10);
987 num += num18;
988 num18 = (uint)(int)num17 - num18 * 10;
989 if (num18 >= 5 && (num18 > 5 || (num & 1) != 0L) && ++num == 0L)
990 {
991 num2++;
992 }
993 goto IL_04b9;
994 }
995
996 internal static long VarCyFromDec(ref DecCalc pdecIn)
997 {
998 int num = pdecIn.Scale - 4;
999 long num4;
1000 if (num < 0)
1001 {
1002 if (pdecIn.High == 0)
1003 {
1004 uint a = s_powers10[-num];
1005 ulong num2 = UInt32x32To64(a, pdecIn.Mid);
1006 if (num2 <= uint.MaxValue)
1007 {
1008 ulong num3 = UInt32x32To64(a, pdecIn.Low);
1009 num3 += (num2 <<= 32);
1010 if (num3 >= num2)
1011 {
1012 num4 = (long)num3;
1013 goto IL_006d;
1014 }
1015 }
1016 }
1017 }
1018 else
1019 {
1020 if (num != 0)
1021 {
1022 InternalRound(ref pdecIn, (uint)num, MidpointRounding.ToEven);
1023 }
1024 if (pdecIn.High == 0)
1025 {
1026 num4 = (long)pdecIn.Low64;
1027 goto IL_006d;
1028 }
1029 }
1030 goto IL_0093;
1031 IL_0093:
1033 IL_006d:
1034 if (num4 >= 0 || (num4 == long.MinValue && pdecIn.IsNegative))
1035 {
1036 if (pdecIn.IsNegative)
1037 {
1038 num4 = -num4;
1039 }
1040 return num4;
1041 }
1042 goto IL_0093;
1043 }
1044
1045 internal static int VarDecCmp(in decimal d1, in decimal d2)
1046 {
1047 if ((d2.Low64 | d2.High) == 0L)
1048 {
1049 if ((d1.Low64 | d1.High) == 0L)
1050 {
1051 return 0;
1052 }
1053 return (d1._flags >> 31) | 1;
1054 }
1055 if ((d1.Low64 | d1.High) == 0L)
1056 {
1057 return -((d2._flags >> 31) | 1);
1058 }
1059 int num = (d1._flags >> 31) - (d2._flags >> 31);
1060 if (num != 0)
1061 {
1062 return num;
1063 }
1064 return VarDecCmpSub(in d1, in d2);
1065 }
1066
1067 private static int VarDecCmpSub(in decimal d1, in decimal d2)
1068 {
1069 int flags = d2._flags;
1070 int num = (flags >> 31) | 1;
1071 int num2 = flags - d1._flags;
1072 ulong num3 = d1.Low64;
1073 uint num4 = d1.High;
1074 ulong num5 = d2.Low64;
1075 uint num6 = d2.High;
1076 if (num2 != 0)
1077 {
1078 num2 >>= 16;
1079 if (num2 < 0)
1080 {
1081 num2 = -num2;
1082 num = -num;
1083 ulong num7 = num3;
1084 num3 = num5;
1085 num5 = num7;
1086 uint num8 = num4;
1087 num4 = num6;
1088 num6 = num8;
1089 }
1090 do
1091 {
1092 uint b = ((num2 >= 9) ? 1000000000u : s_powers10[num2]);
1093 ulong num9 = UInt32x32To64((uint)num3, b);
1094 ulong num10 = UInt32x32To64((uint)(num3 >> 32), b) + (num9 >> 32);
1095 num3 = (uint)num9 + (num10 << 32);
1096 num10 >>= 32;
1098 if (num10 > uint.MaxValue)
1099 {
1100 return num;
1101 }
1102 num4 = (uint)num10;
1103 }
1104 while ((num2 -= 9) > 0);
1105 }
1106 uint num11 = num4 - num6;
1107 if (num11 != 0)
1108 {
1109 if (num11 > num4)
1110 {
1111 num = -num;
1112 }
1113 return num;
1114 }
1115 ulong num12 = num3 - num5;
1116 if (num12 == 0L)
1117 {
1118 num = 0;
1119 }
1120 else if (num12 > num3)
1121 {
1122 num = -num;
1123 }
1124 return num;
1125 }
1126
1127 internal unsafe static void VarDecMul(ref DecCalc d1, ref DecCalc d2)
1128 {
1129 int num = (byte)(d1.uflags + d2.uflags >> 16);
1130 Unsafe.SkipInit<Buf24>(out var value);
1131 uint num6;
1132 if ((d1.High | d1.Mid) == 0)
1133 {
1134 ulong num4;
1135 if ((d2.High | d2.Mid) == 0)
1136 {
1137 ulong num2 = UInt32x32To64(d1.Low, d2.Low);
1138 if (num > 28)
1139 {
1140 if (num > 47)
1141 {
1142 goto IL_03b4;
1143 }
1144 num -= 29;
1145 ulong num3 = s_ulongPowers10[num];
1146 num4 = num2 / num3;
1147 ulong num5 = num2 - num4 * num3;
1148 num2 = num4;
1149 num3 >>= 1;
1150 if (num5 >= num3 && (num5 > num3 || ((uint)(int)num2 & (true ? 1u : 0u)) != 0))
1151 {
1152 num2++;
1153 }
1154 num = 28;
1155 }
1156 d1.Low64 = num2;
1157 d1.uflags = ((d2.uflags ^ d1.uflags) & 0x80000000u) | (uint)(num << 16);
1158 return;
1159 }
1160 num4 = UInt32x32To64(d1.Low, d2.Low);
1161 value.U0 = (uint)num4;
1162 num4 = UInt32x32To64(d1.Low, d2.Mid) + (num4 >> 32);
1163 value.U1 = (uint)num4;
1164 num4 >>= 32;
1165 if (d2.High != 0)
1166 {
1167 num4 += UInt32x32To64(d1.Low, d2.High);
1168 if (num4 > uint.MaxValue)
1169 {
1170 value.Mid64 = num4;
1171 num6 = 3u;
1172 goto IL_0368;
1173 }
1174 }
1175 value.U2 = (uint)num4;
1176 num6 = 2u;
1177 }
1178 else if ((d2.High | d2.Mid) == 0)
1179 {
1180 ulong num4 = UInt32x32To64(d2.Low, d1.Low);
1181 value.U0 = (uint)num4;
1182 num4 = UInt32x32To64(d2.Low, d1.Mid) + (num4 >> 32);
1183 value.U1 = (uint)num4;
1184 num4 >>= 32;
1185 if (d1.High != 0)
1186 {
1187 num4 += UInt32x32To64(d2.Low, d1.High);
1188 if (num4 > uint.MaxValue)
1189 {
1190 value.Mid64 = num4;
1191 num6 = 3u;
1192 goto IL_0368;
1193 }
1194 }
1195 value.U2 = (uint)num4;
1196 num6 = 2u;
1197 }
1198 else
1199 {
1200 ulong num4 = UInt32x32To64(d1.Low, d2.Low);
1201 value.U0 = (uint)num4;
1202 ulong num7 = UInt32x32To64(d1.Low, d2.Mid) + (num4 >> 32);
1203 num4 = UInt32x32To64(d1.Mid, d2.Low);
1204 num4 += num7;
1205 value.U1 = (uint)num4;
1206 num7 = ((num4 >= num7) ? (num4 >> 32) : ((num4 >> 32) | 0x100000000uL));
1207 num4 = UInt32x32To64(d1.Mid, d2.Mid) + num7;
1208 if ((d1.High | d2.High) != 0)
1209 {
1210 num7 = UInt32x32To64(d1.Low, d2.High);
1211 num4 += num7;
1212 uint num8 = 0u;
1213 if (num4 < num7)
1214 {
1215 num8 = 1u;
1216 }
1217 num7 = UInt32x32To64(d1.High, d2.Low);
1218 num4 += num7;
1219 value.U2 = (uint)num4;
1220 if (num4 < num7)
1221 {
1222 num8++;
1223 }
1224 num7 = ((ulong)num8 << 32) | (num4 >> 32);
1225 num4 = UInt32x32To64(d1.Mid, d2.High);
1226 num4 += num7;
1227 num8 = 0u;
1228 if (num4 < num7)
1229 {
1230 num8 = 1u;
1231 }
1232 num7 = UInt32x32To64(d1.High, d2.Mid);
1233 num4 += num7;
1234 value.U3 = (uint)num4;
1235 if (num4 < num7)
1236 {
1237 num8++;
1238 }
1239 num4 = ((ulong)num8 << 32) | (num4 >> 32);
1240 value.High64 = UInt32x32To64(d1.High, d2.High) + num4;
1241 num6 = 5u;
1242 }
1243 else
1244 {
1245 value.Mid64 = num4;
1246 num6 = 3u;
1247 }
1248 }
1249 uint* ptr = (uint*)(&value);
1250 while (ptr[(int)num6] == 0)
1251 {
1252 if (num6 != 0)
1253 {
1254 num6--;
1255 continue;
1256 }
1257 goto IL_03b4;
1258 }
1259 goto IL_0368;
1260 IL_0368:
1261 if (num6 > 2 || num > 28)
1262 {
1263 num = ScaleResult(&value, num6, num);
1264 }
1265 d1.Low64 = value.Low64;
1266 d1.High = value.U2;
1267 d1.uflags = ((d2.uflags ^ d1.uflags) & 0x80000000u) | (uint)(num << 16);
1268 return;
1269 IL_03b4:
1270 d1 = default(DecCalc);
1271 }
1272
1273 internal static void VarDecFromR4(float input, out DecCalc result)
1274 {
1275 result = default(DecCalc);
1276 int num = (int)(GetExponent(input) - 126);
1277 if (num < -94)
1278 {
1279 return;
1280 }
1281 if (num > 96)
1282 {
1284 }
1285 uint num2 = 0u;
1286 if (input < 0f)
1287 {
1288 input = 0f - input;
1289 num2 = 2147483648u;
1290 }
1291 double num3 = input;
1292 int num4 = 6 - (num * 19728 >> 16);
1293 if (num4 >= 0)
1294 {
1295 if (num4 > 28)
1296 {
1297 num4 = 28;
1298 }
1300 }
1301 else if (num4 != -1 || num3 >= 10000000.0)
1302 {
1304 }
1305 else
1306 {
1307 num4 = 0;
1308 }
1309 if (num3 < 1000000.0 && num4 < 28)
1310 {
1311 num3 *= 10.0;
1312 num4++;
1313 }
1314 uint num5;
1315 if (Sse41.IsSupported)
1316 {
1317 num5 = (uint)(int)Math.Round(num3);
1318 }
1319 else
1320 {
1321 num5 = (uint)(int)num3;
1322 num3 -= (double)(int)num5;
1323 if (num3 > 0.5 || (num3 == 0.5 && (num5 & (true ? 1u : 0u)) != 0))
1324 {
1325 num5++;
1326 }
1327 }
1328 if (num5 == 0)
1329 {
1330 return;
1331 }
1332 if (num4 < 0)
1333 {
1334 num4 = -num4;
1335 if (num4 < 10)
1336 {
1338 }
1339 else if (num4 > 18)
1340 {
1341 ulong a = UInt32x32To64(num5, s_powers10[num4 - 18]);
1342 UInt64x64To128(a, 1000000000000000000uL, ref result);
1343 }
1344 else
1345 {
1346 ulong num6 = UInt32x32To64(num5, s_powers10[num4 - 9]);
1347 ulong num7 = UInt32x32To64(1000000000u, (uint)(num6 >> 32));
1348 num6 = UInt32x32To64(1000000000u, (uint)num6);
1349 result.Low = (uint)num6;
1350 num7 += num6 >> 32;
1351 result.Mid = (uint)num7;
1352 num7 >>= 32;
1353 result.High = (uint)num7;
1354 }
1355 }
1356 else
1357 {
1358 int num8 = num4;
1359 if (num8 > 6)
1360 {
1361 num8 = 6;
1362 }
1363 if ((num5 & 0xF) == 0 && num8 >= 4)
1364 {
1365 uint num9 = num5 / 10000;
1366 if (num5 == num9 * 10000)
1367 {
1368 num5 = num9;
1369 num4 -= 4;
1370 num8 -= 4;
1371 }
1372 }
1373 if ((num5 & 3) == 0 && num8 >= 2)
1374 {
1375 uint num10 = num5 / 100;
1376 if (num5 == num10 * 100)
1377 {
1378 num5 = num10;
1379 num4 -= 2;
1380 num8 -= 2;
1381 }
1382 }
1383 if ((num5 & 1) == 0 && num8 >= 1)
1384 {
1385 uint num11 = num5 / 10;
1386 if (num5 == num11 * 10)
1387 {
1388 num5 = num11;
1389 num4--;
1390 }
1391 }
1392 num2 |= (uint)(num4 << 16);
1393 result.Low = num5;
1394 }
1396 }
1397
1398 internal static void VarDecFromR8(double input, out DecCalc result)
1399 {
1400 result = default(DecCalc);
1401 int num = (int)(GetExponent(input) - 1022);
1402 if (num < -94)
1403 {
1404 return;
1405 }
1406 if (num > 96)
1407 {
1409 }
1410 uint num2 = 0u;
1411 if (input < 0.0)
1412 {
1413 input = 0.0 - input;
1414 num2 = 2147483648u;
1415 }
1416 double num3 = input;
1417 int num4 = 14 - (num * 19728 >> 16);
1418 if (num4 >= 0)
1419 {
1420 if (num4 > 28)
1421 {
1422 num4 = 28;
1423 }
1425 }
1426 else if (num4 != -1 || num3 >= 1000000000000000.0)
1427 {
1429 }
1430 else
1431 {
1432 num4 = 0;
1433 }
1434 if (num3 < 100000000000000.0 && num4 < 28)
1435 {
1436 num3 *= 10.0;
1437 num4++;
1438 }
1439 ulong num5;
1440 if (Sse41.IsSupported)
1441 {
1442 num5 = (ulong)(long)Math.Round(num3);
1443 }
1444 else
1445 {
1446 num5 = (ulong)(long)num3;
1447 num3 -= (double)(long)num5;
1448 if (num3 > 0.5 || (num3 == 0.5 && (num5 & 1) != 0L))
1449 {
1450 num5++;
1451 }
1452 }
1453 if (num5 == 0L)
1454 {
1455 return;
1456 }
1457 if (num4 < 0)
1458 {
1459 num4 = -num4;
1460 if (num4 < 10)
1461 {
1462 uint b = s_powers10[num4];
1463 ulong num6 = UInt32x32To64((uint)num5, b);
1464 ulong num7 = UInt32x32To64((uint)(num5 >> 32), b);
1465 result.Low = (uint)num6;
1466 num7 += num6 >> 32;
1467 result.Mid = (uint)num7;
1468 num7 >>= 32;
1469 result.High = (uint)num7;
1470 }
1471 else
1472 {
1474 }
1475 }
1476 else
1477 {
1478 int num8 = num4;
1479 if (num8 > 14)
1480 {
1481 num8 = 14;
1482 }
1483 if ((byte)num5 == 0 && num8 >= 8)
1484 {
1485 ulong num9 = num5 / 100000000;
1486 if ((uint)num5 == (uint)(num9 * 100000000))
1487 {
1488 num5 = num9;
1489 num4 -= 8;
1490 num8 -= 8;
1491 }
1492 }
1493 if (((int)num5 & 0xF) == 0 && num8 >= 4)
1494 {
1495 ulong num10 = num5 / 10000;
1496 if ((uint)num5 == (uint)(num10 * 10000))
1497 {
1498 num5 = num10;
1499 num4 -= 4;
1500 num8 -= 4;
1501 }
1502 }
1503 if (((int)num5 & 3) == 0 && num8 >= 2)
1504 {
1505 ulong num11 = num5 / 100;
1506 if ((uint)num5 == (uint)(num11 * 100))
1507 {
1508 num5 = num11;
1509 num4 -= 2;
1510 num8 -= 2;
1511 }
1512 }
1513 if (((int)num5 & 1) == 0 && num8 >= 1)
1514 {
1515 ulong num12 = num5 / 10;
1516 if ((uint)num5 == (uint)(num12 * 10))
1517 {
1518 num5 = num12;
1519 num4--;
1520 }
1521 }
1522 num2 |= (uint)(num4 << 16);
1524 }
1526 }
1527
1528 internal static float VarR4FromDec(in decimal value)
1529 {
1530 return (float)VarR8FromDec(in value);
1531 }
1532
1533 internal static double VarR8FromDec(in decimal value)
1534 {
1535 double num = ((double)value.Low64 + (double)value.High * 1.8446744073709552E+19) / s_doublePowers10[value.Scale];
1536 if (value.IsNegative)
1537 {
1538 num = 0.0 - num;
1539 }
1540 return num;
1541 }
1542
1543 internal static int GetHashCode(in decimal d)
1544 {
1545 if ((d.Low64 | d.High) == 0L)
1546 {
1547 return 0;
1548 }
1549 uint flags = (uint)d._flags;
1550 if ((flags & 0xFF0000) == 0 || (d.Low & (true ? 1u : 0u)) != 0)
1551 {
1552 return (int)(flags ^ d.High ^ d.Mid ^ d.Low);
1553 }
1554 int scale = (byte)(flags >> 16);
1555 uint low = d.Low;
1556 ulong high = ((ulong)d.High << 32) | d.Mid;
1557 Unscale(ref low, ref high, ref scale);
1558 flags = (flags & 0xFF00FFFFu) | (uint)(scale << 16);
1559 return (int)flags ^ (int)(high >> 32) ^ (int)high ^ (int)low;
1560 }
1561
1562 internal unsafe static void VarDecDiv(ref DecCalc d1, ref DecCalc d2)
1563 {
1564 Unsafe.SkipInit<Buf12>(out var value);
1565 int scale = (sbyte)(d1.uflags - d2.uflags >> 16);
1566 bool flag = false;
1567 uint low;
1568 uint num;
1569 Buf16 value2;
1570 ulong num7;
1571 Buf12 value3;
1572 uint num6;
1573 if ((d2.High | d2.Mid) == 0)
1574 {
1575 low = d2.Low;
1576 if (low == 0)
1577 {
1578 throw new DivideByZeroException();
1579 }
1580 value.Low64 = d1.Low64;
1581 value.U2 = d1.High;
1582 num = Div96By32(ref value, low);
1583 while (true)
1584 {
1585 int num2;
1586 if (num == 0)
1587 {
1588 if (scale >= 0)
1589 {
1590 break;
1591 }
1592 num2 = Math.Min(9, -scale);
1593 }
1594 else
1595 {
1596 flag = true;
1597 if (scale == 28 || (num2 = SearchScale(ref value, scale)) == 0)
1598 {
1599 goto IL_0090;
1600 }
1601 }
1602 uint num3 = s_powers10[num2];
1603 scale += num2;
1604 if (IncreaseScale(ref value, num3) == 0)
1605 {
1606 ulong num4 = UInt32x32To64(num, num3);
1607 uint num5 = (uint)(num4 / low);
1608 num = (uint)(int)num4 - num5 * low;
1609 if (!Add32To96(ref value, num5))
1610 {
1611 scale = OverflowUnscale(ref value, scale, num != 0);
1612 break;
1613 }
1614 continue;
1615 }
1616 goto IL_04ab;
1617 }
1618 }
1619 else
1620 {
1621 num6 = d2.High;
1622 if (num6 == 0)
1623 {
1624 num6 = d2.Mid;
1625 }
1627 Unsafe.SkipInit<Buf16>(out value2);
1629 value2.High64 = d1.Mid + ((ulong)d1.High << 32) >> 32 - num2;
1630 num7 = d2.Low64 << num2;
1631 if (d2.High == 0)
1632 {
1633 value.U2 = 0u;
1634 value.U1 = Div96By64(ref *(Buf12*)(&value2.U1), num7);
1636 while (true)
1637 {
1638 if (value2.Low64 == 0L)
1639 {
1640 if (scale >= 0)
1641 {
1642 break;
1643 }
1644 num2 = Math.Min(9, -scale);
1645 }
1646 else
1647 {
1648 flag = true;
1649 if (scale == 28 || (num2 = SearchScale(ref value, scale)) == 0)
1650 {
1651 goto IL_01e8;
1652 }
1653 }
1654 uint num3 = s_powers10[num2];
1655 scale += num2;
1656 if (IncreaseScale(ref value, num3) == 0)
1657 {
1659 num6 = Div96By64(ref *(Buf12*)(&value2), num7);
1660 if (!Add32To96(ref value, num6))
1661 {
1662 scale = OverflowUnscale(ref value, scale, value2.Low64 != 0);
1663 break;
1664 }
1665 continue;
1666 }
1667 goto IL_04ab;
1668 }
1669 }
1670 else
1671 {
1672 Unsafe.SkipInit<Buf12>(out value3);
1674 value3.U2 = (uint)(d2.Mid + ((ulong)d2.High << 32) >> 32 - num2);
1676 value.U2 = 0u;
1677 while (true)
1678 {
1679 if ((value2.Low64 | value2.U2) == 0L)
1680 {
1681 if (scale >= 0)
1682 {
1683 break;
1684 }
1685 num2 = Math.Min(9, -scale);
1686 }
1687 else
1688 {
1689 flag = true;
1690 if (scale == 28 || (num2 = SearchScale(ref value, scale)) == 0)
1691 {
1692 goto IL_0302;
1693 }
1694 }
1695 uint num3 = s_powers10[num2];
1696 scale += num2;
1697 if (IncreaseScale(ref value, num3) == 0)
1698 {
1701 if (!Add32To96(ref value, num6))
1702 {
1703 scale = OverflowUnscale(ref value, scale, (value2.Low64 | value2.High64) != 0);
1704 break;
1705 }
1706 continue;
1707 }
1708 goto IL_04ab;
1709 }
1710 }
1711 }
1712 goto IL_03f3;
1713 IL_0302:
1714 if ((int)value2.U2 >= 0)
1715 {
1716 num6 = value2.U1 >> 31;
1717 value2.Low64 <<= 1;
1718 value2.U2 = (value2.U2 << 1) + num6;
1719 if (value2.U2 <= value3.U2 && (value2.U2 != value3.U2 || (value2.Low64 <= value3.Low64 && (value2.Low64 != value3.Low64 || (value.U0 & 1) == 0))))
1720 {
1721 goto IL_03f3;
1722 }
1723 }
1724 goto IL_046a;
1725 IL_03f3:
1726 if (flag)
1727 {
1728 uint low2 = value.U0;
1729 ulong high = value.High64;
1730 Unscale(ref low2, ref high, ref scale);
1731 d1.Low = low2;
1732 d1.Mid = (uint)high;
1733 d1.High = (uint)(high >> 32);
1734 }
1735 else
1736 {
1737 d1.Low64 = value.Low64;
1738 d1.High = value.U2;
1739 }
1740 d1.uflags = ((d1.uflags ^ d2.uflags) & 0x80000000u) | (uint)(scale << 16);
1741 return;
1742 IL_046a:
1743 if (++value.Low64 == 0L && ++value.U2 == 0)
1744 {
1745 scale = OverflowUnscale(ref value, scale, sticky: true);
1746 }
1747 goto IL_03f3;
1748 IL_04ab:
1750 return;
1751 IL_01e8:
1752 ulong low3 = value2.Low64;
1753 if ((long)low3 >= 0L && (low3 <<= 1) <= num7 && (low3 != num7 || (value.U0 & 1) == 0))
1754 {
1755 goto IL_03f3;
1756 }
1757 goto IL_046a;
1758 IL_0090:
1759 num6 = num << 1;
1760 if (num6 >= num && (num6 < low || (num6 <= low && (value.U0 & 1) == 0)))
1761 {
1762 goto IL_03f3;
1763 }
1764 goto IL_046a;
1765 }
1766
1767 internal static void VarDecMod(ref DecCalc d1, ref DecCalc d2)
1768 {
1769 if ((d2.ulo | d2.umid | d2.uhi) == 0)
1770 {
1771 throw new DivideByZeroException();
1772 }
1773 if ((d1.ulo | d1.umid | d1.uhi) == 0)
1774 {
1775 return;
1776 }
1777 d2.uflags = (d2.uflags & 0x7FFFFFFFu) | (d1.uflags & 0x80000000u);
1778 int num = VarDecCmpSub(in Unsafe.As<DecCalc, decimal>(ref d1), in Unsafe.As<DecCalc, decimal>(ref d2));
1779 if (num == 0)
1780 {
1781 d1.ulo = 0u;
1782 d1.umid = 0u;
1783 d1.uhi = 0u;
1784 if (d2.uflags > d1.uflags)
1785 {
1786 d1.uflags = d2.uflags;
1787 }
1788 }
1789 else
1790 {
1791 if ((int)((uint)num ^ (d1.uflags & 0x80000000u)) < 0)
1792 {
1793 return;
1794 }
1795 int num2 = (sbyte)(d1.uflags - d2.uflags >> 16);
1796 if (num2 > 0)
1797 {
1798 do
1799 {
1800 uint num3 = ((num2 >= 9) ? 1000000000u : s_powers10[num2]);
1801 ulong num4 = UInt32x32To64(d2.Low, num3);
1802 d2.Low = (uint)num4;
1803 num4 >>= 32;
1804 num4 += (d2.Mid + ((ulong)d2.High << 32)) * num3;
1805 d2.Mid = (uint)num4;
1806 d2.High = (uint)(num4 >> 32);
1807 }
1808 while ((num2 -= 9) > 0);
1809 num2 = 0;
1810 }
1811 do
1812 {
1813 if (num2 < 0)
1814 {
1815 d1.uflags = d2.uflags;
1816 Unsafe.SkipInit<Buf12>(out var value);
1818 value.U2 = d1.High;
1819 uint num6;
1820 do
1821 {
1822 int num5 = SearchScale(ref value, 28 + num2);
1823 if (num5 == 0)
1824 {
1825 break;
1826 }
1827 num6 = ((num5 >= 9) ? 1000000000u : s_powers10[num5]);
1828 num2 += num5;
1829 ulong num7 = UInt32x32To64(value.U0, num6);
1830 value.U0 = (uint)num7;
1831 num7 >>= 32;
1833 }
1834 while (num6 == 1000000000 && num2 < 0);
1835 d1.Low64 = value.Low64;
1836 d1.High = value.U2;
1837 }
1838 if (d1.High == 0)
1839 {
1840 d1.Low64 %= d2.Low64;
1841 break;
1842 }
1843 if ((d2.High | d2.Mid) == 0)
1844 {
1845 uint low = d2.Low;
1846 ulong num8 = ((ulong)d1.High << 32) | d1.Mid;
1847 num8 = (num8 % low << 32) | d1.Low;
1848 d1.Low64 = num8 % low;
1849 d1.High = 0u;
1850 continue;
1851 }
1853 break;
1854 }
1855 while (num2 < 0);
1856 }
1857 }
1858
1859 private unsafe static void VarDecModFull(ref DecCalc d1, ref DecCalc d2, int scale)
1860 {
1861 uint num = d2.High;
1862 if (num == 0)
1863 {
1864 num = d2.Mid;
1865 }
1867 Unsafe.SkipInit<Buf28>(out var value);
1869 value.Buf24.Mid64 = d1.Mid + ((ulong)d1.High << 32) >> 32 - num2;
1870 uint num3 = 3u;
1871 while (scale < 0)
1872 {
1873 uint b = ((scale <= -9) ? 1000000000u : s_powers10[-scale]);
1874 uint* ptr = (uint*)(&value);
1875 ulong num4 = UInt32x32To64(value.Buf24.U0, b);
1876 value.Buf24.U0 = (uint)num4;
1877 for (int i = 1; i <= num3; i++)
1878 {
1879 num4 >>= 32;
1880 num4 += UInt32x32To64(ptr[i], b);
1881 ptr[i] = (uint)num4;
1882 }
1883 if (num4 > int.MaxValue)
1884 {
1885 ptr[++num3] = (uint)(num4 >> 32);
1886 }
1887 scale += 9;
1888 }
1889 if (d2.High == 0)
1890 {
1891 ulong den = d2.Low64 << num2;
1892 switch (num3)
1893 {
1894 case 6u:
1895 Div96By64(ref *(Buf12*)(&value.Buf24.U4), den);
1896 goto case 5u;
1897 case 5u:
1898 Div96By64(ref *(Buf12*)(&value.Buf24.U3), den);
1899 goto case 4u;
1900 case 4u:
1901 Div96By64(ref *(Buf12*)(&value.Buf24.U2), den);
1902 break;
1903 }
1904 Div96By64(ref *(Buf12*)(&value.Buf24.U1), den);
1905 Div96By64(ref *(Buf12*)(&value), den);
1907 d1.High = 0u;
1908 return;
1909 }
1910 Unsafe.SkipInit<Buf12>(out var value2);
1912 value2.U2 = (uint)(d2.Mid + ((ulong)d2.High << 32) >> 32 - num2);
1913 switch (num3)
1914 {
1915 case 6u:
1916 Div128By96(ref *(Buf16*)(&value.Buf24.U3), ref value2);
1917 goto case 5u;
1918 case 5u:
1919 Div128By96(ref *(Buf16*)(&value.Buf24.U2), ref value2);
1920 goto case 4u;
1921 case 4u:
1922 Div128By96(ref *(Buf16*)(&value.Buf24.U1), ref value2);
1923 break;
1924 }
1926 d1.Low64 = (value.Buf24.Low64 >> num2) + ((ulong)value.Buf24.U2 << 32 - num2 << 32);
1928 }
1929
1930 internal static void InternalRound(ref DecCalc d, uint scale, MidpointRounding mode)
1931 {
1932 d.uflags -= scale << 16;
1933 uint num = 0u;
1934 while (true)
1935 {
1936 uint num6;
1937 uint num5;
1938 if (scale >= 9)
1939 {
1940 scale -= 9;
1941 uint num2 = d.uhi;
1942 if (num2 == 0)
1943 {
1944 ulong low = d.Low64;
1945 ulong num4 = (d.Low64 = low / 1000000000);
1946 num5 = (uint)(low - num4 * 1000000000);
1947 }
1948 else
1949 {
1950 num5 = num2 - (d.uhi = num2 / 1000000000) * 1000000000;
1951 num2 = d.umid;
1952 if ((num2 | num5) != 0)
1953 {
1954 num5 = num2 - (d.umid = (uint)((((ulong)num5 << 32) | num2) / 1000000000)) * 1000000000;
1955 }
1956 num2 = d.ulo;
1957 if ((num2 | num5) != 0)
1958 {
1959 num5 = num2 - (d.ulo = (uint)((((ulong)num5 << 32) | num2) / 1000000000)) * 1000000000;
1960 }
1961 }
1962 num6 = 1000000000u;
1963 if (scale != 0)
1964 {
1965 num |= num5;
1966 continue;
1967 }
1968 }
1969 else
1970 {
1971 num6 = s_powers10[scale];
1972 uint num7 = d.uhi;
1973 if (num7 == 0)
1974 {
1975 ulong low2 = d.Low64;
1976 if (low2 == 0L)
1977 {
1978 if (mode <= MidpointRounding.ToZero)
1979 {
1980 break;
1981 }
1982 num5 = 0u;
1983 }
1984 else
1985 {
1986 ulong num9 = (d.Low64 = low2 / num6);
1987 num5 = (uint)(low2 - num9 * num6);
1988 }
1989 }
1990 else
1991 {
1992 num5 = num7 - (d.uhi = num7 / num6) * num6;
1993 num7 = d.umid;
1994 if ((num7 | num5) != 0)
1995 {
1996 num5 = num7 - (d.umid = (uint)((((ulong)num5 << 32) | num7) / num6)) * num6;
1997 }
1998 num7 = d.ulo;
1999 if ((num7 | num5) != 0)
2000 {
2001 num5 = num7 - (d.ulo = (uint)((((ulong)num5 << 32) | num7) / num6)) * num6;
2002 }
2003 }
2004 }
2005 switch (mode)
2006 {
2007 case MidpointRounding.ToEven:
2008 num5 <<= 1;
2009 if ((num | (d.ulo & (true ? 1u : 0u))) != 0)
2010 {
2011 num5++;
2012 }
2013 if (num6 >= num5)
2014 {
2015 break;
2016 }
2017 goto IL_01e5;
2018 case MidpointRounding.AwayFromZero:
2019 num5 <<= 1;
2020 if (num6 > num5)
2021 {
2022 break;
2023 }
2024 goto IL_01e5;
2025 case MidpointRounding.ToNegativeInfinity:
2026 if ((num5 | num) == 0 || !d.IsNegative)
2027 {
2028 break;
2029 }
2030 goto IL_01e5;
2031 default:
2032 if ((num5 | num) == 0 || d.IsNegative)
2033 {
2034 break;
2035 }
2036 goto IL_01e5;
2037 case MidpointRounding.ToZero:
2038 break;
2039 IL_01e5:
2040 if (++d.Low64 == 0L)
2041 {
2042 d.uhi++;
2043 }
2044 break;
2045 }
2046 break;
2047 }
2048 }
2049
2050 internal static uint DecDivMod1E9(ref DecCalc value)
2051 {
2052 ulong num = ((ulong)value.uhi << 32) + value.umid;
2053 ulong num2 = num / 1000000000;
2054 value.uhi = (uint)(num2 >> 32);
2055 value.umid = (uint)num2;
2056 ulong num3 = (num - (uint)((int)num2 * 1000000000) << 32) + value.ulo;
2057 return (uint)(int)num3 - (value.ulo = (uint)(num3 / 1000000000)) * 1000000000;
2058 }
2059 }
2060
2061 public const decimal Zero = 0m;
2062
2063 public const decimal One = 1m;
2064
2065 public const decimal MinusOne = -1m;
2066
2067 public const decimal MaxValue = 79228162514264337593543950335m;
2068
2069 public const decimal MinValue = -79228162514264337593543950335m;
2070
2071 private readonly int _flags;
2072
2073 private readonly uint _hi32;
2074
2075 private readonly ulong _lo64;
2076
2077 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
2079
2080 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
2081 static decimal IMinMaxValue<decimal>.MinValue => decimal.MinValue;
2082
2083 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
2084 static decimal IMinMaxValue<decimal>.MaxValue => decimal.MaxValue;
2085
2086 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
2088
2089 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
2090 static decimal INumber<decimal>.One => 1.0m;
2091
2092 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
2093 static decimal INumber<decimal>.Zero => 0.0m;
2094
2095 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
2097
2098 internal uint High => _hi32;
2099
2100 internal uint Low => (uint)_lo64;
2101
2102 internal uint Mid => (uint)(_lo64 >> 32);
2103
2104 internal bool IsNegative => _flags < 0;
2105
2106 internal int Scale => (byte)(_flags >> 16);
2107
2108 private ulong Low64 => _lo64;
2109
2111 {
2112 this = FromOACurrency(value.m_value);
2113 }
2114
2115 public Decimal(int value)
2116 {
2117 if (value >= 0)
2118 {
2119 _flags = 0;
2120 }
2121 else
2122 {
2123 _flags = int.MinValue;
2124 value = -value;
2125 }
2126 _lo64 = (uint)value;
2127 _hi32 = 0u;
2128 }
2129
2130 [CLSCompliant(false)]
2131 public Decimal(uint value)
2132 {
2133 _flags = 0;
2134 _lo64 = value;
2135 _hi32 = 0u;
2136 }
2137
2138 public Decimal(long value)
2139 {
2140 if (value >= 0)
2141 {
2142 _flags = 0;
2143 }
2144 else
2145 {
2146 _flags = int.MinValue;
2147 value = -value;
2148 }
2149 _lo64 = (ulong)value;
2150 _hi32 = 0u;
2151 }
2152
2153 [CLSCompliant(false)]
2154 public Decimal(ulong value)
2155 {
2156 _flags = 0;
2157 _lo64 = value;
2158 _hi32 = 0u;
2159 }
2160
2161 public Decimal(float value)
2162 {
2164 }
2165
2166 public Decimal(double value)
2167 {
2169 }
2170
2172 {
2173 if (info == null)
2174 {
2175 throw new ArgumentNullException("info");
2176 }
2177 _flags = info.GetInt32("flags");
2178 _hi32 = (uint)info.GetInt32("hi");
2179 _lo64 = (ulong)((uint)info.GetInt32("lo") + ((long)info.GetInt32("mid") << 32));
2180 }
2181
2183 {
2184 if (info == null)
2185 {
2186 throw new ArgumentNullException("info");
2187 }
2188 info.AddValue("flags", _flags);
2189 info.AddValue("hi", (int)High);
2190 info.AddValue("lo", (int)Low);
2191 info.AddValue("mid", (int)Mid);
2192 }
2193
2194 public static decimal FromOACurrency(long cy)
2195 {
2196 bool isNegative = false;
2197 ulong num;
2198 if (cy < 0)
2199 {
2200 isNegative = true;
2201 num = (ulong)(-cy);
2202 }
2203 else
2204 {
2205 num = (ulong)cy;
2206 }
2207 int num2 = 4;
2208 if (num != 0L)
2209 {
2210 while (num2 != 0 && num % 10 == 0L)
2211 {
2212 num2--;
2213 num /= 10;
2214 }
2215 }
2216 return new decimal((int)num, (int)(num >> 32), 0, isNegative, (byte)num2);
2217 }
2218
2219 public static long ToOACurrency(decimal value)
2220 {
2222 }
2223
2224 private static bool IsValid(int flags)
2225 {
2226 if ((flags & 0x7F00FFFF) == 0)
2227 {
2228 return (uint)(flags & 0xFF0000) <= 1835008u;
2229 }
2230 return false;
2231 }
2232
2233 public Decimal(int[] bits)
2234 : this((ReadOnlySpan<int>)(bits ?? throw new ArgumentNullException("bits")))
2235 {
2236 }
2237
2239 {
2240 if (bits.Length == 4)
2241 {
2242 int flags = bits[3];
2243 if (IsValid(flags))
2244 {
2245 _lo64 = (uint)bits[0] + ((ulong)(uint)bits[1] << 32);
2246 _hi32 = (uint)bits[2];
2247 _flags = flags;
2248 return;
2249 }
2250 }
2252 }
2253
2254 public Decimal(int lo, int mid, int hi, bool isNegative, byte scale)
2255 {
2256 if (scale > 28)
2257 {
2259 }
2260 _lo64 = (uint)lo + ((ulong)(uint)mid << 32);
2261 _hi32 = (uint)hi;
2262 _flags = scale << 16;
2263 if (isNegative)
2264 {
2265 _flags |= int.MinValue;
2266 }
2267 }
2268
2270 {
2271 if (!IsValid(_flags))
2272 {
2274 }
2275 }
2276
2277 private Decimal(int lo, int mid, int hi, int flags)
2278 {
2279 if (IsValid(flags))
2280 {
2281 _lo64 = (uint)lo + ((ulong)(uint)mid << 32);
2282 _hi32 = (uint)hi;
2283 _flags = flags;
2284 return;
2285 }
2287 }
2288
2289 private Decimal(in decimal d, int flags)
2290 {
2291 this = d;
2292 _flags = flags;
2293 }
2294
2295 internal static decimal Abs(in decimal d)
2296 {
2297 return new decimal(in d, d._flags & 0x7FFFFFFF);
2298 }
2299
2300 public static decimal Add(decimal d1, decimal d2)
2301 {
2303 return d1;
2304 }
2305
2306 public static decimal Ceiling(decimal d)
2307 {
2308 int flags = d._flags;
2309 if (((uint)flags & 0xFF0000u) != 0)
2310 {
2311 DecCalc.InternalRound(ref AsMutable(ref d), (byte)(flags >> 16), MidpointRounding.ToPositiveInfinity);
2312 }
2313 return d;
2314 }
2315
2316 public static int Compare(decimal d1, decimal d2)
2317 {
2318 return DecCalc.VarDecCmp(in d1, in d2);
2319 }
2320
2321 public int CompareTo(object? value)
2322 {
2323 if (value == null)
2324 {
2325 return 1;
2326 }
2327 if (!(value is decimal d))
2328 {
2330 }
2331 return DecCalc.VarDecCmp(in this, in d);
2332 }
2333
2334 public int CompareTo(decimal value)
2335 {
2336 return DecCalc.VarDecCmp(in this, in value);
2337 }
2338
2339 public static decimal Divide(decimal d1, decimal d2)
2340 {
2342 return d1;
2343 }
2344
2345 public override bool Equals([NotNullWhen(true)] object? value)
2346 {
2347 if (value is decimal d)
2348 {
2349 return DecCalc.VarDecCmp(in this, in d) == 0;
2350 }
2351 return false;
2352 }
2353
2354 public bool Equals(decimal value)
2355 {
2356 return DecCalc.VarDecCmp(in this, in value) == 0;
2357 }
2358
2359 public override int GetHashCode()
2360 {
2361 return DecCalc.GetHashCode(in this);
2362 }
2363
2364 public static bool Equals(decimal d1, decimal d2)
2365 {
2366 return DecCalc.VarDecCmp(in d1, in d2) == 0;
2367 }
2368
2369 public static decimal Floor(decimal d)
2370 {
2371 int flags = d._flags;
2372 if (((uint)flags & 0xFF0000u) != 0)
2373 {
2374 DecCalc.InternalRound(ref AsMutable(ref d), (byte)(flags >> 16), MidpointRounding.ToNegativeInfinity);
2375 }
2376 return d;
2377 }
2378
2379 public override string ToString()
2380 {
2382 }
2383
2384 public string ToString(string? format)
2385 {
2387 }
2388
2390 {
2392 }
2393
2394 public string ToString(string? format, IFormatProvider? provider)
2395 {
2397 }
2398
2403
2404 public static decimal Parse(string s)
2405 {
2406 if (s == null)
2407 {
2409 }
2411 }
2412
2413 public static decimal Parse(string s, NumberStyles style)
2414 {
2416 if (s == null)
2417 {
2419 }
2421 }
2422
2423 public static decimal Parse(string s, IFormatProvider? provider)
2424 {
2425 if (s == null)
2426 {
2428 }
2430 }
2431
2432 public static decimal Parse(string s, NumberStyles style, IFormatProvider? provider)
2433 {
2435 if (s == null)
2436 {
2438 }
2440 }
2441
2447
2448 public static bool TryParse([NotNullWhen(true)] string? s, out decimal result)
2449 {
2450 if (s == null)
2451 {
2452 result = default(decimal);
2453 return false;
2454 }
2456 }
2457
2458 public static bool TryParse(ReadOnlySpan<char> s, out decimal result)
2459 {
2461 }
2462
2463 public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out decimal result)
2464 {
2466 if (s == null)
2467 {
2468 result = default(decimal);
2469 return false;
2470 }
2472 }
2473
2479
2480 public static int[] GetBits(decimal d)
2481 {
2482 return new int[4]
2483 {
2484 (int)d.Low,
2485 (int)d.Mid,
2486 (int)d.High,
2487 d._flags
2488 };
2489 }
2490
2491 public static int GetBits(decimal d, Span<int> destination)
2492 {
2493 if ((uint)destination.Length <= 3u)
2494 {
2496 }
2497 destination[0] = (int)d.Low;
2498 destination[1] = (int)d.Mid;
2499 destination[2] = (int)d.High;
2500 destination[3] = d._flags;
2501 return 4;
2502 }
2503
2504 public static bool TryGetBits(decimal d, Span<int> destination, out int valuesWritten)
2505 {
2506 if ((uint)destination.Length <= 3u)
2507 {
2508 valuesWritten = 0;
2509 return false;
2510 }
2511 destination[0] = (int)d.Low;
2512 destination[1] = (int)d.Mid;
2513 destination[2] = (int)d.High;
2514 destination[3] = d._flags;
2515 valuesWritten = 4;
2516 return true;
2517 }
2518
2519 internal static void GetBytes(in decimal d, Span<byte> buffer)
2520 {
2522 BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(4), (int)d.Mid);
2523 BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(8), (int)d.High);
2525 }
2526
2527 internal static decimal ToDecimal(ReadOnlySpan<byte> span)
2528 {
2532 int flags = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(12));
2533 return new decimal(lo, mid, hi, flags);
2534 }
2535
2536 internal static ref readonly decimal Max(in decimal d1, in decimal d2)
2537 {
2538 if (DecCalc.VarDecCmp(in d1, in d2) < 0)
2539 {
2540 return ref d2;
2541 }
2542 return ref d1;
2543 }
2544
2545 internal static ref readonly decimal Min(in decimal d1, in decimal d2)
2546 {
2547 if (DecCalc.VarDecCmp(in d1, in d2) >= 0)
2548 {
2549 return ref d2;
2550 }
2551 return ref d1;
2552 }
2553
2554 public static decimal Remainder(decimal d1, decimal d2)
2555 {
2557 return d1;
2558 }
2559
2560 public static decimal Multiply(decimal d1, decimal d2)
2561 {
2563 return d1;
2564 }
2565
2566 public static decimal Negate(decimal d)
2567 {
2568 return new decimal(in d, d._flags ^ int.MinValue);
2569 }
2570
2571 public static decimal Round(decimal d)
2572 {
2573 return Round(ref d, 0, MidpointRounding.ToEven);
2574 }
2575
2576 public static decimal Round(decimal d, int decimals)
2577 {
2578 return Round(ref d, decimals, MidpointRounding.ToEven);
2579 }
2580
2581 public static decimal Round(decimal d, MidpointRounding mode)
2582 {
2583 return Round(ref d, 0, mode);
2584 }
2585
2586 public static decimal Round(decimal d, int decimals, MidpointRounding mode)
2587 {
2588 return Round(ref d, decimals, mode);
2589 }
2590
2591 private static decimal Round(ref decimal d, int decimals, MidpointRounding mode)
2592 {
2593 if ((uint)decimals > 28u)
2594 {
2596 }
2597 if ((uint)mode > 4u)
2598 {
2599 throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, "MidpointRounding"), "mode");
2600 }
2601 int num = d.Scale - decimals;
2602 if (num > 0)
2603 {
2604 DecCalc.InternalRound(ref AsMutable(ref d), (uint)num, mode);
2605 }
2606 return d;
2607 }
2608
2609 internal static int Sign(in decimal d)
2610 {
2611 if ((d.Low64 | d.High) != 0L)
2612 {
2613 return (d._flags >> 31) | 1;
2614 }
2615 return 0;
2616 }
2617
2618 public static decimal Subtract(decimal d1, decimal d2)
2619 {
2621 return d1;
2622 }
2623
2624 public static byte ToByte(decimal value)
2625 {
2626 uint num;
2627 try
2628 {
2629 num = ToUInt32(value);
2630 }
2631 catch (OverflowException)
2632 {
2634 throw;
2635 }
2636 if (num != (byte)num)
2637 {
2639 }
2640 return (byte)num;
2641 }
2642
2643 [CLSCompliant(false)]
2644 public static sbyte ToSByte(decimal value)
2645 {
2646 int num;
2647 try
2648 {
2649 num = ToInt32(value);
2650 }
2651 catch (OverflowException)
2652 {
2654 throw;
2655 }
2656 if (num != (sbyte)num)
2657 {
2659 }
2660 return (sbyte)num;
2661 }
2662
2663 public static short ToInt16(decimal value)
2664 {
2665 int num;
2666 try
2667 {
2668 num = ToInt32(value);
2669 }
2670 catch (OverflowException)
2671 {
2673 throw;
2674 }
2675 if (num != (short)num)
2676 {
2678 }
2679 return (short)num;
2680 }
2681
2682 public static double ToDouble(decimal d)
2683 {
2684 return DecCalc.VarR8FromDec(in d);
2685 }
2686
2687 public static int ToInt32(decimal d)
2688 {
2689 Truncate(ref d);
2690 if ((d.High | d.Mid) == 0)
2691 {
2692 int low = (int)d.Low;
2693 if (!d.IsNegative)
2694 {
2695 if (low >= 0)
2696 {
2697 return low;
2698 }
2699 }
2700 else
2701 {
2702 low = -low;
2703 if (low <= 0)
2704 {
2705 return low;
2706 }
2707 }
2708 }
2710 }
2711
2712 public static long ToInt64(decimal d)
2713 {
2714 Truncate(ref d);
2715 if (d.High == 0)
2716 {
2717 long low = (long)d.Low64;
2718 if (!d.IsNegative)
2719 {
2720 if (low >= 0)
2721 {
2722 return low;
2723 }
2724 }
2725 else
2726 {
2727 low = -low;
2728 if (low <= 0)
2729 {
2730 return low;
2731 }
2732 }
2733 }
2735 }
2736
2737 [CLSCompliant(false)]
2738 public static ushort ToUInt16(decimal value)
2739 {
2740 uint num;
2741 try
2742 {
2743 num = ToUInt32(value);
2744 }
2745 catch (OverflowException)
2746 {
2748 throw;
2749 }
2750 if (num != (ushort)num)
2751 {
2753 }
2754 return (ushort)num;
2755 }
2756
2757 [CLSCompliant(false)]
2758 public static uint ToUInt32(decimal d)
2759 {
2760 Truncate(ref d);
2761 if ((d.High | d.Mid) == 0)
2762 {
2763 uint low = d.Low;
2764 if (!d.IsNegative || low == 0)
2765 {
2766 return low;
2767 }
2768 }
2770 }
2771
2772 [CLSCompliant(false)]
2773 public static ulong ToUInt64(decimal d)
2774 {
2775 Truncate(ref d);
2776 if (d.High == 0)
2777 {
2778 ulong low = d.Low64;
2779 if (!d.IsNegative || low == 0L)
2780 {
2781 return low;
2782 }
2783 }
2785 }
2786
2787 public static float ToSingle(decimal d)
2788 {
2789 return DecCalc.VarR4FromDec(in d);
2790 }
2791
2792 public static decimal Truncate(decimal d)
2793 {
2794 Truncate(ref d);
2795 return d;
2796 }
2797
2798 [MethodImpl(MethodImplOptions.AggressiveInlining)]
2799 private static void Truncate(ref decimal d)
2800 {
2801 int flags = d._flags;
2802 if (((uint)flags & 0xFF0000u) != 0)
2803 {
2804 DecCalc.InternalRound(ref AsMutable(ref d), (byte)(flags >> 16), MidpointRounding.ToZero);
2805 }
2806 }
2807
2808 public static implicit operator decimal(byte value)
2809 {
2810 return new decimal((uint)value);
2811 }
2812
2813 [CLSCompliant(false)]
2814 public static implicit operator decimal(sbyte value)
2815 {
2816 return new decimal(value);
2817 }
2818
2819 public static implicit operator decimal(short value)
2820 {
2821 return new decimal(value);
2822 }
2823
2824 [CLSCompliant(false)]
2825 public static implicit operator decimal(ushort value)
2826 {
2827 return new decimal((uint)value);
2828 }
2829
2830 public static implicit operator decimal(char value)
2831 {
2832 return new decimal((uint)value);
2833 }
2834
2835 public static implicit operator decimal(int value)
2836 {
2837 return new decimal(value);
2838 }
2839
2840 [CLSCompliant(false)]
2841 public static implicit operator decimal(uint value)
2842 {
2843 return new decimal(value);
2844 }
2845
2846 public static implicit operator decimal(long value)
2847 {
2848 return new decimal(value);
2849 }
2850
2851 [CLSCompliant(false)]
2852 public static implicit operator decimal(ulong value)
2853 {
2854 return new decimal(value);
2855 }
2856
2857 public static explicit operator decimal(float value)
2858 {
2859 return new decimal(value);
2860 }
2861
2862 public static explicit operator decimal(double value)
2863 {
2864 return new decimal(value);
2865 }
2866
2867 public static explicit operator byte(decimal value)
2868 {
2869 return ToByte(value);
2870 }
2871
2872 [CLSCompliant(false)]
2873 public static explicit operator sbyte(decimal value)
2874 {
2875 return ToSByte(value);
2876 }
2877
2878 public static explicit operator char(decimal value)
2879 {
2880 try
2881 {
2882 return (char)ToUInt16(value);
2883 }
2885 {
2887 }
2888 }
2889
2890 public static explicit operator short(decimal value)
2891 {
2892 return ToInt16(value);
2893 }
2894
2895 [CLSCompliant(false)]
2896 public static explicit operator ushort(decimal value)
2897 {
2898 return ToUInt16(value);
2899 }
2900
2901 public static explicit operator int(decimal value)
2902 {
2903 return ToInt32(value);
2904 }
2905
2906 [CLSCompliant(false)]
2907 public static explicit operator uint(decimal value)
2908 {
2909 return ToUInt32(value);
2910 }
2911
2912 public static explicit operator long(decimal value)
2913 {
2914 return ToInt64(value);
2915 }
2916
2917 [CLSCompliant(false)]
2918 public static explicit operator ulong(decimal value)
2919 {
2920 return ToUInt64(value);
2921 }
2922
2923 public static explicit operator float(decimal value)
2924 {
2925 return DecCalc.VarR4FromDec(in value);
2926 }
2927
2928 public static explicit operator double(decimal value)
2929 {
2930 return DecCalc.VarR8FromDec(in value);
2931 }
2932
2933 public static decimal operator +(decimal d)
2934 {
2935 return d;
2936 }
2937
2938 public static decimal operator -(decimal d)
2939 {
2940 return new decimal(in d, d._flags ^ int.MinValue);
2941 }
2942
2943 public static decimal operator ++(decimal d)
2944 {
2945 return Add(d, 1m);
2946 }
2947
2948 public static decimal operator --(decimal d)
2949 {
2950 return Subtract(d, 1m);
2951 }
2952
2953 public static decimal operator +(decimal d1, decimal d2)
2954 {
2956 return d1;
2957 }
2958
2959 public static decimal operator -(decimal d1, decimal d2)
2960 {
2962 return d1;
2963 }
2964
2965 public static decimal operator *(decimal d1, decimal d2)
2966 {
2968 return d1;
2969 }
2970
2971 public static decimal operator /(decimal d1, decimal d2)
2972 {
2974 return d1;
2975 }
2976
2977 public static decimal operator %(decimal d1, decimal d2)
2978 {
2980 return d1;
2981 }
2982
2983 public static bool operator ==(decimal d1, decimal d2)
2984 {
2985 return DecCalc.VarDecCmp(in d1, in d2) == 0;
2986 }
2987
2988 public static bool operator !=(decimal d1, decimal d2)
2989 {
2990 return DecCalc.VarDecCmp(in d1, in d2) != 0;
2991 }
2992
2993 public static bool operator <(decimal d1, decimal d2)
2994 {
2995 return DecCalc.VarDecCmp(in d1, in d2) < 0;
2996 }
2997
2998 public static bool operator <=(decimal d1, decimal d2)
2999 {
3000 return DecCalc.VarDecCmp(in d1, in d2) <= 0;
3001 }
3002
3003 public static bool operator >(decimal d1, decimal d2)
3004 {
3005 return DecCalc.VarDecCmp(in d1, in d2) > 0;
3006 }
3007
3008 public static bool operator >=(decimal d1, decimal d2)
3009 {
3010 return DecCalc.VarDecCmp(in d1, in d2) >= 0;
3011 }
3012
3014 {
3015 return TypeCode.Decimal;
3016 }
3017
3019 {
3020 return Convert.ToBoolean(this);
3021 }
3022
3024 {
3025 throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Decimal", "Char"));
3026 }
3027
3029 {
3030 return Convert.ToSByte(this);
3031 }
3032
3034 {
3035 return Convert.ToByte(this);
3036 }
3037
3039 {
3040 return Convert.ToInt16(this);
3041 }
3042
3044 {
3045 return Convert.ToUInt16(this);
3046 }
3047
3049 {
3050 return Convert.ToInt32(this);
3051 }
3052
3054 {
3055 return Convert.ToUInt32(this);
3056 }
3057
3059 {
3060 return Convert.ToInt64(this);
3061 }
3062
3064 {
3065 return Convert.ToUInt64(this);
3066 }
3067
3069 {
3070 return DecCalc.VarR4FromDec(in this);
3071 }
3072
3074 {
3075 return DecCalc.VarR8FromDec(in this);
3076 }
3077
3079 {
3080 return this;
3081 }
3082
3087
3092
3093 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3094 static decimal IAdditionOperators<decimal, decimal, decimal>.operator +(decimal left, decimal right)
3095 {
3096 return left + right;
3097 }
3098
3099 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3100 static bool IComparisonOperators<decimal, decimal>.operator <(decimal left, decimal right)
3101 {
3102 return left < right;
3103 }
3104
3105 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3106 static bool IComparisonOperators<decimal, decimal>.operator <=(decimal left, decimal right)
3107 {
3108 return left <= right;
3109 }
3110
3111 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3112 static bool IComparisonOperators<decimal, decimal>.operator >(decimal left, decimal right)
3113 {
3114 return left > right;
3115 }
3116
3117 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3118 static bool IComparisonOperators<decimal, decimal>.operator >=(decimal left, decimal right)
3119 {
3120 return left >= right;
3121 }
3122
3123 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3124 static decimal IDecrementOperators<decimal>.operator --(decimal value)
3125 {
3126 return --value;
3127 }
3128
3129 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3130 static decimal IDivisionOperators<decimal, decimal, decimal>.operator /(decimal left, decimal right)
3131 {
3132 return left / right;
3133 }
3134
3135 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3136 static bool IEqualityOperators<decimal, decimal>.operator ==(decimal left, decimal right)
3137 {
3138 return left == right;
3139 }
3140
3141 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3142 static bool IEqualityOperators<decimal, decimal>.operator !=(decimal left, decimal right)
3143 {
3144 return left != right;
3145 }
3146
3147 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3148 static decimal IIncrementOperators<decimal>.operator ++(decimal value)
3149 {
3150 return ++value;
3151 }
3152
3153 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3154 static decimal IModulusOperators<decimal, decimal, decimal>.operator %(decimal left, decimal right)
3155 {
3156 return left % right;
3157 }
3158
3159 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3160 static decimal IMultiplyOperators<decimal, decimal, decimal>.operator *(decimal left, decimal right)
3161 {
3162 return left * right;
3163 }
3164
3165 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3166 static decimal INumber<decimal>.Abs(decimal value)
3167 {
3168 return Math.Abs(value);
3169 }
3170
3171 [MethodImpl(MethodImplOptions.AggressiveInlining)]
3172 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3173 static decimal INumber<decimal>.Create<TOther>(TOther value)
3174 {
3175 if (typeof(TOther) == typeof(byte))
3176 {
3177 return (byte)(object)value;
3178 }
3179 if (typeof(TOther) == typeof(char))
3180 {
3181 return (char)(object)value;
3182 }
3183 if (typeof(TOther) == typeof(decimal))
3184 {
3185 return (decimal)(object)value;
3186 }
3187 if (typeof(TOther) == typeof(double))
3188 {
3189 return (decimal)(double)(object)value;
3190 }
3191 if (typeof(TOther) == typeof(short))
3192 {
3193 return (short)(object)value;
3194 }
3195 if (typeof(TOther) == typeof(int))
3196 {
3197 return (int)(object)value;
3198 }
3199 if (typeof(TOther) == typeof(long))
3200 {
3201 return (long)(object)value;
3202 }
3203 if (typeof(TOther) == typeof(IntPtr))
3204 {
3205 return (long)(IntPtr)(object)value;
3206 }
3207 if (typeof(TOther) == typeof(sbyte))
3208 {
3209 return (sbyte)(object)value;
3210 }
3211 if (typeof(TOther) == typeof(float))
3212 {
3213 return (decimal)(float)(object)value;
3214 }
3215 if (typeof(TOther) == typeof(ushort))
3216 {
3217 return (ushort)(object)value;
3218 }
3219 if (typeof(TOther) == typeof(uint))
3220 {
3221 return (uint)(object)value;
3222 }
3223 if (typeof(TOther) == typeof(ulong))
3224 {
3225 return (ulong)(object)value;
3226 }
3227 if (typeof(TOther) == typeof(UIntPtr))
3228 {
3229 return (ulong)(UIntPtr)(object)value;
3230 }
3232 return 0m;
3233 }
3234
3235 [MethodImpl(MethodImplOptions.AggressiveInlining)]
3236 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3237 static decimal INumber<decimal>.CreateSaturating<TOther>(TOther value)
3238 {
3239 if (typeof(TOther) == typeof(byte))
3240 {
3241 return (byte)(object)value;
3242 }
3243 if (typeof(TOther) == typeof(char))
3244 {
3245 return (char)(object)value;
3246 }
3247 if (typeof(TOther) == typeof(decimal))
3248 {
3249 return (decimal)(object)value;
3250 }
3251 if (typeof(TOther) == typeof(double))
3252 {
3253 return (decimal)(double)(object)value;
3254 }
3255 if (typeof(TOther) == typeof(short))
3256 {
3257 return (short)(object)value;
3258 }
3259 if (typeof(TOther) == typeof(int))
3260 {
3261 return (int)(object)value;
3262 }
3263 if (typeof(TOther) == typeof(long))
3264 {
3265 return (long)(object)value;
3266 }
3267 if (typeof(TOther) == typeof(IntPtr))
3268 {
3269 return (long)(IntPtr)(object)value;
3270 }
3271 if (typeof(TOther) == typeof(sbyte))
3272 {
3273 return (sbyte)(object)value;
3274 }
3275 if (typeof(TOther) == typeof(float))
3276 {
3277 return (decimal)(float)(object)value;
3278 }
3279 if (typeof(TOther) == typeof(ushort))
3280 {
3281 return (ushort)(object)value;
3282 }
3283 if (typeof(TOther) == typeof(uint))
3284 {
3285 return (uint)(object)value;
3286 }
3287 if (typeof(TOther) == typeof(ulong))
3288 {
3289 return (ulong)(object)value;
3290 }
3291 if (typeof(TOther) == typeof(UIntPtr))
3292 {
3293 return (ulong)(UIntPtr)(object)value;
3294 }
3296 return 0m;
3297 }
3298
3299 [MethodImpl(MethodImplOptions.AggressiveInlining)]
3300 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3301 static decimal INumber<decimal>.CreateTruncating<TOther>(TOther value)
3302 {
3303 if (typeof(TOther) == typeof(byte))
3304 {
3305 return (byte)(object)value;
3306 }
3307 if (typeof(TOther) == typeof(char))
3308 {
3309 return (char)(object)value;
3310 }
3311 if (typeof(TOther) == typeof(decimal))
3312 {
3313 return (decimal)(object)value;
3314 }
3315 if (typeof(TOther) == typeof(double))
3316 {
3317 return (decimal)(double)(object)value;
3318 }
3319 if (typeof(TOther) == typeof(short))
3320 {
3321 return (short)(object)value;
3322 }
3323 if (typeof(TOther) == typeof(int))
3324 {
3325 return (int)(object)value;
3326 }
3327 if (typeof(TOther) == typeof(long))
3328 {
3329 return (long)(object)value;
3330 }
3331 if (typeof(TOther) == typeof(IntPtr))
3332 {
3333 return (long)(IntPtr)(object)value;
3334 }
3335 if (typeof(TOther) == typeof(sbyte))
3336 {
3337 return (sbyte)(object)value;
3338 }
3339 if (typeof(TOther) == typeof(float))
3340 {
3341 return (decimal)(float)(object)value;
3342 }
3343 if (typeof(TOther) == typeof(ushort))
3344 {
3345 return (ushort)(object)value;
3346 }
3347 if (typeof(TOther) == typeof(uint))
3348 {
3349 return (uint)(object)value;
3350 }
3351 if (typeof(TOther) == typeof(ulong))
3352 {
3353 return (ulong)(object)value;
3354 }
3355 if (typeof(TOther) == typeof(UIntPtr))
3356 {
3357 return (ulong)(UIntPtr)(object)value;
3358 }
3360 return 0m;
3361 }
3362
3363 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3364 static decimal INumber<decimal>.Clamp(decimal value, decimal min, decimal max)
3365 {
3366 return Math.Clamp(value, min, max);
3367 }
3368
3369 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3370 static (decimal Quotient, decimal Remainder) INumber<decimal>.DivRem(decimal left, decimal right)
3371 {
3372 return (Quotient: left / right, Remainder: left % right);
3373 }
3374
3375 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3376 static decimal INumber<decimal>.Max(decimal x, decimal y)
3377 {
3378 return Math.Max(x, y);
3379 }
3380
3381 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3382 static decimal INumber<decimal>.Min(decimal x, decimal y)
3383 {
3384 return Math.Min(x, y);
3385 }
3386
3387 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3389 {
3390 return Parse(s, style, provider);
3391 }
3392
3393 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3395 {
3396 return Parse(s, style, provider);
3397 }
3398
3399 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3400 static decimal INumber<decimal>.Sign(decimal value)
3401 {
3402 return Math.Sign(value);
3403 }
3404
3405 [MethodImpl(MethodImplOptions.AggressiveInlining)]
3406 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3407 static bool INumber<decimal>.TryCreate<TOther>(TOther value, out decimal result)
3408 {
3409 if (typeof(TOther) == typeof(byte))
3410 {
3411 result = (byte)(object)value;
3412 return true;
3413 }
3414 if (typeof(TOther) == typeof(char))
3415 {
3416 result = (char)(object)value;
3417 return true;
3418 }
3419 if (typeof(TOther) == typeof(decimal))
3420 {
3421 result = (decimal)(object)value;
3422 return true;
3423 }
3424 if (typeof(TOther) == typeof(double))
3425 {
3426 result = (decimal)(double)(object)value;
3427 return true;
3428 }
3429 if (typeof(TOther) == typeof(short))
3430 {
3431 result = (short)(object)value;
3432 return true;
3433 }
3434 if (typeof(TOther) == typeof(int))
3435 {
3436 result = (int)(object)value;
3437 return true;
3438 }
3439 if (typeof(TOther) == typeof(long))
3440 {
3441 result = (long)(object)value;
3442 return true;
3443 }
3444 if (typeof(TOther) == typeof(IntPtr))
3445 {
3446 result = (long)(IntPtr)(object)value;
3447 return true;
3448 }
3449 if (typeof(TOther) == typeof(sbyte))
3450 {
3451 result = (sbyte)(object)value;
3452 return true;
3453 }
3454 if (typeof(TOther) == typeof(float))
3455 {
3456 result = (decimal)(float)(object)value;
3457 return true;
3458 }
3459 if (typeof(TOther) == typeof(ushort))
3460 {
3461 result = (ushort)(object)value;
3462 return true;
3463 }
3464 if (typeof(TOther) == typeof(uint))
3465 {
3466 result = (uint)(object)value;
3467 return true;
3468 }
3469 if (typeof(TOther) == typeof(ulong))
3470 {
3471 result = (ulong)(object)value;
3472 return true;
3473 }
3474 if (typeof(TOther) == typeof(UIntPtr))
3475 {
3476 result = (ulong)(UIntPtr)(object)value;
3477 return true;
3478 }
3480 result = default(decimal);
3481 return false;
3482 }
3483
3484 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3485 static bool INumber<decimal>.TryParse([NotNullWhen(true)] string s, NumberStyles style, IFormatProvider provider, out decimal result)
3486 {
3487 return TryParse(s, style, provider, out result);
3488 }
3489
3490 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3492 {
3493 return TryParse(s, style, provider, out result);
3494 }
3495
3496 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3498 {
3499 return Parse(s, provider);
3500 }
3501
3502 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3503 static bool IParseable<decimal>.TryParse([NotNullWhen(true)] string s, IFormatProvider provider, out decimal result)
3504 {
3505 return TryParse(s, NumberStyles.Number, provider, out result);
3506 }
3507
3508 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3513
3514 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3516 {
3517 return TryParse(s, NumberStyles.Number, provider, out result);
3518 }
3519
3520 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3521 static decimal ISubtractionOperators<decimal, decimal, decimal>.operator -(decimal left, decimal right)
3522 {
3523 return left - right;
3524 }
3525
3526 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3527 static decimal IUnaryNegationOperators<decimal, decimal>.operator -(decimal value)
3528 {
3529 return -value;
3530 }
3531
3532 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
3533 static decimal IUnaryPlusOperators<decimal, decimal>.operator +(decimal value)
3534 {
3535 return value;
3536 }
3537
3538 private static ref DecCalc AsMutable(ref decimal d)
3539 {
3540 return ref Unsafe.As<decimal, DecCalc>(ref d);
3541 }
3542
3543 internal static uint DecDivMod1E9(ref decimal value)
3544 {
3546 }
3547}
static void WriteInt32LittleEndian(Span< byte > destination, int value)
static int ReadInt32LittleEndian(ReadOnlySpan< byte > source)
static long ToInt64(object? value)
Definition Convert.cs:1623
static int ToInt32(object? value)
Definition Convert.cs:1320
static short ToInt16(object? value)
Definition Convert.cs:1038
static byte ToByte(object? value)
Definition Convert.cs:900
static uint ToUInt32(object? value)
Definition Convert.cs:1470
static ulong ToUInt64(object? value)
Definition Convert.cs:1738
static ushort ToUInt16(object? value)
Definition Convert.cs:1177
static sbyte ToSByte(object? value)
Definition Convert.cs:745
static bool ToBoolean([NotNullWhen(true)] object? value)
Definition Convert.cs:508
static object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
Definition Convert.cs:269
static NumberFormatInfo GetInstance(IFormatProvider? formatProvider)
static void ValidateParseStyleFloatingPoint(NumberStyles style)
static byte Clamp(byte value, byte min, byte max)
Definition Math.cs:435
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static decimal Round(decimal d)
Definition Math.cs:1096
static double Abs(double value)
static int Sign(decimal value)
Definition Math.cs:1202
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static void ThrowOverflowException(TypeCode type)
Definition Number.cs:5924
static unsafe string FormatDecimal(decimal value, ReadOnlySpan< char > format, NumberFormatInfo info)
Definition Number.cs:1551
static unsafe bool TryFormatDecimal(decimal value, ReadOnlySpan< char > format, NumberFormatInfo info, Span< char > destination, out int charsWritten)
Definition Number.cs:1571
static decimal ParseDecimal(ReadOnlySpan< char > value, NumberStyles styles, NumberFormatInfo info)
Definition Number.cs:5502
static unsafe ParsingStatus TryParseDecimal(ReadOnlySpan< char > value, NumberStyles styles, NumberFormatInfo info, out decimal result)
Definition Number.cs:5640
static int LeadingZeroCount(uint value)
static string InvalidCast_FromTo
Definition SR.cs:1392
static string Overflow_Int32
Definition SR.cs:1772
static string Overflow_UInt64
Definition SR.cs:1790
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Arg_DecBitCtor
Definition SR.cs:114
static string ArgumentOutOfRange_DecimalRound
Definition SR.cs:1004
static string Overflow_Int64
Definition SR.cs:1774
static string Arg_MustBeDecimal
Definition SR.cs:266
static string Overflow_Currency
Definition SR.cs:1764
static string Overflow_Char
Definition SR.cs:1762
static string Overflow_Decimal
Definition SR.cs:1766
static string Argument_InvalidEnumValue
Definition SR.cs:18
static string Overflow_UInt32
Definition SR.cs:1788
static string ArgumentOutOfRange_DecimalScale
Definition SR.cs:1006
Definition SR.cs:7
static void ThrowNotSupportedException(ExceptionResource resource)
static void ThrowArgumentNullException(string name)
static void ThrowArgumentException_DestinationTooShort()
static TResult AdditiveIdentity
short ToInt16(IFormatProvider? provider)
char ToChar(IFormatProvider? provider)
byte ToByte(IFormatProvider? provider)
decimal ToDecimal(IFormatProvider? provider)
object ToType(Type conversionType, IFormatProvider? provider)
uint ToUInt32(IFormatProvider? provider)
DateTime ToDateTime(IFormatProvider? provider)
int ToInt32(IFormatProvider? provider)
long ToInt64(IFormatProvider? provider)
ushort ToUInt16(IFormatProvider? provider)
double ToDouble(IFormatProvider? provider)
float ToSingle(IFormatProvider? provider)
sbyte ToSByte(IFormatProvider? provider)
ulong ToUInt64(IFormatProvider? provider)
bool ToBoolean(IFormatProvider? provider)
static TSelf MinValue
static TSelf MaxValue
static TSelf Max(TSelf x, TSelf y)
static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out TSelf result)
static TSelf Parse(string s, NumberStyles style, IFormatProvider? provider)
static TSelf Sign(TSelf value)
static TSelf Min(TSelf x, TSelf y)
static TSelf One
Definition INumber.cs:10
static TSelf Zero
Definition INumber.cs:12
static TSelf Abs(TSelf value)
static TSelf Clamp(TSelf value, TSelf min, TSelf max)
static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out TSelf result)
static TSelf Parse(string s, IFormatProvider? provider)
static TSelf NegativeOne
static bool TryParse(ReadOnlySpan< char > s, IFormatProvider? provider, out TSelf result)
static TSelf Parse(ReadOnlySpan< char > s, IFormatProvider? provider)
void GetObjectData(SerializationInfo info, StreamingContext context)
TypeCode
Definition TypeCode.cs:4
PowerOvfl(uint hi, uint mid, uint lo)
Definition Decimal.cs:28
static unsafe void VarDecDiv(ref DecCalc d1, ref DecCalc d2)
Definition Decimal.cs:1562
static void UInt64x64To128(ulong a, ulong b, ref DecCalc result)
Definition Decimal.cs:305
static unsafe int ScaleResult(Buf24 *bufRes, uint hiRes, int scale)
Definition Decimal.cs:513
static uint Div96By64(ref Buf12 bufNum, ulong den)
Definition Decimal.cs:390
static void VarDecMod(ref DecCalc d1, ref DecCalc d2)
Definition Decimal.cs:1767
static float VarR4FromDec(in decimal value)
Definition Decimal.cs:1528
static int GetHashCode(in decimal d)
Definition Decimal.cs:1543
static unsafe uint GetExponent(double d)
Definition Decimal.cs:295
static readonly uint[] s_powers10
Definition Decimal.cs:205
static int SearchScale(ref Buf12 bufQuo, int scale)
Definition Decimal.cs:635
static uint Div128By96(ref Buf16 bufNum, ref Buf12 bufDen)
Definition Decimal.cs:444
static void VarDecFromR4(float input, out DecCalc result)
Definition Decimal.cs:1273
static uint IncreaseScale(ref Buf12 bufNum, uint power)
Definition Decimal.cs:491
static unsafe void DecAddSub(ref DecCalc d1, ref DecCalc d2, bool sign)
Definition Decimal.cs:713
static unsafe void VarDecModFull(ref DecCalc d1, ref DecCalc d2, int scale)
Definition Decimal.cs:1859
static unsafe uint DivByConst(uint *result, uint hiRes, out uint quotient, out uint remainder, uint power)
Definition Decimal.cs:604
static void IncreaseScale64(ref Buf12 bufNum, uint power)
Definition Decimal.cs:504
static unsafe void VarDecMul(ref DecCalc d1, ref DecCalc d2)
Definition Decimal.cs:1127
static unsafe uint GetExponent(float f)
Definition Decimal.cs:290
static void InternalRound(ref DecCalc d, uint scale, MidpointRounding mode)
Definition Decimal.cs:1930
static readonly double[] s_doublePowers10
Definition Decimal.cs:213
static int VarDecCmp(in decimal d1, in decimal d2)
Definition Decimal.cs:1045
static void Unscale(ref uint low, ref ulong high64, ref int scale)
Definition Decimal.cs:370
static long VarCyFromDec(ref DecCalc pdecIn)
Definition Decimal.cs:996
static bool Div96ByConst(ref ulong high64, ref uint low, uint pow)
Definition Decimal.cs:356
static readonly PowerOvfl[] PowerOvflValues
Definition Decimal.cs:226
static bool Add32To96(ref Buf12 bufNum, uint value)
Definition Decimal.cs:704
static double VarR8FromDec(in decimal value)
Definition Decimal.cs:1533
static uint DecDivMod1E9(ref DecCalc value)
Definition Decimal.cs:2050
static int OverflowUnscale(ref Buf12 bufQuo, int scale, bool sticky)
Definition Decimal.cs:618
static uint Div96By32(ref Buf12 bufNum, uint den)
Definition Decimal.cs:331
static void VarDecFromR8(double input, out DecCalc result)
Definition Decimal.cs:1398
static ulong UInt32x32To64(uint a, uint b)
Definition Decimal.cs:300
static int VarDecCmpSub(in decimal d1, in decimal d2)
Definition Decimal.cs:1067
static readonly ulong[] s_ulongPowers10
Definition Decimal.cs:207
Decimal(int[] bits)
Definition Decimal.cs:2233
static bool operator>(decimal d1, decimal d2)
Definition Decimal.cs:3003
static ushort ToUInt16(decimal value)
Definition Decimal.cs:2738
static decimal Ceiling(decimal d)
Definition Decimal.cs:2306
static bool IsValid(int flags)
Definition Decimal.cs:2224
string ToString(string? format)
Definition Decimal.cs:2384
static decimal Parse(string s)
Definition Decimal.cs:2404
static decimal Parse(ReadOnlySpan< char > s, NumberStyles style=NumberStyles.Number, IFormatProvider? provider=null)
Definition Decimal.cs:2442
Decimal(float value)
Definition Decimal.cs:2161
static decimal Quotient
Definition Decimal.cs:3370
const decimal MinValue
Definition Decimal.cs:2069
TypeCode GetTypeCode()
Definition Decimal.cs:3013
static decimal Round(decimal d)
Definition Decimal.cs:2571
Decimal(ReadOnlySpan< int > bits)
Definition Decimal.cs:2238
static short ToInt16(decimal value)
Definition Decimal.cs:2663
Decimal(ulong value)
Definition Decimal.cs:2154
int CompareTo(object? value)
Definition Decimal.cs:2321
static decimal decimal Remainder INumber< decimal >. DivRem(decimal left, decimal right)
Definition Decimal.cs:3370
static decimal Abs(in decimal d)
Definition Decimal.cs:2295
static decimal Parse(string s, NumberStyles style)
Definition Decimal.cs:2413
static decimal FromOACurrency(long cy)
Definition Decimal.cs:2194
string ToString(IFormatProvider? provider)
Definition Decimal.cs:2389
static decimal operator%(decimal d1, decimal d2)
Definition Decimal.cs:2977
static decimal Multiply(decimal d1, decimal d2)
Definition Decimal.cs:2560
static bool TryParse(ReadOnlySpan< char > s, out decimal result)
Definition Decimal.cs:2458
static decimal Parse(string s, NumberStyles style, IFormatProvider? provider)
Definition Decimal.cs:2432
int CompareTo(decimal value)
Definition Decimal.cs:2334
Decimal(int lo, int mid, int hi, bool isNegative, byte scale)
Definition Decimal.cs:2254
static decimal ToDecimal(ReadOnlySpan< byte > span)
Definition Decimal.cs:2527
static decimal Round(decimal d, MidpointRounding mode)
Definition Decimal.cs:2581
static int GetBits(decimal d, Span< int > destination)
Definition Decimal.cs:2491
Decimal(long value)
Definition Decimal.cs:2138
Decimal(uint value)
Definition Decimal.cs:2131
static int Compare(decimal d1, decimal d2)
Definition Decimal.cs:2316
static bool operator!=(decimal d1, decimal d2)
Definition Decimal.cs:2988
bool Equals(decimal value)
Definition Decimal.cs:2354
static void GetBytes(in decimal d, Span< byte > buffer)
Definition Decimal.cs:2519
static bool TryParse([NotNullWhen(true)] string? s, out decimal result)
Definition Decimal.cs:2448
static bool Equals(decimal d1, decimal d2)
Definition Decimal.cs:2364
static sbyte ToSByte(decimal value)
Definition Decimal.cs:2644
static int Sign(in decimal d)
Definition Decimal.cs:2609
Decimal(Currency value)
Definition Decimal.cs:2110
readonly uint _hi32
Definition Decimal.cs:2073
Decimal(int value)
Definition Decimal.cs:2115
static decimal Truncate(decimal d)
Definition Decimal.cs:2792
Decimal(double value)
Definition Decimal.cs:2166
static bool operator<=(decimal d1, decimal d2)
Definition Decimal.cs:2998
Decimal(in decimal d, int flags)
Definition Decimal.cs:2289
static uint ToUInt32(decimal d)
Definition Decimal.cs:2758
const decimal MinusOne
Definition Decimal.cs:2065
static bool TryGetBits(decimal d, Span< int > destination, out int valuesWritten)
Definition Decimal.cs:2504
static decimal Round(decimal d, int decimals, MidpointRounding mode)
Definition Decimal.cs:2586
static bool TryParse(ReadOnlySpan< char > s, NumberStyles style, IFormatProvider? provider, out decimal result)
Definition Decimal.cs:2474
static decimal operator++(decimal d)
Definition Decimal.cs:2943
override int GetHashCode()
Definition Decimal.cs:2359
const decimal MaxValue
Definition Decimal.cs:2067
static decimal Round(decimal d, int decimals)
Definition Decimal.cs:2576
static decimal Add(decimal d1, decimal d2)
Definition Decimal.cs:2300
bool TryFormat(Span< char > destination, out int charsWritten, ReadOnlySpan< char > format=default(ReadOnlySpan< char >), IFormatProvider? provider=null)
Definition Decimal.cs:2399
string ToString(string? format, IFormatProvider? provider)
Definition Decimal.cs:2394
static long ToOACurrency(decimal value)
Definition Decimal.cs:2219
const decimal One
Definition Decimal.cs:2063
static double ToDouble(decimal d)
Definition Decimal.cs:2682
static bool operator<(decimal d1, decimal d2)
Definition Decimal.cs:2993
static decimal operator+(decimal d)
Definition Decimal.cs:2933
static ref DecCalc AsMutable(ref decimal d)
Definition Decimal.cs:3538
const decimal Zero
Definition Decimal.cs:2061
readonly int _flags
Definition Decimal.cs:2071
override string ToString()
Definition Decimal.cs:2379
static ref readonly decimal Min(in decimal d1, in decimal d2)
Definition Decimal.cs:2545
static int ToInt32(decimal d)
Definition Decimal.cs:2687
static long ToInt64(decimal d)
Definition Decimal.cs:2712
static ulong ToUInt64(decimal d)
Definition Decimal.cs:2773
static void Truncate(ref decimal d)
Definition Decimal.cs:2799
static decimal Parse(string s, IFormatProvider? provider)
Definition Decimal.cs:2423
static decimal operator*(decimal d1, decimal d2)
Definition Decimal.cs:2965
static bool operator==(decimal d1, decimal d2)
Definition Decimal.cs:2983
static decimal Floor(decimal d)
Definition Decimal.cs:2369
static decimal operator--(decimal d)
Definition Decimal.cs:2948
static decimal Subtract(decimal d1, decimal d2)
Definition Decimal.cs:2618
Decimal(int lo, int mid, int hi, int flags)
Definition Decimal.cs:2277
static float ToSingle(decimal d)
Definition Decimal.cs:2787
static uint DecDivMod1E9(ref decimal value)
Definition Decimal.cs:3543
static decimal operator-(decimal d)
Definition Decimal.cs:2938
static int[] GetBits(decimal d)
Definition Decimal.cs:2480
static byte ToByte(decimal value)
Definition Decimal.cs:2624
static decimal Round(ref decimal d, int decimals, MidpointRounding mode)
Definition Decimal.cs:2591
static decimal Remainder(decimal d1, decimal d2)
Definition Decimal.cs:2554
override bool Equals([NotNullWhen(true)] object? value)
Definition Decimal.cs:2345
static decimal Divide(decimal d1, decimal d2)
Definition Decimal.cs:2339
Decimal(SerializationInfo info, StreamingContext context)
Definition Decimal.cs:2171
static bool operator>=(decimal d1, decimal d2)
Definition Decimal.cs:3008
static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out decimal result)
Definition Decimal.cs:2463
readonly ulong _lo64
Definition Decimal.cs:2075
static ref readonly decimal Max(in decimal d1, in decimal d2)
Definition Decimal.cs:2536
static decimal Negate(decimal d)
Definition Decimal.cs:2566
static decimal operator/(decimal d1, decimal d2)
Definition Decimal.cs:2971