Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Half.cs
Go to the documentation of this file.
6
7namespace System;
8
9public readonly struct Half : IComparable, ISpanFormattable, IFormattable, IComparable<Half>, IEquatable<Half>, IBinaryFloatingPoint<Half>, IBinaryNumber<Half>, IBitwiseOperators<Half, Half, Half>, INumber<Half>, IAdditionOperators<Half, Half, Half>, IAdditiveIdentity<Half, Half>, IComparisonOperators<Half, Half>, IEqualityOperators<Half, Half>, IDecrementOperators<Half>, IDivisionOperators<Half, Half, Half>, IIncrementOperators<Half>, IModulusOperators<Half, Half, Half>, IMultiplicativeIdentity<Half, Half>, IMultiplyOperators<Half, Half, Half>, ISpanParseable<Half>, IParseable<Half>, ISubtractionOperators<Half, Half, Half>, IUnaryNegationOperators<Half, Half>, IUnaryPlusOperators<Half, Half>, IFloatingPoint<Half>, ISignedNumber<Half>, IMinMaxValue<Half>
10{
11 private static readonly Half PositiveZero = new Half(0);
12
13 private static readonly Half NegativeZero = new Half(32768);
14
15 private readonly ushort _value;
16
17 public static Half Epsilon => new Half(1);
18
19 public static Half PositiveInfinity => new Half(31744);
20
21 public static Half NegativeInfinity => new Half(64512);
22
23 public static Half NaN => new Half(65024);
24
25 public static Half MinValue => new Half(64511);
26
27 public static Half MaxValue => new Half(31743);
28
29 private sbyte Exponent => (sbyte)((_value & 0x7C00) >> 10);
30
31 private ushort Significand => (ushort)(_value & 0x3FFu);
32
33 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
35
36 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
37 static Half IFloatingPoint<Half>.E => (Half)(float)Math.E;
38
39 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
41
42 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
44
45 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
47
48 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
50
51 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
53
54 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
56
57 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
58 static Half IFloatingPoint<Half>.Tau => (Half)((float)Math.PI * 2f);
59
60 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
62
63 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
65
66 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
68
69 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
70 static Half INumber<Half>.One => (Half)1f;
71
72 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
74
75 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
77
78 internal Half(ushort value)
79 {
80 _value = value;
81 }
82
83 private Half(bool sign, ushort exp, ushort sig)
84 {
85 _value = (ushort)(((sign ? 1 : 0) << 15) + (exp << 10) + sig);
86 }
87
88 public static bool operator <(Half left, Half right)
89 {
90 if (IsNaN(left) || IsNaN(right))
91 {
92 return false;
93 }
94 bool flag = IsNegative(left);
95 if (flag != IsNegative(right))
96 {
97 if (flag)
98 {
99 return !AreZero(left, right);
100 }
101 return false;
102 }
103 if (left._value != right._value)
104 {
105 return (left._value < right._value) ^ flag;
106 }
107 return false;
108 }
109
110 public static bool operator >(Half left, Half right)
111 {
112 return right < left;
113 }
114
115 public static bool operator <=(Half left, Half right)
116 {
117 if (IsNaN(left) || IsNaN(right))
118 {
119 return false;
120 }
121 bool flag = IsNegative(left);
122 if (flag != IsNegative(right))
123 {
124 if (!flag)
125 {
126 return AreZero(left, right);
127 }
128 return true;
129 }
130 if (left._value != right._value)
131 {
132 return (left._value < right._value) ^ flag;
133 }
134 return true;
135 }
136
137 public static bool operator >=(Half left, Half right)
138 {
139 return right <= left;
140 }
141
142 public static bool operator ==(Half left, Half right)
143 {
144 if (IsNaN(left) || IsNaN(right))
145 {
146 return false;
147 }
148 if (left._value != right._value)
149 {
150 return AreZero(left, right);
151 }
152 return true;
153 }
154
155 public static bool operator !=(Half left, Half right)
156 {
157 return !(left == right);
158 }
159
160 public static bool IsFinite(Half value)
161 {
162 return StripSign(value) < 31744;
163 }
164
165 public static bool IsInfinity(Half value)
166 {
167 return StripSign(value) == 31744;
168 }
169
170 public static bool IsNaN(Half value)
171 {
172 return StripSign(value) > 31744;
173 }
174
175 public static bool IsNegative(Half value)
176 {
177 return (short)value._value < 0;
178 }
179
180 public static bool IsNegativeInfinity(Half value)
181 {
182 return value._value == 64512;
183 }
184
185 public static bool IsNormal(Half value)
186 {
187 uint num = StripSign(value);
188 if (num < 31744 && num != 0)
189 {
190 return (num & 0x7C00) != 0;
191 }
192 return false;
193 }
194
195 public static bool IsPositiveInfinity(Half value)
196 {
197 return value._value == 31744;
198 }
199
200 public static bool IsSubnormal(Half value)
201 {
202 uint num = StripSign(value);
203 if (num < 31744 && num != 0)
204 {
205 return (num & 0x7C00) == 0;
206 }
207 return false;
208 }
209
210 public static Half Parse(string s)
211 {
212 if (s == null)
213 {
215 }
216 return Number.ParseHalf(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo);
217 }
218
219 public static Half Parse(string s, NumberStyles style)
220 {
222 if (s == null)
223 {
225 }
227 }
228
229 public static Half Parse(string s, IFormatProvider? provider)
230 {
231 if (s == null)
232 {
234 }
235 return Number.ParseHalf(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.GetInstance(provider));
236 }
237
238 public static Half Parse(string s, NumberStyles style = NumberStyles.Float | NumberStyles.AllowThousands, IFormatProvider? provider = null)
239 {
241 if (s == null)
242 {
244 }
245 return Number.ParseHalf(s, style, NumberFormatInfo.GetInstance(provider));
246 }
247
248 public static Half Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Float | NumberStyles.AllowThousands, IFormatProvider? provider = null)
249 {
251 return Number.ParseHalf(s, style, NumberFormatInfo.GetInstance(provider));
252 }
253
254 public static bool TryParse([NotNullWhen(true)] string? s, out Half result)
255 {
256 if (s == null)
257 {
258 result = default(Half);
259 return false;
260 }
261 return TryParse(s, NumberStyles.Float | NumberStyles.AllowThousands, null, out result);
262 }
263
264 public static bool TryParse(ReadOnlySpan<char> s, out Half result)
265 {
266 return TryParse(s, NumberStyles.Float | NumberStyles.AllowThousands, null, out result);
267 }
268
269 public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out Half result)
270 {
272 if (s == null)
273 {
274 result = default(Half);
275 return false;
276 }
277 return TryParse(s.AsSpan(), style, provider, out result);
278 }
279
280 public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out Half result)
281 {
283 return Number.TryParseHalf(s, style, NumberFormatInfo.GetInstance(provider), out result);
284 }
285
286 private static bool AreZero(Half left, Half right)
287 {
288 return (ushort)((left._value | right._value) & -32769) == 0;
289 }
290
291 private static bool IsNaNOrZero(Half value)
292 {
293 return ((value._value - 1) & -32769) >= 31744;
294 }
295
296 private static uint StripSign(Half value)
297 {
298 return (ushort)(value._value & 0xFFFF7FFFu);
299 }
300
301 public int CompareTo(object? obj)
302 {
303 if (!(obj is Half))
304 {
305 if (obj != null)
306 {
308 }
309 return 1;
310 }
311 return CompareTo((Half)obj);
312 }
313
314 public int CompareTo(Half other)
315 {
316 if (this < other)
317 {
318 return -1;
319 }
320 if (this > other)
321 {
322 return 1;
323 }
324 if (this == other)
325 {
326 return 0;
327 }
328 if (IsNaN(this))
329 {
330 if (!IsNaN(other))
331 {
332 return -1;
333 }
334 return 0;
335 }
336 return 1;
337 }
338
339 public override bool Equals([NotNullWhen(true)] object? obj)
340 {
341 if (obj is Half other)
342 {
343 return Equals(other);
344 }
345 return false;
346 }
347
348 public bool Equals(Half other)
349 {
350 if (_value != other._value && !AreZero(this, other))
351 {
352 if (IsNaN(this))
353 {
354 return IsNaN(other);
355 }
356 return false;
357 }
358 return true;
359 }
360
361 public override int GetHashCode()
362 {
363 if (IsNaNOrZero(this))
364 {
365 return _value & 0x7C00;
366 }
367 return _value;
368 }
369
370 public override string ToString()
371 {
372 return Number.FormatHalf(this, null, NumberFormatInfo.CurrentInfo);
373 }
374
375 public string ToString(string? format)
376 {
378 }
379
380 public string ToString(IFormatProvider? provider)
381 {
382 return Number.FormatHalf(this, null, NumberFormatInfo.GetInstance(provider));
383 }
384
385 public string ToString(string? format, IFormatProvider? provider)
386 {
387 return Number.FormatHalf(this, format, NumberFormatInfo.GetInstance(provider));
388 }
389
390 public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default(ReadOnlySpan<char>), IFormatProvider? provider = null)
391 {
392 return Number.TryFormatHalf(this, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten);
393 }
394
395 public static explicit operator Half(float value)
396 {
398 bool flag = (num & 0x80000000u) >> 31 != 0;
399 int num2 = (int)(num & 0x7F800000) >> 23;
400 uint num3 = num & 0x7FFFFFu;
401 if (num2 == 255)
402 {
403 if (num3 != 0)
404 {
405 return CreateHalfNaN(flag, (ulong)num3 << 41);
406 }
407 if (!flag)
408 {
409 return PositiveInfinity;
410 }
411 return NegativeInfinity;
412 }
413 uint num4 = (num3 >> 9) | (((num3 & 0x1FFu) != 0) ? 1u : 0u);
414 if (((uint)num2 | num4) == 0)
415 {
416 return new Half(flag, 0, 0);
417 }
418 return new Half(RoundPackToHalf(flag, (short)(num2 - 113), (ushort)(num4 | 0x4000u)));
419 }
420
421 public static explicit operator Half(double value)
422 {
424 bool flag = (num & 0x8000000000000000uL) >> 63 != 0;
425 int num2 = (int)((num & 0x7FF0000000000000L) >> 52);
426 ulong num3 = num & 0xFFFFFFFFFFFFFuL;
427 if (num2 == 2047)
428 {
429 if (num3 != 0L)
430 {
431 return CreateHalfNaN(flag, num3 << 12);
432 }
433 if (!flag)
434 {
435 return PositiveInfinity;
436 }
437 return NegativeInfinity;
438 }
439 uint num4 = (uint)ShiftRightJam(num3, 38);
440 if (((uint)num2 | num4) == 0)
441 {
442 return new Half(flag, 0, 0);
443 }
444 return new Half(RoundPackToHalf(flag, (short)(num2 - 1009), (ushort)(num4 | 0x4000u)));
445 }
446
447 public static explicit operator float(Half value)
448 {
449 bool flag = IsNegative(value);
450 int num = value.Exponent;
451 uint num2 = value.Significand;
452 switch (num)
453 {
454 case 31:
455 if (num2 != 0)
456 {
457 return CreateSingleNaN(flag, (ulong)num2 << 54);
458 }
459 if (!flag)
460 {
461 return float.PositiveInfinity;
462 }
463 return float.NegativeInfinity;
464 case 0:
465 {
466 if (num2 == 0)
467 {
468 return BitConverter.UInt32BitsToSingle(flag ? 2147483648u : 0u);
469 }
470 (int Exp, uint Sig) tuple = NormSubnormalF16Sig(num2);
471 num = tuple.Exp;
472 num2 = tuple.Sig;
473 num--;
474 break;
475 }
476 }
477 return CreateSingle(flag, (byte)(num + 112), num2 << 13);
478 }
479
480 public static explicit operator double(Half value)
481 {
482 bool flag = IsNegative(value);
483 int num = value.Exponent;
484 uint num2 = value.Significand;
485 switch (num)
486 {
487 case 31:
488 if (num2 != 0)
489 {
490 return CreateDoubleNaN(flag, (ulong)num2 << 54);
491 }
492 if (!flag)
493 {
494 return double.PositiveInfinity;
495 }
496 return double.NegativeInfinity;
497 case 0:
498 {
499 if (num2 == 0)
500 {
501 return BitConverter.UInt64BitsToDouble(flag ? 9223372036854775808uL : 0);
502 }
503 (int Exp, uint Sig) tuple = NormSubnormalF16Sig(num2);
504 num = tuple.Exp;
505 num2 = tuple.Sig;
506 num--;
507 break;
508 }
509 }
510 return CreateDouble(flag, (ushort)(num + 1008), (ulong)num2 << 42);
511 }
512
513 internal static Half Negate(Half value)
514 {
515 if (!IsNaN(value))
516 {
517 return new Half((ushort)(value._value ^ 0x8000u));
518 }
519 return value;
520 }
521
522 private static (int Exp, uint Sig) NormSubnormalF16Sig(uint sig)
523 {
524 int num = BitOperations.LeadingZeroCount(sig) - 16 - 5;
525 return (Exp: 1 - num, Sig: sig << num);
526 }
527
528 private static Half CreateHalfNaN(bool sign, ulong significand)
529 {
530 uint num = (uint)((sign ? 1 : 0) << 15);
531 uint num2 = (uint)(significand >> 54);
532 return BitConverter.UInt16BitsToHalf((ushort)(num | 0x7E00u | num2));
533 }
534
535 private static ushort RoundPackToHalf(bool sign, short exp, ushort sig)
536 {
537 int num = sig & 0xF;
538 if ((uint)exp >= 29u)
539 {
540 if (exp < 0)
541 {
542 sig = (ushort)ShiftRightJam(sig, -exp);
543 exp = 0;
544 num = sig & 0xF;
545 }
546 else if (exp > 29 || sig + 8 >= 32768)
547 {
548 if (!sign)
549 {
550 return 31744;
551 }
552 return 64512;
553 }
554 }
555 sig = (ushort)(sig + 8 >> 4);
556 sig &= (ushort)(~((((num ^ 8) == 0) ? 1u : 0u) & 1u));
557 if (sig == 0)
558 {
559 exp = 0;
560 }
561 return new Half(sign, (ushort)exp, sig)._value;
562 }
563
564 private static uint ShiftRightJam(uint i, int dist)
565 {
566 if (dist >= 31)
567 {
568 if (i == 0)
569 {
570 return 0u;
571 }
572 return 1u;
573 }
574 return (i >> dist) | ((i << -dist != 0) ? 1u : 0u);
575 }
576
577 private static ulong ShiftRightJam(ulong l, int dist)
578 {
579 if (dist >= 63)
580 {
581 if (l == 0L)
582 {
583 return 0uL;
584 }
585 return 1uL;
586 }
587 return (l >> dist) | (ulong)((l << -dist != 0L) ? 1 : 0);
588 }
589
590 private static float CreateSingleNaN(bool sign, ulong significand)
591 {
592 uint num = (uint)((sign ? 1 : 0) << 31);
593 uint num2 = (uint)(significand >> 41);
594 return BitConverter.UInt32BitsToSingle(num | 0x7FC00000u | num2);
595 }
596
597 private static double CreateDoubleNaN(bool sign, ulong significand)
598 {
599 ulong num = (ulong)((long)(sign ? 1 : 0) << 63);
600 ulong num2 = significand >> 12;
601 return BitConverter.UInt64BitsToDouble(num | 0x7FF8000000000000uL | num2);
602 }
603
604 private static float CreateSingle(bool sign, byte exp, uint sig)
605 {
606 return BitConverter.UInt32BitsToSingle((uint)(((sign ? 1 : 0) << 31) + (exp << 23)) + sig);
607 }
608
609 private static double CreateDouble(bool sign, ushort exp, ulong sig)
610 {
611 return BitConverter.UInt64BitsToDouble((ulong)(((long)(sign ? 1 : 0) << 63) + (long)((ulong)exp << 52)) + sig);
612 }
613
614 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
615 static Half IAdditionOperators<Half, Half, Half>.operator +(Half left, Half right)
616 {
617 return (Half)((float)left + (float)right);
618 }
619
620 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
622 {
624 uint num2 = (num >> 10) & 0x1Fu;
625 uint num3 = num & 0x3FFu;
626 if (value > PositiveZero && num2 != 0 && num2 != 31)
627 {
628 return num3 == 0;
629 }
630 return false;
631 }
632
633 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
635 {
636 return (Half)MathF.Log2((float)value);
637 }
638
639 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
640 static Half IBitwiseOperators<Half, Half, Half>.operator &(Half left, Half right)
641 {
642 ushort value = (ushort)(BitConverter.HalfToUInt16Bits(left) & BitConverter.HalfToUInt16Bits(right));
644 }
645
646 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
647 static Half IBitwiseOperators<Half, Half, Half>.operator |(Half left, Half right)
648 {
649 ushort value = (ushort)(BitConverter.HalfToUInt16Bits(left) | BitConverter.HalfToUInt16Bits(right));
651 }
652
653 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
654 static Half IBitwiseOperators<Half, Half, Half>.operator ^(Half left, Half right)
655 {
656 ushort value = (ushort)(BitConverter.HalfToUInt16Bits(left) ^ BitConverter.HalfToUInt16Bits(right));
658 }
659
660 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
662 {
663 ushort value2 = (ushort)(~BitConverter.HalfToUInt16Bits(value));
664 return BitConverter.UInt16BitsToHalf(value2);
665 }
666
667 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
668 static bool IComparisonOperators<Half, Half>.operator <(Half left, Half right)
669 {
670 return left < right;
671 }
672
673 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
674 static bool IComparisonOperators<Half, Half>.operator <=(Half left, Half right)
675 {
676 return left <= right;
677 }
678
679 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
680 static bool IComparisonOperators<Half, Half>.operator >(Half left, Half right)
681 {
682 return left > right;
683 }
684
685 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
686 static bool IComparisonOperators<Half, Half>.operator >=(Half left, Half right)
687 {
688 return left >= right;
689 }
690
691 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
693 {
694 float num = (float)value;
695 num -= 1f;
696 return (Half)num;
697 }
698
699 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
700 static bool IEqualityOperators<Half, Half>.operator ==(Half left, Half right)
701 {
702 return left == right;
703 }
704
705 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
706 static bool IEqualityOperators<Half, Half>.operator !=(Half left, Half right)
707 {
708 return left != right;
709 }
710
711 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
712 static Half IDivisionOperators<Half, Half, Half>.operator /(Half left, Half right)
713 {
714 return (Half)((float)left / (float)right);
715 }
716
717 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
719 {
720 return (Half)MathF.Acos((float)x);
721 }
722
723 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
725 {
726 return (Half)MathF.Acosh((float)x);
727 }
728
729 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
731 {
732 return (Half)MathF.Asin((float)x);
733 }
734
735 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
737 {
738 return (Half)MathF.Asinh((float)x);
739 }
740
741 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
743 {
744 return (Half)MathF.Atan((float)x);
745 }
746
747 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
749 {
750 return (Half)MathF.Atan2((float)y, (float)x);
751 }
752
753 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
755 {
756 return (Half)MathF.Atanh((float)x);
757 }
758
759 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
761 {
762 ushort num = BitConverter.HalfToUInt16Bits(x);
763 if ((num & 0x7C00) >= 31744)
764 {
765 if (num != 64512)
766 {
767 return x;
768 }
769 return MinValue;
770 }
771 if (num == 32768)
772 {
773 return Epsilon;
774 }
775 num += (ushort)((num >= 0) ? 1 : (-1));
776 return BitConverter.UInt16BitsToHalf(num);
777 }
778
779 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
781 {
782 ushort num = BitConverter.HalfToUInt16Bits(x);
783 if ((num & 0x7C00) >= 31744)
784 {
785 if (num != 31744)
786 {
787 return x;
788 }
789 return MaxValue;
790 }
791 if (num == 0)
792 {
793 return new Half(32769);
794 }
795 num += (ushort)((num < 0) ? 1 : (-1));
796 return BitConverter.UInt16BitsToHalf(num);
797 }
798
799 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
801 {
802 return (Half)MathF.Cbrt((float)x);
803 }
804
805 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
807 {
808 return (Half)MathF.Ceiling((float)x);
809 }
810
811 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
813 {
814 return (Half)MathF.CopySign((float)x, (float)y);
815 }
816
817 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
819 {
820 return (Half)MathF.Cos((float)x);
821 }
822
823 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
825 {
826 return (Half)MathF.Cosh((float)x);
827 }
828
829 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
831 {
832 return (Half)MathF.Exp((float)x);
833 }
834
835 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
837 {
838 return (Half)MathF.Floor((float)x);
839 }
840
841 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
843 {
844 return (Half)MathF.FusedMultiplyAdd((float)left, (float)right, (float)addend);
845 }
846
847 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
849 {
850 return (Half)MathF.IEEERemainder((float)left, (float)right);
851 }
852
853 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
854 static TInteger IFloatingPoint<Half>.ILogB<TInteger>(Half x)
855 {
856 return TInteger.Create(MathF.ILogB((float)x));
857 }
858
859 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
861 {
862 return (Half)MathF.Log((float)x);
863 }
864
865 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
867 {
868 return (Half)MathF.Log((float)x, (float)newBase);
869 }
870
871 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
873 {
874 return (Half)MathF.Log2((float)x);
875 }
876
877 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
879 {
880 return (Half)MathF.Log10((float)x);
881 }
882
883 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
885 {
886 return (Half)MathF.MaxMagnitude((float)x, (float)y);
887 }
888
889 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
891 {
892 return (Half)MathF.MinMagnitude((float)x, (float)y);
893 }
894
895 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
897 {
898 return (Half)MathF.Pow((float)x, (float)y);
899 }
900
901 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
903 {
904 return (Half)MathF.Round((float)x);
905 }
906
907 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
908 static Half IFloatingPoint<Half>.Round<TInteger>(Half x, TInteger digits)
909 {
910 return (Half)MathF.Round((float)x, int.Create(digits));
911 }
912
913 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
915 {
916 return (Half)MathF.Round((float)x, mode);
917 }
918
919 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
920 static Half IFloatingPoint<Half>.Round<TInteger>(Half x, TInteger digits, MidpointRounding mode)
921 {
922 return (Half)MathF.Round((float)x, int.Create(digits), mode);
923 }
924
925 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
926 static Half IFloatingPoint<Half>.ScaleB<TInteger>(Half x, TInteger n)
927 {
928 return (Half)MathF.ScaleB((float)x, int.Create(n));
929 }
930
931 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
933 {
934 return (Half)MathF.Sin((float)x);
935 }
936
937 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
939 {
940 return (Half)MathF.Sinh((float)x);
941 }
942
943 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
945 {
946 return (Half)MathF.Sqrt((float)x);
947 }
948
949 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
951 {
952 return (Half)MathF.Tan((float)x);
953 }
954
955 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
957 {
958 return (Half)MathF.Tanh((float)x);
959 }
960
961 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
963 {
964 return (Half)MathF.Truncate((float)x);
965 }
966
967 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
969 {
970 return IsFinite(x);
971 }
972
973 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
975 {
976 return IsInfinity(x);
977 }
978
979 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
981 {
982 return IsNaN(x);
983 }
984
985 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
987 {
988 return IsNegative(x);
989 }
990
991 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
993 {
994 return IsNegativeInfinity(x);
995 }
996
997 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
999 {
1000 return IsNormal(x);
1001 }
1002
1003 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1005 {
1006 return IsPositiveInfinity(x);
1007 }
1008
1009 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1011 {
1012 return IsSubnormal(x);
1013 }
1014
1015 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1017 {
1018 float num = (float)value;
1019 num += 1f;
1020 return (Half)num;
1021 }
1022
1023 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1024 static Half IModulusOperators<Half, Half, Half>.operator %(Half left, Half right)
1025 {
1026 return (Half)((float)left % (float)right);
1027 }
1028
1029 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1031 {
1032 return (Half)((float)left * (float)right);
1033 }
1034
1035 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1037 {
1038 return (Half)MathF.Abs((float)value);
1039 }
1040
1041 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1043 {
1044 return (Half)Math.Clamp((float)value, (float)min, (float)max);
1045 }
1046
1047 [MethodImpl(MethodImplOptions.AggressiveInlining)]
1048 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1049 static Half INumber<Half>.Create<TOther>(TOther value)
1050 {
1051 if (typeof(TOther) == typeof(byte))
1052 {
1053 return (Half)(int)(byte)(object)value;
1054 }
1055 if (typeof(TOther) == typeof(char))
1056 {
1057 return (Half)(int)(char)(object)value;
1058 }
1059 if (typeof(TOther) == typeof(decimal))
1060 {
1061 return (Half)(float)(decimal)(object)value;
1062 }
1063 if (typeof(TOther) == typeof(double))
1064 {
1065 return (Half)(double)(object)value;
1066 }
1067 if (typeof(TOther) == typeof(short))
1068 {
1069 return (Half)(short)(object)value;
1070 }
1071 if (typeof(TOther) == typeof(int))
1072 {
1073 return (Half)(int)(object)value;
1074 }
1075 if (typeof(TOther) == typeof(long))
1076 {
1077 return (Half)(long)(object)value;
1078 }
1079 if (typeof(TOther) == typeof(IntPtr))
1080 {
1081 return (Half)(nint)(IntPtr)(object)value;
1082 }
1083 if (typeof(TOther) == typeof(sbyte))
1084 {
1085 return (Half)(sbyte)(object)value;
1086 }
1087 if (typeof(TOther) == typeof(float))
1088 {
1089 return (Half)(float)(object)value;
1090 }
1091 if (typeof(TOther) == typeof(ushort))
1092 {
1093 return (Half)(int)(ushort)(object)value;
1094 }
1095 if (typeof(TOther) == typeof(uint))
1096 {
1097 return (Half)(uint)(object)value;
1098 }
1099 if (typeof(TOther) == typeof(ulong))
1100 {
1101 return (Half)(ulong)(object)value;
1102 }
1103 if (typeof(TOther) == typeof(UIntPtr))
1104 {
1105 return (Half)(nuint)(UIntPtr)(object)value;
1106 }
1108 return default(Half);
1109 }
1110
1111 [MethodImpl(MethodImplOptions.AggressiveInlining)]
1112 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1113 static Half INumber<Half>.CreateSaturating<TOther>(TOther value)
1114 {
1115 if (typeof(TOther) == typeof(byte))
1116 {
1117 return (Half)(int)(byte)(object)value;
1118 }
1119 if (typeof(TOther) == typeof(char))
1120 {
1121 return (Half)(int)(char)(object)value;
1122 }
1123 if (typeof(TOther) == typeof(decimal))
1124 {
1125 return (Half)(float)(decimal)(object)value;
1126 }
1127 if (typeof(TOther) == typeof(double))
1128 {
1129 return (Half)(double)(object)value;
1130 }
1131 if (typeof(TOther) == typeof(short))
1132 {
1133 return (Half)(short)(object)value;
1134 }
1135 if (typeof(TOther) == typeof(int))
1136 {
1137 return (Half)(int)(object)value;
1138 }
1139 if (typeof(TOther) == typeof(long))
1140 {
1141 return (Half)(long)(object)value;
1142 }
1143 if (typeof(TOther) == typeof(IntPtr))
1144 {
1145 return (Half)(nint)(IntPtr)(object)value;
1146 }
1147 if (typeof(TOther) == typeof(sbyte))
1148 {
1149 return (Half)(sbyte)(object)value;
1150 }
1151 if (typeof(TOther) == typeof(float))
1152 {
1153 return (Half)(float)(object)value;
1154 }
1155 if (typeof(TOther) == typeof(ushort))
1156 {
1157 return (Half)(int)(ushort)(object)value;
1158 }
1159 if (typeof(TOther) == typeof(uint))
1160 {
1161 return (Half)(uint)(object)value;
1162 }
1163 if (typeof(TOther) == typeof(ulong))
1164 {
1165 return (Half)(ulong)(object)value;
1166 }
1167 if (typeof(TOther) == typeof(UIntPtr))
1168 {
1169 return (Half)(nuint)(UIntPtr)(object)value;
1170 }
1172 return default(Half);
1173 }
1174
1175 [MethodImpl(MethodImplOptions.AggressiveInlining)]
1176 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1177 static Half INumber<Half>.CreateTruncating<TOther>(TOther value)
1178 {
1179 if (typeof(TOther) == typeof(byte))
1180 {
1181 return (Half)(int)(byte)(object)value;
1182 }
1183 if (typeof(TOther) == typeof(char))
1184 {
1185 return (Half)(int)(char)(object)value;
1186 }
1187 if (typeof(TOther) == typeof(decimal))
1188 {
1189 return (Half)(float)(decimal)(object)value;
1190 }
1191 if (typeof(TOther) == typeof(double))
1192 {
1193 return (Half)(double)(object)value;
1194 }
1195 if (typeof(TOther) == typeof(short))
1196 {
1197 return (Half)(short)(object)value;
1198 }
1199 if (typeof(TOther) == typeof(int))
1200 {
1201 return (Half)(int)(object)value;
1202 }
1203 if (typeof(TOther) == typeof(long))
1204 {
1205 return (Half)(long)(object)value;
1206 }
1207 if (typeof(TOther) == typeof(IntPtr))
1208 {
1209 return (Half)(nint)(IntPtr)(object)value;
1210 }
1211 if (typeof(TOther) == typeof(sbyte))
1212 {
1213 return (Half)(sbyte)(object)value;
1214 }
1215 if (typeof(TOther) == typeof(float))
1216 {
1217 return (Half)(float)(object)value;
1218 }
1219 if (typeof(TOther) == typeof(ushort))
1220 {
1221 return (Half)(int)(ushort)(object)value;
1222 }
1223 if (typeof(TOther) == typeof(uint))
1224 {
1225 return (Half)(uint)(object)value;
1226 }
1227 if (typeof(TOther) == typeof(ulong))
1228 {
1229 return (Half)(ulong)(object)value;
1230 }
1231 if (typeof(TOther) == typeof(UIntPtr))
1232 {
1233 return (Half)(nuint)(UIntPtr)(object)value;
1234 }
1236 return default(Half);
1237 }
1238
1239 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1240 static (Half Quotient, Half Remainder) INumber<Half>.DivRem(Half left, Half right)
1241 {
1242 return (Quotient: (Half)((float)left / (float)right), Remainder: (Half)((float)left % (float)right));
1243 }
1244
1245 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1247 {
1248 return (Half)MathF.Max((float)x, (float)y);
1249 }
1250
1251 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1253 {
1254 return (Half)MathF.Min((float)x, (float)y);
1255 }
1256
1257 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1258 static Half INumber<Half>.Parse(string s, NumberStyles style, IFormatProvider provider)
1259 {
1260 return Parse(s, style, provider);
1261 }
1262
1263 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1265 {
1266 return Parse(s, style, provider);
1267 }
1268
1269 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1271 {
1272 return (Half)MathF.Sign((float)value);
1273 }
1274
1275 [MethodImpl(MethodImplOptions.AggressiveInlining)]
1276 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1277 static bool INumber<Half>.TryCreate<TOther>(TOther value, out Half result)
1278 {
1279 if (typeof(TOther) == typeof(byte))
1280 {
1281 result = (Half)(int)(byte)(object)value;
1282 return true;
1283 }
1284 if (typeof(TOther) == typeof(char))
1285 {
1286 result = (Half)(int)(char)(object)value;
1287 return true;
1288 }
1289 if (typeof(TOther) == typeof(decimal))
1290 {
1291 result = (Half)(float)(decimal)(object)value;
1292 return true;
1293 }
1294 if (typeof(TOther) == typeof(double))
1295 {
1296 result = (Half)(double)(object)value;
1297 return true;
1298 }
1299 if (typeof(TOther) == typeof(short))
1300 {
1301 result = (Half)(short)(object)value;
1302 return true;
1303 }
1304 if (typeof(TOther) == typeof(int))
1305 {
1306 result = (Half)(int)(object)value;
1307 return true;
1308 }
1309 if (typeof(TOther) == typeof(long))
1310 {
1311 result = (Half)(long)(object)value;
1312 return true;
1313 }
1314 if (typeof(TOther) == typeof(IntPtr))
1315 {
1316 result = (Half)(nint)(IntPtr)(object)value;
1317 return true;
1318 }
1319 if (typeof(TOther) == typeof(sbyte))
1320 {
1321 result = (Half)(sbyte)(object)value;
1322 return true;
1323 }
1324 if (typeof(TOther) == typeof(float))
1325 {
1326 result = (Half)(float)(object)value;
1327 return true;
1328 }
1329 if (typeof(TOther) == typeof(ushort))
1330 {
1331 result = (Half)(int)(ushort)(object)value;
1332 return true;
1333 }
1334 if (typeof(TOther) == typeof(uint))
1335 {
1336 result = (Half)(uint)(object)value;
1337 return true;
1338 }
1339 if (typeof(TOther) == typeof(ulong))
1340 {
1341 result = (Half)(ulong)(object)value;
1342 return true;
1343 }
1344 if (typeof(TOther) == typeof(UIntPtr))
1345 {
1346 result = (Half)(nuint)(UIntPtr)(object)value;
1347 return true;
1348 }
1350 result = default(Half);
1351 return false;
1352 }
1353
1354 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1355 static bool INumber<Half>.TryParse([NotNullWhen(true)] string s, NumberStyles style, IFormatProvider provider, out Half result)
1356 {
1357 return TryParse(s, style, provider, out result);
1358 }
1359
1360 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1362 {
1363 return TryParse(s, style, provider, out result);
1364 }
1365
1366 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1368 {
1369 return Parse(s, provider);
1370 }
1371
1372 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1373 static bool IParseable<Half>.TryParse([NotNullWhen(true)] string s, IFormatProvider provider, out Half result)
1374 {
1375 return TryParse(s, NumberStyles.Float | NumberStyles.AllowThousands, provider, out result);
1376 }
1377
1378 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1380 {
1381 return Parse(s, NumberStyles.Float | NumberStyles.AllowThousands, provider);
1382 }
1383
1384 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1386 {
1387 return TryParse(s, NumberStyles.Float | NumberStyles.AllowThousands, provider, out result);
1388 }
1389
1390 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1392 {
1393 return (Half)((float)left - (float)right);
1394 }
1395
1396 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1398 {
1399 return (Half)(0f - (float)value);
1400 }
1401
1402 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
1404 {
1405 return value;
1406 }
1407}
static Half UInt16BitsToHalf(ushort value)
static ushort HalfToUInt16Bits(Half value)
static ulong DoubleToUInt64Bits(double value)
static double UInt64BitsToDouble(ulong value)
static uint SingleToUInt32Bits(float value)
static float UInt32BitsToSingle(uint value)
static NumberFormatInfo GetInstance(IFormatProvider? formatProvider)
static void ValidateParseStyleFloatingPoint(NumberStyles style)
static float Abs(float x)
Definition MathF.cs:130
static float Log(float x)
static unsafe float Truncate(float x)
Definition MathF.cs:413
static int Sign(float x)
Definition MathF.cs:408
static float MinMagnitude(float x, float y)
Definition MathF.cs:280
static float ScaleB(float x, int n)
Definition MathF.cs:419
static float Log2(float x)
static float Max(float x, float y)
Definition MathF.cs:250
static float Atan(float x)
static float Acosh(float x)
static float FusedMultiplyAdd(float x, float y, float z)
static float Atan2(float y, float x)
static float Sqrt(float x)
static float MaxMagnitude(float x, float y)
Definition MathF.cs:255
static float Pow(float x, float y)
static float Min(float x, float y)
Definition MathF.cs:275
static float Log10(float x)
static float Asinh(float x)
static float Acos(float x)
static float Cos(float x)
static float Sinh(float x)
static float Asin(float x)
static float Atanh(float x)
static float Cbrt(float x)
static float Cosh(float x)
static float IEEERemainder(float x, float y)
Definition MathF.cs:191
static float CopySign(float x, float y)
Definition MathF.cs:174
static float Ceiling(float x)
static float Sin(float x)
static float Floor(float x)
static float Exp(float x)
static float Tan(float x)
static float Tanh(float x)
static int ILogB(float x)
static float Round(float x)
Definition MathF.cs:326
static byte Clamp(byte value, byte min, byte max)
Definition Math.cs:435
const double E
Definition Math.cs:14
const double PI
Definition Math.cs:16
static string FormatHalf(Half value, string format, NumberFormatInfo info)
Definition Number.cs:1803
static Half ParseHalf(ReadOnlySpan< char > value, NumberStyles styles, NumberFormatInfo info)
Definition Number.cs:5631
static bool TryFormatHalf(Half value, ReadOnlySpan< char > format, NumberFormatInfo info, Span< char > destination, out int charsWritten)
Definition Number.cs:1854
static unsafe bool TryParseHalf(ReadOnlySpan< char > value, NumberStyles styles, NumberFormatInfo info, out Half result)
Definition Number.cs:5718
static int LeadingZeroCount(uint value)
static string Arg_MustBeHalf
Definition SR.cs:2176
Definition SR.cs:7
static void ThrowNotSupportedException(ExceptionResource resource)
static void ThrowArgumentNullException(string name)
static TResult AdditiveIdentity
static bool IsPow2(TSelf value)
static TSelf Log2(TSelf value)
static bool IsNaN(TSelf value)
static TSelf CopySign(TSelf x, TSelf y)
static bool IsPositiveInfinity(TSelf value)
static TSelf Acosh(TSelf x)
static TSelf MinMagnitude(TSelf x, TSelf y)
static TSelf Log10(TSelf x)
static TSelf Ceiling(TSelf x)
static bool IsFinite(TSelf value)
static bool IsNegativeInfinity(TSelf value)
static TSelf MaxMagnitude(TSelf x, TSelf y)
static TSelf PositiveInfinity
static TSelf IEEERemainder(TSelf left, TSelf right)
static TSelf Pow(TSelf x, TSelf y)
static TSelf Asin(TSelf x)
static TSelf Floor(TSelf x)
static TSelf Truncate(TSelf x)
static TSelf Asinh(TSelf x)
static TSelf Atanh(TSelf x)
static TSelf NegativeZero
static TSelf Log(TSelf x)
static TSelf Cbrt(TSelf x)
static TSelf BitIncrement(TSelf x)
static TSelf Tan(TSelf x)
static TSelf Sinh(TSelf x)
static bool IsInfinity(TSelf value)
static bool IsSubnormal(TSelf value)
static TSelf Tanh(TSelf x)
static TSelf Exp(TSelf x)
static bool IsNegative(TSelf value)
static TSelf Atan(TSelf x)
static TSelf Sqrt(TSelf x)
static TSelf BitDecrement(TSelf x)
static TSelf FusedMultiplyAdd(TSelf left, TSelf right, TSelf addend)
static TSelf Sin(TSelf x)
static TSelf Acos(TSelf x)
static TSelf Round(TSelf x)
static bool IsNormal(TSelf value)
static TSelf Atan2(TSelf y, TSelf x)
static TSelf Cos(TSelf x)
static TSelf Cosh(TSelf x)
static TSelf NegativeInfinity
static TSelf Log2(TSelf x)
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)
static Half NaN
Definition Half.cs:23
static bool IsNaNOrZero(Half value)
Definition Half.cs:291
static bool TryParse(ReadOnlySpan< char > s, out Half result)
Definition Half.cs:264
static Half NegativeInfinity
Definition Half.cs:21
static bool IsPositiveInfinity(Half value)
Definition Half.cs:195
static Half MaxValue
Definition Half.cs:27
static bool IsNaN(Half value)
Definition Half.cs:170
static Half Quotient
Definition Half.cs:1240
static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out Half result)
Definition Half.cs:269
static ushort RoundPackToHalf(bool sign, short exp, ushort sig)
Definition Half.cs:535
static Half Parse(string s, IFormatProvider? provider)
Definition Half.cs:229
static float CreateSingle(bool sign, byte exp, uint sig)
Definition Half.cs:604
static Half Parse(string s)
Definition Half.cs:210
static Half Negate(Half value)
Definition Half.cs:513
static bool operator>=(Half left, Half right)
Definition Half.cs:137
static readonly Half NegativeZero
Definition Half.cs:13
bool TryFormat(Span< char > destination, out int charsWritten, ReadOnlySpan< char > format=default(ReadOnlySpan< char >), IFormatProvider? provider=null)
Definition Half.cs:390
static Half MinValue
Definition Half.cs:25
static Half Parse(string s, NumberStyles style)
Definition Half.cs:219
static bool TryParse(ReadOnlySpan< char > s, NumberStyles style, IFormatProvider? provider, out Half result)
Definition Half.cs:280
static bool IsNegative(Half value)
Definition Half.cs:175
static bool IsSubnormal(Half value)
Definition Half.cs:200
static Half Parse(ReadOnlySpan< char > s, NumberStyles style=NumberStyles.Float|NumberStyles.AllowThousands, IFormatProvider? provider=null)
Definition Half.cs:248
override bool Equals([NotNullWhen(true)] object? obj)
Definition Half.cs:339
static bool operator>(Half left, Half right)
Definition Half.cs:110
static bool operator==(Half left, Half right)
Definition Half.cs:142
static Half IFloatingPoint< Half >. PositiveInfinity
Definition Half.cs:55
static Half PositiveInfinity
Definition Half.cs:19
static bool TryParse([NotNullWhen(true)] string? s, out Half result)
Definition Half.cs:254
static readonly Half PositiveZero
Definition Half.cs:11
override int GetHashCode()
Definition Half.cs:361
static Half Epsilon
Definition Half.cs:17
static Half IFloatingPoint< Half >. NaN
Definition Half.cs:43
static Half Half Remainder INumber< Half >. DivRem(Half left, Half right)
Definition Half.cs:1240
static Half IFloatingPoint< Half >. NegativeInfinity
Definition Half.cs:46
string ToString(IFormatProvider? provider)
Definition Half.cs:380
Half(bool sign, ushort exp, ushort sig)
Definition Half.cs:83
static bool operator<=(Half left, Half right)
Definition Half.cs:115
static ulong ShiftRightJam(ulong l, int dist)
Definition Half.cs:577
static bool IsFinite(Half value)
Definition Half.cs:160
static uint ShiftRightJam(uint i, int dist)
Definition Half.cs:564
static bool IsNormal(Half value)
Definition Half.cs:185
static float CreateSingleNaN(bool sign, ulong significand)
Definition Half.cs:590
static double CreateDouble(bool sign, ushort exp, ulong sig)
Definition Half.cs:609
Half(ushort value)
Definition Half.cs:78
static int Exp
Definition Half.cs:522
string ToString(string? format)
Definition Half.cs:375
static Half CreateHalfNaN(bool sign, ulong significand)
Definition Half.cs:528
static Half IMinMaxValue< Half >. MinValue
Definition Half.cs:61
int CompareTo(object? obj)
Definition Half.cs:301
bool Equals(Half other)
Definition Half.cs:348
int CompareTo(Half other)
Definition Half.cs:314
static double CreateDoubleNaN(bool sign, ulong significand)
Definition Half.cs:597
static bool IsInfinity(Half value)
Definition Half.cs:165
static int uint Sig NormSubnormalF16Sig(uint sig)
Definition Half.cs:522
static Half IFloatingPoint< Half >. NegativeZero
Definition Half.cs:49
static bool operator<(Half left, Half right)
Definition Half.cs:88
static Half IFloatingPoint< Half >. Epsilon
Definition Half.cs:40
ushort Significand
Definition Half.cs:31
static uint StripSign(Half value)
Definition Half.cs:296
readonly ushort _value
Definition Half.cs:15
static Half IMinMaxValue< Half >. MaxValue
Definition Half.cs:64
sbyte Exponent
Definition Half.cs:29
static Half Parse(string s, NumberStyles style=NumberStyles.Float|NumberStyles.AllowThousands, IFormatProvider? provider=null)
Definition Half.cs:238
override string ToString()
Definition Half.cs:370
string ToString(string? format, IFormatProvider? provider)
Definition Half.cs:385
static bool AreZero(Half left, Half right)
Definition Half.cs:286
static bool IsNegativeInfinity(Half value)
Definition Half.cs:180
static bool operator!=(Half left, Half right)
Definition Half.cs:155