Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SByte.cs
Go to the documentation of this file.
6
7namespace System;
8
10[CLSCompliant(false)]
11[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
12public readonly struct SByte : IComparable, IConvertible, ISpanFormattable, IFormattable, IComparable<sbyte>, IEquatable<sbyte>, IBinaryInteger<sbyte>, IBinaryNumber<sbyte>, IBitwiseOperators<sbyte, sbyte, sbyte>, INumber<sbyte>, IAdditionOperators<sbyte, sbyte, sbyte>, IAdditiveIdentity<sbyte, sbyte>, IComparisonOperators<sbyte, sbyte>, IEqualityOperators<sbyte, sbyte>, IDecrementOperators<sbyte>, IDivisionOperators<sbyte, sbyte, sbyte>, IIncrementOperators<sbyte>, IModulusOperators<sbyte, sbyte, sbyte>, IMultiplicativeIdentity<sbyte, sbyte>, IMultiplyOperators<sbyte, sbyte, sbyte>, ISpanParseable<sbyte>, IParseable<sbyte>, ISubtractionOperators<sbyte, sbyte, sbyte>, IUnaryNegationOperators<sbyte, sbyte>, IUnaryPlusOperators<sbyte, sbyte>, IShiftOperators<sbyte, sbyte>, IMinMaxValue<sbyte>, ISignedNumber<sbyte>
13{
14 private readonly sbyte m_value;
15
16 public const sbyte MaxValue = 127;
17
18 public const sbyte MinValue = -128;
19
20 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
22
23 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
24 static sbyte IMinMaxValue<sbyte>.MinValue => sbyte.MinValue;
25
26 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
27 static sbyte IMinMaxValue<sbyte>.MaxValue => sbyte.MaxValue;
28
29 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
31
32 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
33 static sbyte INumber<sbyte>.One => 1;
34
35 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
36 static sbyte INumber<sbyte>.Zero => 0;
37
38 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
40
41 public int CompareTo(object? obj)
42 {
43 if (obj == null)
44 {
45 return 1;
46 }
47 if (!(obj is sbyte))
48 {
50 }
51 return this - (sbyte)obj;
52 }
53
54 public int CompareTo(sbyte value)
55 {
56 return this - value;
57 }
58
59 public override bool Equals([NotNullWhen(true)] object? obj)
60 {
61 if (!(obj is sbyte))
62 {
63 return false;
64 }
65 return this == (sbyte)obj;
66 }
67
68 [NonVersionable]
69 public bool Equals(sbyte obj)
70 {
71 return this == obj;
72 }
73
74 public override int GetHashCode()
75 {
76 return this;
77 }
78
79 public override string ToString()
80 {
81 return Number.Int32ToDecStr(this);
82 }
83
84 public string ToString(string? format)
85 {
86 return ToString(format, null);
87 }
88
89 public string ToString(IFormatProvider? provider)
90 {
91 return Number.FormatInt32(this, 0, null, provider);
92 }
93
94 public string ToString(string? format, IFormatProvider? provider)
95 {
96 return Number.FormatInt32(this, 255, format, provider);
97 }
98
99 public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default(ReadOnlySpan<char>), IFormatProvider? provider = null)
100 {
101 return Number.TryFormatInt32(this, 255, format, provider, destination, out charsWritten);
102 }
103
104 public static sbyte Parse(string s)
105 {
106 if (s == null)
107 {
109 }
111 }
112
113 public static sbyte Parse(string s, NumberStyles style)
114 {
116 if (s == null)
117 {
119 }
121 }
122
123 public static sbyte Parse(string s, IFormatProvider? provider)
124 {
125 if (s == null)
126 {
128 }
130 }
131
132 public static sbyte Parse(string s, NumberStyles style, IFormatProvider? provider)
133 {
135 if (s == null)
136 {
138 }
139 return Parse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider));
140 }
141
142 public static sbyte Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
143 {
145 return Parse(s, style, NumberFormatInfo.GetInstance(provider));
146 }
147
149 {
150 int result;
151 Number.ParsingStatus parsingStatus = Number.TryParseInt32(s, style, info, out result);
152 if (parsingStatus != 0)
153 {
154 Number.ThrowOverflowOrFormatException(parsingStatus, TypeCode.SByte);
155 }
156 if ((uint)(result - -128 - ((int)(style & NumberStyles.AllowHexSpecifier) >> 2)) > 255u)
157 {
159 }
160 return (sbyte)result;
161 }
162
163 public static bool TryParse([NotNullWhen(true)] string? s, out sbyte result)
164 {
165 if (s == null)
166 {
167 result = 0;
168 return false;
169 }
171 }
172
173 public static bool TryParse(ReadOnlySpan<char> s, out sbyte result)
174 {
175 return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
176 }
177
178 public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out sbyte result)
179 {
181 if (s == null)
182 {
183 result = 0;
184 return false;
185 }
186 return TryParse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider), out result);
187 }
188
189 public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out sbyte result)
190 {
192 return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
193 }
194
195 private static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info, out sbyte result)
196 {
197 if (Number.TryParseInt32(s, style, info, out var result2) != 0 || (uint)(result2 - -128 - ((int)(style & NumberStyles.AllowHexSpecifier) >> 2)) > 255u)
198 {
199 result = 0;
200 return false;
201 }
202 result = (sbyte)result2;
203 return true;
204 }
205
207 {
208 return TypeCode.SByte;
209 }
210
212 {
213 return Convert.ToBoolean(this);
214 }
215
217 {
218 return Convert.ToChar(this);
219 }
220
222 {
223 return this;
224 }
225
227 {
228 return Convert.ToByte(this);
229 }
230
232 {
233 return Convert.ToInt16(this);
234 }
235
237 {
238 return Convert.ToUInt16(this);
239 }
240
242 {
243 return this;
244 }
245
247 {
248 return Convert.ToUInt32(this);
249 }
250
252 {
253 return Convert.ToInt64(this);
254 }
255
257 {
258 return Convert.ToUInt64(this);
259 }
260
262 {
263 return Convert.ToSingle(this);
264 }
265
267 {
268 return Convert.ToDouble(this);
269 }
270
272 {
273 return Convert.ToDecimal(this);
274 }
275
277 {
278 throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "SByte", "DateTime"));
279 }
280
282 {
283 return Convert.DefaultToType(this, type, provider);
284 }
285
286 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
287 static sbyte IAdditionOperators<sbyte, sbyte, sbyte>.operator +(sbyte left, sbyte right)
288 {
289 return (sbyte)(left + right);
290 }
291
292 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
294 {
295 return (sbyte)(BitOperations.LeadingZeroCount((byte)value) - 24);
296 }
297
298 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
300 {
301 return (sbyte)BitOperations.PopCount((byte)value);
302 }
303
304 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
305 static sbyte IBinaryInteger<sbyte>.RotateLeft(sbyte value, int rotateAmount)
306 {
307 return (sbyte)((value << (rotateAmount & 7)) | ((byte)value >> ((8 - rotateAmount) & 7)));
308 }
309
310 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
311 static sbyte IBinaryInteger<sbyte>.RotateRight(sbyte value, int rotateAmount)
312 {
313 return (sbyte)(((byte)value >> (rotateAmount & 7)) | (value << ((8 - rotateAmount) & 7)));
314 }
315
316 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
318 {
319 return (sbyte)(BitOperations.TrailingZeroCount(value << 24) - 24);
320 }
321
322 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
324 {
325 return BitOperations.IsPow2(value);
326 }
327
328 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
329 static sbyte IBinaryNumber<sbyte>.Log2(sbyte value)
330 {
331 if (value < 0)
332 {
334 }
335 return (sbyte)BitOperations.Log2((byte)value);
336 }
337
338 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
339 static sbyte IBitwiseOperators<sbyte, sbyte, sbyte>.operator &(sbyte left, sbyte right)
340 {
341 return (sbyte)(left & right);
342 }
343
344 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
345 static sbyte IBitwiseOperators<sbyte, sbyte, sbyte>.operator |(sbyte left, sbyte right)
346 {
347 return (sbyte)(left | right);
348 }
349
350 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
351 static sbyte IBitwiseOperators<sbyte, sbyte, sbyte>.operator ^(sbyte left, sbyte right)
352 {
353 return (sbyte)(left ^ right);
354 }
355
356 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
357 static sbyte IBitwiseOperators<sbyte, sbyte, sbyte>.operator ~(sbyte value)
358 {
359 return (sbyte)(~value);
360 }
361
362 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
363 static bool IComparisonOperators<sbyte, sbyte>.operator <(sbyte left, sbyte right)
364 {
365 return left < right;
366 }
367
368 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
369 static bool IComparisonOperators<sbyte, sbyte>.operator <=(sbyte left, sbyte right)
370 {
371 return left <= right;
372 }
373
374 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
375 static bool IComparisonOperators<sbyte, sbyte>.operator >(sbyte left, sbyte right)
376 {
377 return left > right;
378 }
379
380 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
381 static bool IComparisonOperators<sbyte, sbyte>.operator >=(sbyte left, sbyte right)
382 {
383 return left >= right;
384 }
385
386 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
387 static sbyte IDecrementOperators<sbyte>.operator --(sbyte value)
388 {
389 return --value;
390 }
391
392 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
393 static sbyte IDivisionOperators<sbyte, sbyte, sbyte>.operator /(sbyte left, sbyte right)
394 {
395 return (sbyte)(left / right);
396 }
397
398 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
399 static bool IEqualityOperators<sbyte, sbyte>.operator ==(sbyte left, sbyte right)
400 {
401 return left == right;
402 }
403
404 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
405 static bool IEqualityOperators<sbyte, sbyte>.operator !=(sbyte left, sbyte right)
406 {
407 return left != right;
408 }
409
410 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
411 static sbyte IIncrementOperators<sbyte>.operator ++(sbyte value)
412 {
413 return ++value;
414 }
415
416 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
417 static sbyte IModulusOperators<sbyte, sbyte, sbyte>.operator %(sbyte left, sbyte right)
418 {
419 return (sbyte)(left % right);
420 }
421
422 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
423 static sbyte IMultiplyOperators<sbyte, sbyte, sbyte>.operator *(sbyte left, sbyte right)
424 {
425 return (sbyte)(left * right);
426 }
427
428 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
429 static sbyte INumber<sbyte>.Abs(sbyte value)
430 {
431 return Math.Abs(value);
432 }
433
434 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
435 static sbyte INumber<sbyte>.Clamp(sbyte value, sbyte min, sbyte max)
436 {
437 return Math.Clamp(value, min, max);
438 }
439
440 [MethodImpl(MethodImplOptions.AggressiveInlining)]
441 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
442 static sbyte INumber<sbyte>.Create<TOther>(TOther value)
443 {
444 checked
445 {
446 if (typeof(TOther) == typeof(byte))
447 {
448 return (sbyte)(byte)(object)value;
449 }
450 if (typeof(TOther) == typeof(char))
451 {
452 return (sbyte)(char)(object)value;
453 }
454 if (typeof(TOther) == typeof(decimal))
455 {
456 return (sbyte)(decimal)(object)value;
457 }
458 if (typeof(TOther) == typeof(double))
459 {
460 return (sbyte)(double)(object)value;
461 }
462 if (typeof(TOther) == typeof(short))
463 {
464 return (sbyte)(short)(object)value;
465 }
466 if (typeof(TOther) == typeof(int))
467 {
468 return (sbyte)(int)(object)value;
469 }
470 if (typeof(TOther) == typeof(long))
471 {
472 return (sbyte)(long)(object)value;
473 }
474 if (typeof(TOther) == typeof(IntPtr))
475 {
476 return (sbyte)(nint)(IntPtr)(object)value;
477 }
478 if (typeof(TOther) == typeof(sbyte))
479 {
480 return (sbyte)(object)value;
481 }
482 if (typeof(TOther) == typeof(float))
483 {
484 return (sbyte)(float)(object)value;
485 }
486 if (typeof(TOther) == typeof(ushort))
487 {
488 return (sbyte)(ushort)(object)value;
489 }
490 if (typeof(TOther) == typeof(uint))
491 {
492 return (sbyte)(uint)(object)value;
493 }
494 if (typeof(TOther) == typeof(ulong))
495 {
496 return (sbyte)(ulong)(object)value;
497 }
498 if (typeof(TOther) == typeof(UIntPtr))
499 {
500 return (sbyte)(nuint)(UIntPtr)(object)value;
501 }
503 return 0;
504 }
505 }
506
507 [MethodImpl(MethodImplOptions.AggressiveInlining)]
508 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
509 static sbyte INumber<sbyte>.CreateSaturating<TOther>(TOther value)
510 {
511 if (typeof(TOther) == typeof(byte))
512 {
513 byte b = (byte)(object)value;
514 if (b <= 127)
515 {
516 return (sbyte)b;
517 }
518 return sbyte.MaxValue;
519 }
520 if (typeof(TOther) == typeof(char))
521 {
522 char c = (char)(object)value;
523 if (c <= '\u007f')
524 {
525 return (sbyte)c;
526 }
527 return sbyte.MaxValue;
528 }
529 if (typeof(TOther) == typeof(decimal))
530 {
531 decimal num = (decimal)(object)value;
532 if (!(num > 127m))
533 {
534 if (!(num < -128m))
535 {
536 return (sbyte)num;
537 }
538 return sbyte.MinValue;
539 }
540 return sbyte.MaxValue;
541 }
542 if (typeof(TOther) == typeof(double))
543 {
544 double num2 = (double)(object)value;
545 if (!(num2 > 127.0))
546 {
547 if (!(num2 < -128.0))
548 {
549 return (sbyte)num2;
550 }
551 return sbyte.MinValue;
552 }
553 return sbyte.MaxValue;
554 }
555 if (typeof(TOther) == typeof(short))
556 {
557 short num3 = (short)(object)value;
558 if (num3 <= 127)
559 {
560 if (num3 >= -128)
561 {
562 return (sbyte)num3;
563 }
564 return sbyte.MinValue;
565 }
566 return sbyte.MaxValue;
567 }
568 if (typeof(TOther) == typeof(int))
569 {
570 int num4 = (int)(object)value;
571 if (num4 <= 127)
572 {
573 if (num4 >= -128)
574 {
575 return (sbyte)num4;
576 }
577 return sbyte.MinValue;
578 }
579 return sbyte.MaxValue;
580 }
581 if (typeof(TOther) == typeof(long))
582 {
583 long num5 = (long)(object)value;
584 if (num5 <= 127)
585 {
586 if (num5 >= -128)
587 {
588 return (sbyte)num5;
589 }
590 return sbyte.MinValue;
591 }
592 return sbyte.MaxValue;
593 }
594 if (typeof(TOther) == typeof(IntPtr))
595 {
596 IntPtr intPtr = (IntPtr)(object)value;
597 if ((nint)intPtr <= 127)
598 {
599 if ((nint)intPtr >= -128)
600 {
601 return (sbyte)(nint)intPtr;
602 }
603 return sbyte.MinValue;
604 }
605 return sbyte.MaxValue;
606 }
607 if (typeof(TOther) == typeof(sbyte))
608 {
609 return (sbyte)(object)value;
610 }
611 if (typeof(TOther) == typeof(float))
612 {
613 float num6 = (float)(object)value;
614 if (!(num6 > 127f))
615 {
616 if (!(num6 < -128f))
617 {
618 return (sbyte)num6;
619 }
620 return sbyte.MinValue;
621 }
622 return sbyte.MaxValue;
623 }
624 if (typeof(TOther) == typeof(ushort))
625 {
626 ushort num7 = (ushort)(object)value;
627 if (num7 <= 127)
628 {
629 return (sbyte)num7;
630 }
631 return sbyte.MaxValue;
632 }
633 if (typeof(TOther) == typeof(uint))
634 {
635 uint num8 = (uint)(object)value;
636 if ((long)num8 <= 127L)
637 {
638 return (sbyte)num8;
639 }
640 return sbyte.MaxValue;
641 }
642 if (typeof(TOther) == typeof(ulong))
643 {
644 ulong num9 = (ulong)(object)value;
645 if (num9 <= 127)
646 {
647 return (sbyte)num9;
648 }
649 return sbyte.MaxValue;
650 }
651 if (typeof(TOther) == typeof(UIntPtr))
652 {
653 UIntPtr uIntPtr = (UIntPtr)(object)value;
654 if ((nuint)uIntPtr <= 127)
655 {
656 return (sbyte)(nuint)uIntPtr;
657 }
658 return sbyte.MaxValue;
659 }
661 return 0;
662 }
663
664 [MethodImpl(MethodImplOptions.AggressiveInlining)]
665 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
666 static sbyte INumber<sbyte>.CreateTruncating<TOther>(TOther value)
667 {
668 if (typeof(TOther) == typeof(byte))
669 {
670 return (sbyte)(byte)(object)value;
671 }
672 if (typeof(TOther) == typeof(char))
673 {
674 return (sbyte)(char)(object)value;
675 }
676 if (typeof(TOther) == typeof(decimal))
677 {
678 return (sbyte)(decimal)(object)value;
679 }
680 if (typeof(TOther) == typeof(double))
681 {
682 return (sbyte)(double)(object)value;
683 }
684 if (typeof(TOther) == typeof(short))
685 {
686 return (sbyte)(short)(object)value;
687 }
688 if (typeof(TOther) == typeof(int))
689 {
690 return (sbyte)(int)(object)value;
691 }
692 if (typeof(TOther) == typeof(long))
693 {
694 return (sbyte)(long)(object)value;
695 }
696 if (typeof(TOther) == typeof(IntPtr))
697 {
698 return (sbyte)(nint)(IntPtr)(object)value;
699 }
700 if (typeof(TOther) == typeof(sbyte))
701 {
702 return (sbyte)(object)value;
703 }
704 if (typeof(TOther) == typeof(float))
705 {
706 return (sbyte)(float)(object)value;
707 }
708 if (typeof(TOther) == typeof(ushort))
709 {
710 return (sbyte)(ushort)(object)value;
711 }
712 if (typeof(TOther) == typeof(uint))
713 {
714 return (sbyte)(uint)(object)value;
715 }
716 if (typeof(TOther) == typeof(ulong))
717 {
718 return (sbyte)(ulong)(object)value;
719 }
720 if (typeof(TOther) == typeof(UIntPtr))
721 {
722 return (sbyte)(nuint)(UIntPtr)(object)value;
723 }
725 return 0;
726 }
727
728 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
729 static (sbyte Quotient, sbyte Remainder) INumber<sbyte>.DivRem(sbyte left, sbyte right)
730 {
731 return Math.DivRem(left, right);
732 }
733
734 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
735 static sbyte INumber<sbyte>.Max(sbyte x, sbyte y)
736 {
737 return Math.Max(x, y);
738 }
739
740 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
741 static sbyte INumber<sbyte>.Min(sbyte x, sbyte y)
742 {
743 return Math.Min(x, y);
744 }
745
746 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
747 static sbyte INumber<sbyte>.Parse(string s, NumberStyles style, IFormatProvider provider)
748 {
749 return Parse(s, style, provider);
750 }
751
752 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
754 {
755 return Parse(s, style, provider);
756 }
757
758 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
759 static sbyte INumber<sbyte>.Sign(sbyte value)
760 {
761 return (sbyte)Math.Sign(value);
762 }
763
764 [MethodImpl(MethodImplOptions.AggressiveInlining)]
765 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
766 static bool INumber<sbyte>.TryCreate<TOther>(TOther value, out sbyte result)
767 {
768 if (typeof(TOther) == typeof(byte))
769 {
770 byte b = (byte)(object)value;
771 if (b > 127)
772 {
773 result = 0;
774 return false;
775 }
776 result = (sbyte)b;
777 return true;
778 }
779 if (typeof(TOther) == typeof(char))
780 {
781 char c = (char)(object)value;
782 if (c > '\u007f')
783 {
784 result = 0;
785 return false;
786 }
787 result = (sbyte)c;
788 return true;
789 }
790 if (typeof(TOther) == typeof(decimal))
791 {
792 decimal num = (decimal)(object)value;
793 if (num < -128m || num > 127m)
794 {
795 result = 0;
796 return false;
797 }
798 result = (sbyte)num;
799 return true;
800 }
801 if (typeof(TOther) == typeof(double))
802 {
803 double num2 = (double)(object)value;
804 if (num2 < -128.0 || num2 > 127.0)
805 {
806 result = 0;
807 return false;
808 }
809 result = (sbyte)num2;
810 return true;
811 }
812 if (typeof(TOther) == typeof(short))
813 {
814 short num3 = (short)(object)value;
815 if (num3 < -128 || num3 > 127)
816 {
817 result = 0;
818 return false;
819 }
820 result = (sbyte)num3;
821 return true;
822 }
823 if (typeof(TOther) == typeof(int))
824 {
825 int num4 = (int)(object)value;
826 if (num4 < -128 || num4 > 127)
827 {
828 result = 0;
829 return false;
830 }
831 result = (sbyte)num4;
832 return true;
833 }
834 if (typeof(TOther) == typeof(long))
835 {
836 long num5 = (long)(object)value;
837 if (num5 < -128 || num5 > 127)
838 {
839 result = 0;
840 return false;
841 }
842 result = (sbyte)num5;
843 return true;
844 }
845 if (typeof(TOther) == typeof(IntPtr))
846 {
847 IntPtr intPtr = (IntPtr)(object)value;
848 if ((nint)intPtr < -128 || (nint)intPtr > 127)
849 {
850 result = 0;
851 return false;
852 }
853 result = (sbyte)(nint)intPtr;
854 return true;
855 }
856 if (typeof(TOther) == typeof(sbyte))
857 {
858 result = (sbyte)(object)value;
859 return true;
860 }
861 if (typeof(TOther) == typeof(float))
862 {
863 float num6 = (float)(object)value;
864 if (num6 < -128f || num6 > 127f)
865 {
866 result = 0;
867 return false;
868 }
869 result = (sbyte)num6;
870 return true;
871 }
872 if (typeof(TOther) == typeof(ushort))
873 {
874 ushort num7 = (ushort)(object)value;
875 if (num7 > 127)
876 {
877 result = 0;
878 return false;
879 }
880 result = (sbyte)num7;
881 return true;
882 }
883 if (typeof(TOther) == typeof(uint))
884 {
885 uint num8 = (uint)(object)value;
886 if ((long)num8 > 127L)
887 {
888 result = 0;
889 return false;
890 }
891 result = (sbyte)num8;
892 return true;
893 }
894 if (typeof(TOther) == typeof(ulong))
895 {
896 ulong num9 = (ulong)(object)value;
897 if (num9 > 127)
898 {
899 result = 0;
900 return false;
901 }
902 result = (sbyte)num9;
903 return true;
904 }
905 if (typeof(TOther) == typeof(UIntPtr))
906 {
907 UIntPtr uIntPtr = (UIntPtr)(object)value;
908 if ((nuint)uIntPtr > 127)
909 {
910 result = 0;
911 return false;
912 }
913 result = (sbyte)(nuint)uIntPtr;
914 return true;
915 }
917 result = 0;
918 return false;
919 }
920
921 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
922 static bool INumber<sbyte>.TryParse([NotNullWhen(true)] string s, NumberStyles style, IFormatProvider provider, out sbyte result)
923 {
924 return TryParse(s, style, provider, out result);
925 }
926
927 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
928 static bool INumber<sbyte>.TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out sbyte result)
929 {
930 return TryParse(s, style, provider, out result);
931 }
932
933 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
934 static sbyte IParseable<sbyte>.Parse(string s, IFormatProvider provider)
935 {
936 return Parse(s, provider);
937 }
938
939 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
940 static bool IParseable<sbyte>.TryParse([NotNullWhen(true)] string s, IFormatProvider provider, out sbyte result)
941 {
942 return TryParse(s, NumberStyles.Integer, provider, out result);
943 }
944
945 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
946 static sbyte IShiftOperators<sbyte, sbyte>.operator <<(sbyte value, int shiftAmount)
947 {
948 return (sbyte)(value << shiftAmount);
949 }
950
951 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
952 static sbyte IShiftOperators<sbyte, sbyte>.operator >>(sbyte value, int shiftAmount)
953 {
954 return (sbyte)(value >> shiftAmount);
955 }
956
957 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
959 {
960 return Parse(s, NumberStyles.Integer, provider);
961 }
962
963 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
964 static bool ISpanParseable<sbyte>.TryParse(ReadOnlySpan<char> s, IFormatProvider provider, out sbyte result)
965 {
966 return TryParse(s, NumberStyles.Integer, provider, out result);
967 }
968
969 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
970 static sbyte ISubtractionOperators<sbyte, sbyte, sbyte>.operator -(sbyte left, sbyte right)
971 {
972 return (sbyte)(left - right);
973 }
974
975 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
976 static sbyte IUnaryNegationOperators<sbyte, sbyte>.operator -(sbyte value)
977 {
978 return (sbyte)(-value);
979 }
980
981 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
982 static sbyte IUnaryPlusOperators<sbyte, sbyte>.operator +(sbyte value)
983 {
984 return value;
985 }
986}
static decimal ToDecimal(object? value)
Definition Convert.cs:2101
static long ToInt64(object? value)
Definition Convert.cs:1623
static float ToSingle(object? value)
Definition Convert.cs:1881
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 char ToChar(object? value)
Definition Convert.cs:618
static ushort ToUInt16(object? value)
Definition Convert.cs:1177
static double ToDouble(object? value)
Definition Convert.cs:1991
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 void ValidateParseStyleInteger(NumberStyles style)
static NumberFormatInfo GetInstance(IFormatProvider? formatProvider)
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 double Abs(double value)
static int DivRem(int a, int b, out int result)
Definition Math.cs:329
static int Sign(decimal value)
Definition Math.cs:1202
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static void ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type=TypeCode.Empty)
Definition Number.cs:5918
static void ThrowOverflowException(TypeCode type)
Definition Number.cs:5924
static string FormatInt32(int value, int hexMask, string format, IFormatProvider provider)
Definition Number.cs:1882
static string Int32ToDecStr(int value)
Definition Number.cs:2246
static ParsingStatus TryParseInt32(ReadOnlySpan< char > value, NumberStyles styles, NumberFormatInfo info, out int result)
Definition Number.cs:4251
static bool TryFormatInt32(int value, int hexMask, ReadOnlySpan< char > format, IFormatProvider provider, Span< char > destination, out int charsWritten)
Definition Number.cs:1929
static int TrailingZeroCount(int value)
static bool IsPow2(int value)
static int PopCount(uint value)
static int Log2(uint value)
static int LeadingZeroCount(uint value)
static string InvalidCast_FromTo
Definition SR.cs:1392
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Arg_MustBeSByte
Definition SR.cs:294
Definition SR.cs:7
static void ThrowNotSupportedException(ExceptionResource resource)
static void ThrowValueArgumentOutOfRange_NeedNonNegNumException()
static void ThrowArgumentNullException(string name)
static TResult AdditiveIdentity
static TSelf RotateRight(TSelf value, int rotateAmount)
static TSelf LeadingZeroCount(TSelf value)
static TSelf PopCount(TSelf value)
static TSelf TrailingZeroCount(TSelf value)
static TSelf RotateLeft(TSelf value, int rotateAmount)
static bool IsPow2(TSelf value)
static TSelf Log2(TSelf value)
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)
TypeCode
Definition TypeCode.cs:4
static IntPtr MinValue
Definition IntPtr.cs:39
static bool TryParse(ReadOnlySpan< char > s, out sbyte result)
Definition SByte.cs:173
static sbyte Parse(ReadOnlySpan< char > s, NumberStyles style=NumberStyles.Integer, IFormatProvider? provider=null)
Definition SByte.cs:142
string ToString(string? format)
Definition SByte.cs:84
static sbyte Parse(ReadOnlySpan< char > s, NumberStyles style, NumberFormatInfo info)
Definition SByte.cs:148
override bool Equals([NotNullWhen(true)] object? obj)
Definition SByte.cs:59
const sbyte MinValue
Definition SByte.cs:18
static sbyte Parse(string s, NumberStyles style, IFormatProvider? provider)
Definition SByte.cs:132
override string ToString()
Definition SByte.cs:79
static sbyte sbyte Remainder INumber< sbyte >. DivRem(sbyte left, sbyte right)
Definition SByte.cs:729
const sbyte MaxValue
Definition SByte.cs:16
bool Equals(sbyte obj)
Definition SByte.cs:69
int CompareTo(object? obj)
Definition SByte.cs:41
int CompareTo(sbyte value)
Definition SByte.cs:54
TypeCode GetTypeCode()
Definition SByte.cs:206
static bool TryParse(ReadOnlySpan< char > s, NumberStyles style, IFormatProvider? provider, out sbyte result)
Definition SByte.cs:189
bool TryFormat(Span< char > destination, out int charsWritten, ReadOnlySpan< char > format=default(ReadOnlySpan< char >), IFormatProvider? provider=null)
Definition SByte.cs:99
string ToString(IFormatProvider? provider)
Definition SByte.cs:89
static bool TryParse([NotNullWhen(true)] string? s, out sbyte result)
Definition SByte.cs:163
readonly sbyte m_value
Definition SByte.cs:14
static bool TryParse(ReadOnlySpan< char > s, NumberStyles style, NumberFormatInfo info, out sbyte result)
Definition SByte.cs:195
override int GetHashCode()
Definition SByte.cs:74
static sbyte Parse(string s, NumberStyles style)
Definition SByte.cs:113
static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out sbyte result)
Definition SByte.cs:178
static sbyte Parse(string s, IFormatProvider? provider)
Definition SByte.cs:123
static sbyte Quotient
Definition SByte.cs:729
string ToString(string? format, IFormatProvider? provider)
Definition SByte.cs:94
static sbyte Parse(string s)
Definition SByte.cs:104
static UIntPtr MaxValue
Definition UIntPtr.cs:31