[interp] Fix interp logging (#17636)
[mono-project.git] / mono / mini / builtin-types.cs
blobb927c403a530039b2ff387cd6ec8a14e7980ceaa
1 // #define ARCH_32
3 /* This is _NOT_ set by Xamarin.iOS. We can enable it in order to make sure
4 * methods are intrinsified (by throwing NotImplementedException), but some
5 * methods aren't intrinsified by JIT/interp. For example, conversion to
6 * decimal. Therefore JIT/interp should fall back to managed implementation.
7 */
8 // #define NINT_JIT_OPTIMIZED
10 using System;
11 using System.Diagnostics;
12 using System.Globalization;
13 using System.Runtime.CompilerServices;
14 using System.Runtime.InteropServices;
15 using System.Collections.Generic;
18 public class BuiltinTests {
19 static int test_0_nint_ctor ()
21 var x = new nint (10);
22 var y = new nint (x);
23 var z = new nint (new nint (20));
24 if ((int)x != 10)
25 return 1;
26 if ((int)y != 10)
27 return 2;
28 if ((int)z != 20)
29 return 3;
30 return 0;
33 static int test_0_nint_casts ()
35 var x = (nint)10;
36 var y = (nint)20L;
37 int z = 30;
39 if ((int)x != 10)
40 return 1;
41 if ((long)x != 10L)
42 return 2;
43 if ((int)y != 20)
44 return 3;
45 if ((long)y != 20L)
46 return 4;
47 if ((nint)z != 30)
48 return 5;
49 return 0;
52 static int test_0_nint_plus ()
54 var x = (nint)10;
55 var z = +x;
56 if ((int)z != 10)
57 return 1;
58 return 0;
61 static int test_0_nint_neg ()
63 var x = (nint)10;
64 var z = -x;
65 if ((int)z != -10)
66 return 1;
67 return 0;
70 static int test_0_nint_comp ()
72 var x = (nint)10;
73 var z = ~x;
74 if ((int)z != ~10)
75 return 1;
76 return 0;
79 static int test_0_nint_inc ()
81 var x = (nint)10;
82 ++x;
83 if ((int)x != 11)
84 return 1;
85 return 0;
88 static int test_0_nint_dec ()
90 var x = (nint)10;
91 --x;
92 if ((int)x != 9)
93 return 1;
94 return 0;
97 static int test_0_nint_add ()
99 var x = (nint)10;
100 var y = (nint)20;
101 var z = x + y;
102 if ((int)z != 30)
103 return 1;
104 return 0;
107 static int test_0_nint_sub ()
109 var x = (nint)10;
110 var y = (nint)20;
111 var z = x - y;
112 if ((int)z != -10)
113 return 1;
114 return 0;
117 static int test_0_nint_mul ()
119 var x = (nint)10;
120 var y = (nint)20;
121 var z = x * y;
122 if ((int)z != 200)
123 return 1;
124 return 0;
127 static int test_0_nint_div ()
129 var x = (nint)30;
130 var y = (nint)3;
131 var z = x / y;
132 if ((int)z != 10)
133 return 1;
134 return 0;
137 static int test_0_nint_rem ()
139 var x = (nint)22;
140 var y = (nint)10;
141 var z = x % y;
142 if ((int)z != 2)
143 return 1;
144 return 0;
147 static int test_0_nint_and ()
149 var x = (nint)0x30;
150 var y = (nint)0x11;
151 var z = x & y;
152 if ((int)z != 0x10)
153 return 1;
154 return 0;
157 static int test_0_nint_or ()
159 var x = (nint)0x0F;
160 var y = (nint)0xF0;
161 var z = x | y;
162 if ((int)z != 0xFF)
163 return 1;
164 return 0;
167 static int test_0_nint_xor ()
169 var x = (nint)0xFF;
170 var y = (nint)0xF0;
171 var z = x ^ y;
172 if ((int)z != 0x0F)
173 return 1;
174 return 0;
177 static int test_0_nint_shl ()
179 var x = (nint)10;
180 var z = x << 2;
181 if ((int)z != 40)
182 return 1;
183 return 0;
186 static int test_0_nint_shr ()
188 var x = (nint)10;
189 var z = x >> 2;
190 if ((int)z != 2)
191 return 1;
192 return 0;
195 static int test_0_nint_cmp_same_val ()
197 var x = (nint)10;
198 var y = (nint)10;
199 if (!(x == y))
200 return 1;
201 if (x != y)
202 return 2;
203 if (x < y)
204 return 3;
205 if (x > y)
206 return 4;
207 if (!(x <= y))
208 return 5;
209 if (!(x >= y))
210 return 6;
211 return 0;
214 static int test_0_nint_cmp_small_val ()
216 var x = (nint)5;
217 var y = (nint)10;
218 if (x == y)
219 return 1;
220 if (!(x != y))
221 return 2;
222 if (!(x < y))
223 return 3;
224 if (x > y)
225 return 4;
226 if (!(x <= y))
227 return 5;
228 if (x >= y)
229 return 6;
230 return 0;
233 static int test_0_nint_cmp_large_val ()
235 var x = (nint)20;
236 var y = (nint)10;
237 if (x == y)
238 return 1;
239 if (!(x != y))
240 return 2;
241 if (x < y)
242 return 3;
243 if (!(x > y))
244 return 4;
245 if (x <= y)
246 return 1;
247 if (!(x >= y))
248 return 1;
249 return 0;
252 static int test_0_nint_compareto ()
254 if (((nint) 0).CompareTo ((nint) 0) != 0)
255 return 1;
256 if (((nint) 0).CompareTo ((nint) 1) != -1)
257 return 2;
258 if (((nint) 1).CompareTo ((nint) 0) != 1)
259 return 3;
261 if (((nint) 0).CompareTo ((object)(nint) 0) != 0)
262 return 4;
263 if (((nint) 0).CompareTo ((object)(nint) 1) != -1)
264 return 5;
265 if (((nint) 1).CompareTo ((object)(nint) 0) != 1)
266 return 6;
268 if (((nint) 1).CompareTo (null) != 1)
269 return 7;
271 return 0;
274 static int test_0_nint_call_boxed_equals ()
276 object x = new nint (10);
277 object y = new nint (10);
278 if (!x.Equals (y))
279 return 1;
280 return 0;
283 static int test_0_nint_equals ()
285 if (!((nint) 0).Equals ((nint) 0))
286 return 1;
287 if (!((nint) 0).Equals ((object) (nint) 0))
288 return 2;
289 if (((nint) 0).Equals (null))
290 return 3;
291 return 0;
294 private sealed class MyGenericEqualityComparer<T> : EqualityComparer<T> where T : IEquatable<T>
296 public sealed override bool Equals(T x, T y) {
297 if (x != null) {
298 if (y != null)
299 return x.Equals (y);
300 return false;
302 if (y != null)
303 return false;
304 return true;
307 public sealed override int GetHashCode(T obj)
309 if (obj == null)
310 return 0;
311 return obj.GetHashCode ();
315 static int test_0_nint_genequals ()
317 MyGenericEqualityComparer<nint> cmp = new MyGenericEqualityComparer<nint> ();
318 if (cmp.Equals ((nint) 1, (nint) 2))
319 return 1;
320 if (!cmp.Equals ((nint) 4, (nint) 4))
321 return 2;
322 return 0;
325 static int test_0_nint_call_boxed_funs ()
327 object x = new nint (10);
328 object y = new nint (10);
329 if (x.GetHashCode () == 0)
330 return 2;
331 if (x.ToString () != "10")
332 return 3;
333 return 0;
336 static int test_0_nint_tostring ()
338 int x = 1337;
339 if (((nint) x).ToString () != "1337")
340 return 1;
341 x = -1337;
342 if (((nint) x).ToString () != "-1337")
343 return 2;
345 return 0;
348 [MethodImplAttribute (MethodImplOptions.NoInlining)]
349 static bool decimal_cmp (decimal a, decimal b)
351 return a == b;
354 static bool decimal_cmp_can_inline (decimal a, decimal b)
356 return a == b;
359 static int test_0_nint_implicit_decimal ()
361 nint a = new nint (10);
362 nint b = new nint (9);
363 if (decimal_cmp (a, b))
364 return 1;
365 b++;
366 if (!decimal_cmp (a, b))
367 return 2;
368 if (!decimal_cmp ((nint) 10, b))
369 return 3;
370 if (!decimal_cmp (a, (nint) 10))
371 return 4;
372 return 0;
375 static int test_0_nint_unboxed_member_calls ()
377 var x = (nint)10;
378 #if FALSE
379 if (!x.Equals (x))
380 return 1;
381 #endif
382 if (x != nint.Parse ("10"))
383 return 2;
384 return 0;
387 struct SomeNativeStructWithNint {
388 public nint a;
389 public static nint b;
391 public SomeNativeStructWithNint (nint a)
393 this.a = a;
394 b = a + 1;
397 public static nint GetAStatic (SomeNativeStructWithNint x)
399 return x.a;
402 public nint GetA ()
404 return a;
408 class SomeClassWithNint {
409 public nint a;
411 public SomeClassWithNint (nint a)
413 this.a = a;
416 public virtual nint GetAVirtual ()
418 return a;
422 static int test_0_nint_fieldload ()
424 var x = new SomeNativeStructWithNint ((nint) 20f);
426 if ((float) x.a != 20f)
427 return 1;
429 if ((int) x.a != 20)
430 return 2;
432 if ((float) SomeNativeStructWithNint.GetAStatic (x) != 20f)
433 return 3;
435 if ((float) x.GetA () != 20f)
436 return 4;
438 if ((int) SomeNativeStructWithNint.GetAStatic (x) != 20)
439 return 5;
441 if ((int) x.GetA () != 20)
442 return 6;
444 if ((float) SomeNativeStructWithNint.b != 21f)
445 return 7;
447 if ((int) SomeNativeStructWithNint.b != 21)
448 return 8;
450 SomeClassWithNint y = new SomeClassWithNint ((nint) 30f);
452 if ((int) y.GetAVirtual () != 30)
453 return 9;
455 if ((float) y.GetAVirtual () != 30f)
456 return 10;
458 return 0;
461 static int NuintConstructor (nuint cap)
463 if (cap > (ulong) nint.MaxValue)
464 return 1;
465 return 0;
468 /* resembles https://github.com/xamarin/xamarin-macios/blob/bc492585d137d8c3d3a2ffc827db3cdaae3cc869/tests/monotouch-test/Foundation/MutableDataTest.cs#L62-L89 */
469 static int test_0_nint_maxintcmp ()
471 /* does not work on 32bit */
472 if (IntPtr.Size == 4)
473 return 0;
475 uint cap = (uint) Int32.MaxValue + 2;
476 return NuintConstructor (cap);
480 static int test_0_nuint_ctor ()
482 var x = new nuint (10u);
483 var y = new nuint (x);
484 var z = new nuint (new nuint (20u));
485 if ((uint)x != 10)
486 return 1;
487 if ((uint)y != 10)
488 return 2;
489 if ((uint)z != 20)
490 return 3;
491 return 0;
494 static int test_0_nuint_casts ()
496 var x = (nuint)10;
497 var y = (nuint)20L;
498 int z = 30;
500 if ((uint)x != 10)
501 return 1;
502 if ((ulong)x != 10L)
503 return 2;
504 if ((uint)y != 20)
505 return 3;
506 if ((ulong)y != 20L)
507 return 4;
508 if ((nuint)z != 30)
509 return 5;
510 return 0;
513 static int test_0_nuint_plus ()
515 var x = (nuint)10;
516 var z = +x;
517 if ((uint)z != 10)
518 return 1;
519 return 0;
522 // static int test_0_nuint_neg ()
523 // {
524 // var x = (nuint)10;
525 // var z = -x;
526 // if ((uint)z != -10)
527 // return 1;
528 // return 0;
529 // }
531 static int test_0_nuint_comp ()
533 var x = (nuint)10;
534 var z = ~x;
535 if ((uint)z != ~10u)
536 return 1;
537 return 0;
540 static int test_0_nuint_inc ()
542 var x = (nuint)10;
543 ++x;
544 if ((uint)x != 11)
545 return 1;
546 return 0;
549 static int test_0_nuint_dec ()
551 var x = (nuint)10;
552 --x;
553 if ((uint)x != 9)
554 return 1;
555 return 0;
558 static int test_0_nuint_add ()
560 var x = (nuint)10;
561 var y = (nuint)20;
562 var z = x + y;
563 if ((uint)z != 30)
564 return 1;
565 return 0;
568 static int test_0_nuint_sub ()
570 var x = (nuint)20;
571 var y = (nuint)5;
572 var z = x - y;
573 if ((uint)z != 15)
574 return 1;
575 return 0;
578 static int test_0_nuint_mul ()
580 var x = (nuint)10;
581 var y = (nuint)20;
582 var z = x * y;
583 if ((uint)z != 200)
584 return 1;
585 return 0;
588 static int test_0_nuint_div ()
590 var x = (nuint)30;
591 var y = (nuint)3;
592 var z = x / y;
593 if ((uint)z != 10)
594 return 1;
595 return 0;
598 static int test_0_nuint_rem ()
600 var x = (nuint)22;
601 var y = (nuint)10;
602 var z = x % y;
603 if ((uint)z != 2)
604 return 1;
605 return 0;
608 static int test_0_nuint_and ()
610 var x = (nuint)0x30;
611 var y = (nuint)0x11;
612 var z = x & y;
613 if ((uint)z != 0x10)
614 return 1;
615 return 0;
618 static int test_0_nuint_or ()
620 var x = (nuint)0x0F;
621 var y = (nuint)0xF0;
622 var z = x | y;
623 if ((uint)z != 0xFF)
624 return 1;
625 return 0;
628 static int test_0_nuint_xor ()
630 var x = (nuint)0xFF;
631 var y = (nuint)0xF0;
632 var z = x ^ y;
633 if ((uint)z != 0x0F)
634 return 1;
635 return 0;
638 static int test_0_nuint_shl ()
640 var x = (nuint)10;
641 var z = x << 2;
642 if ((uint)z != 40)
643 return 1;
644 return 0;
647 static int test_0_nuint_shr ()
649 var x = (nuint)10;
650 var z = x >> 2;
651 if ((uint)z != 2)
652 return 1;
653 return 0;
656 static int test_0_nuint_cmp_same_val ()
658 var x = (nuint)10;
659 var y = (nuint)10;
660 if (!(x == y))
661 return 1;
662 if (x != y)
663 return 2;
664 if (x < y)
665 return 3;
666 if (x > y)
667 return 4;
668 if (!(x <= y))
669 return 5;
670 if (!(x >= y))
671 return 6;
672 return 0;
675 static int test_0_nuint_cmp_small_val ()
677 var x = (nuint)5;
678 var y = (nuint)10;
679 if (x == y)
680 return 1;
681 if (!(x != y))
682 return 2;
683 if (!(x < y))
684 return 3;
685 if (x > y)
686 return 4;
687 if (!(x <= y))
688 return 5;
689 if (x >= y)
690 return 6;
691 return 0;
694 static int test_0_nuint_cmp_large_val ()
696 var x = (nuint)20;
697 var y = (nuint)10;
698 if (x == y)
699 return 1;
700 if (!(x != y))
701 return 2;
702 if (x < y)
703 return 3;
704 if (!(x > y))
705 return 4;
706 if (x <= y)
707 return 1;
708 if (!(x >= y))
709 return 1;
710 return 0;
713 static int test_0_nuint_compareto ()
715 if (((nuint) 0).CompareTo ((nuint) 0) != 0)
716 return 1;
717 if (((nuint) 0).CompareTo ((nuint) 1) != -1)
718 return 2;
719 if (((nuint) 1).CompareTo ((nuint) 0) != 1)
720 return 3;
722 if (((nuint) 0).CompareTo ((object)(nuint) 0) != 0)
723 return 4;
724 if (((nuint) 0).CompareTo ((object)(nuint) 1) != -1)
725 return 5;
726 if (((nuint) 1).CompareTo ((object)(nuint) 0) != 1)
727 return 6;
729 if (((nuint) 1).CompareTo (null) != 1)
730 return 7;
732 return 0;
735 static int test_0_nuint_call_boxed_equals ()
737 object x = new nuint (10);
738 object y = new nuint (10);
739 if (!x.Equals (y))
740 return 1;
741 return 0;
744 static int test_0_nuint_equals ()
746 if (!((nuint) 0).Equals ((nuint) 0))
747 return 1;
748 if (!((nuint) 0).Equals ((object) (nuint) 0))
749 return 2;
750 if (((nuint) 0).Equals (null))
751 return 3;
752 return 0;
755 static int test_0_nuint_call_boxed_funs ()
757 object x = new nuint (10u);
758 object y = new nuint (10u);
759 if (x.GetHashCode () == 0)
760 return 2;
761 if (x.ToString () != "10")
762 return 3;
763 return 0;
766 static int test_0_nuint_tostring ()
768 int x = 1337;
769 if (((nuint) x).ToString () != "1337")
770 return 1;
771 x = -1337;
772 if (((nuint) x).ToString () == "-1337")
773 return 2;
775 return 0;
778 static int test_0_nuint_implicit_decimal ()
780 nuint a = new nuint (10);
781 nuint b = new nuint (9);
782 if (decimal_cmp (a, b))
783 return 1;
784 b++;
785 if (!decimal_cmp (a, b))
786 return 2;
787 if (!decimal_cmp ((nuint) 10, b))
788 return 3;
789 if (!decimal_cmp (a, (nuint) 10))
790 return 4;
791 return 0;
794 static int test_0_nuint_unboxed_member_calls ()
796 var x = (nuint)10;
797 #if FALSE
798 if (!x.Equals (x))
799 return 1;
800 #endif
801 if (x != nuint.Parse ("10"))
802 return 2;
803 return 0;
806 struct SomeNativeStructWithNuint {
807 public nuint a;
808 public static nuint b;
810 public SomeNativeStructWithNuint (nuint a)
812 this.a = a;
813 b = a + 1;
816 public static nuint GetAStatic (SomeNativeStructWithNuint x)
818 return x.a;
821 public nuint GetA ()
823 return a;
827 class SomeClassWithNuint {
828 public nuint a;
830 public SomeClassWithNuint (nuint a)
832 this.a = a;
835 public virtual nuint GetAVirtual ()
837 return a;
841 static int test_0_nuint_fieldload ()
843 var x = new SomeNativeStructWithNuint ((nuint) 20f);
845 if ((float) x.a != 20f)
846 return 1;
848 if ((int) x.a != 20)
849 return 2;
851 if ((float) SomeNativeStructWithNuint.GetAStatic (x) != 20f)
852 return 3;
854 if ((float) x.GetA () != 20f)
855 return 4;
857 if ((int) SomeNativeStructWithNuint.GetAStatic (x) != 20)
858 return 5;
860 if ((int) x.GetA () != 20)
861 return 6;
863 if (!decimal_cmp_can_inline ((int) x.GetA (), 20))
864 return 66;
866 if ((float) SomeNativeStructWithNuint.b != 21f)
867 return 7;
869 if ((int) SomeNativeStructWithNuint.b != 21)
870 return 8;
872 SomeClassWithNuint y = new SomeClassWithNuint ((nuint) 30f);
874 if ((int) y.GetAVirtual () != 30)
875 return 9;
877 if ((float) y.GetAVirtual () != 30f)
878 return 10;
880 return 0;
883 static int test_0_nfloat_ctor ()
885 var x = new nfloat (10.0f);
886 var y = new nfloat (x);
887 var z = new nfloat (new nfloat (20f));
888 if ((float)x != 10f)
889 return 1;
890 if ((float)y != 10f)
891 return 2;
892 if ((float)z != 20f)
893 return 3;
894 return 0;
897 static int test_0_nfloat_casts ()
899 var x = (nfloat)10f;
901 if ((float)x != 10f)
902 return 1;
903 if ((double)x != 10)
904 return 2;
905 #if FALSE
906 var y = (nfloat)20;
907 if ((float)y != 20f)
908 return 3;
909 if ((double)y != 20)
910 return 4;
911 #endif
912 int z = 30;
913 if ((nfloat) z != 30f)
914 return 5;
916 if ((int) x != 10)
917 return 6;
918 return 0;
921 static int test_0_nfloat_plus ()
923 var x = (nfloat)10f;
924 var z = +x;
925 if ((float)z != 10f)
926 return 1;
927 return 0;
930 static int test_0_nfloat_neg ()
932 var x = (nfloat)10f;
933 var z = -x;
934 if ((float)z != -10f)
935 return 1;
936 return 0;
939 #if FALSE
940 static int test_0_nfloat_inc ()
942 var x = (nfloat)10f;
943 ++x;
944 if ((float)x != 11f) {
945 Console.WriteLine ((float)x);
946 return 1;
948 return 0;
951 static int test_0_nfloat_dec ()
953 var x = (nfloat)10f;
954 --x;
955 if ((float)x != 9f) {
956 Console.WriteLine ((float)x);
957 return 1;
959 return 0;
961 #endif
963 static int test_0_nfloat_add ()
965 var x = (nfloat)10f;
966 var y = (nfloat)20f;
967 var z = x + y;
968 if ((float)z != 30f)
969 return 1;
970 return 0;
973 static int test_0_nfloat_sub ()
975 var x = (nfloat)10f;
976 var y = (nfloat)20f;
977 var z = x - y;
978 if ((float)z != -10f)
979 return 1;
980 return 0;
983 static int test_0_nfloat_mul ()
985 var x = (nfloat)10f;
986 var y = (nfloat)20f;
987 var z = x * y;
988 if ((float)z != 200f)
989 return 1;
990 return 0;
993 static int test_0_nfloat_div ()
995 var x = (nfloat)30f;
996 var y = (nfloat)3f;
997 var z = x / y;
998 if ((float)z != 10f)
999 return 1;
1000 return 0;
1003 static int test_0_nfloat_rem ()
1005 var x = (nfloat)22f;
1006 var y = (nfloat)10f;
1007 var z = x % y;
1008 if ((float)z != 2f)
1009 return 1;
1010 return 0;
1013 static int test_0_nfloat_cmp_same_val ()
1015 var x = (nfloat)10f;
1016 var y = (nfloat)10f;
1017 if (!(x == y))
1018 return 1;
1019 if (x != y)
1020 return 2;
1021 if (x < y)
1022 return 3;
1023 if (x > y)
1024 return 4;
1025 if (!(x <= y))
1026 return 5;
1027 if (!(x >= y))
1028 return 6;
1029 return 0;
1032 static int test_0_nfloat_cmp_small_val ()
1034 var x = (nfloat)5f;
1035 var y = (nfloat)10f;
1036 if (x == y)
1037 return 1;
1038 if (!(x != y))
1039 return 2;
1040 if (!(x < y))
1041 return 3;
1042 if (x > y)
1043 return 4;
1044 if (!(x <= y))
1045 return 5;
1046 if (x >= y)
1047 return 6;
1048 return 0;
1051 static int test_0_nfloat_cmp_large_val ()
1053 var x = (nfloat)20f;
1054 var y = (nfloat)10f;
1055 if (x == y)
1056 return 1;
1057 if (!(x != y))
1058 return 2;
1059 if (x < y)
1060 return 3;
1061 if (!(x > y))
1062 return 4;
1063 if (x <= y)
1064 return 1;
1065 if (!(x >= y))
1066 return 1;
1067 return 0;
1070 /* fails on arm64 */
1071 static int test_0_nfloat_cmp_left_nan ()
1073 var x = (nfloat)float.NaN;
1074 var y = (nfloat)10f;
1075 if (x == y)
1076 return 1;
1077 if (!(x != y))
1078 return 2;
1079 if (x < y)
1080 return 3;
1081 if (x > y)
1082 return 4;
1083 if (x <= y)
1084 return 5;
1085 if (x >= y)
1086 return 6;
1087 return 0;
1091 static int test_0_nfloat_cmp_right_nan ()
1093 var x = (nfloat)10f;
1094 var y = (nfloat)float.NaN;
1095 if (x == y)
1096 return 1;
1097 if (!(x != y))
1098 return 2;
1099 if (x < y)
1100 return 3;
1101 if (x > y)
1102 return 4;
1103 if (x <= y)
1104 return 5;
1105 if (x >= y)
1106 return 6;
1107 return 0;
1110 static int test_0_nfloat_isinfinity ()
1112 var x = (nfloat) float.NaN;
1113 if (nfloat.IsInfinity (x))
1114 return 1;
1115 if (nfloat.IsInfinity (12))
1116 return 2;
1117 if (!nfloat.IsInfinity (nfloat.PositiveInfinity))
1118 return 3;
1119 if (!nfloat.IsInfinity (nfloat.NegativeInfinity))
1120 return 4;
1122 return 0;
1125 static int test_0_nfloat_isnegativeinfinity ()
1127 var x = (nfloat) float.NaN;
1128 if (nfloat.IsNegativeInfinity (x))
1129 return 1;
1130 if (nfloat.IsNegativeInfinity (12))
1131 return 2;
1132 if (nfloat.IsNegativeInfinity (nfloat.PositiveInfinity))
1133 return 3;
1134 if (!nfloat.IsNegativeInfinity (nfloat.NegativeInfinity))
1135 return 4;
1137 float f = float.NegativeInfinity;
1138 nfloat n = (nfloat) f;
1139 if (!nfloat.IsNegativeInfinity (n))
1140 return 5;
1142 double d = double.NegativeInfinity;
1143 n = (nfloat) d;
1144 if (!nfloat.IsNegativeInfinity (n))
1145 return 6;
1147 return 0;
1150 static int test_0_nfloat_ispositiveinfinity ()
1152 var x = (nfloat) float.NaN;
1153 if (nfloat.IsPositiveInfinity (x))
1154 return 1;
1155 if (nfloat.IsPositiveInfinity (12))
1156 return 2;
1157 if (!nfloat.IsPositiveInfinity (nfloat.PositiveInfinity))
1158 return 3;
1159 if (nfloat.IsPositiveInfinity (nfloat.NegativeInfinity))
1160 return 4;
1162 float f = float.PositiveInfinity;
1163 nfloat n = (nfloat) f;
1164 if (!nfloat.IsPositiveInfinity (n))
1165 return 5;
1167 double d = double.PositiveInfinity;
1168 n = (nfloat) d;
1169 if (!nfloat.IsPositiveInfinity (n))
1170 return 6;
1172 return 0;
1175 static int test_0_nfloat_isnan ()
1177 var x = (nfloat) float.NaN;
1178 if (!nfloat.IsNaN (x))
1179 return 1;
1180 if (nfloat.IsNaN (12))
1181 return 2;
1182 if (nfloat.IsNaN (nfloat.PositiveInfinity))
1183 return 3;
1184 if (nfloat.IsNaN (nfloat.NegativeInfinity))
1185 return 4;
1187 float f = float.NaN;
1188 nfloat n = (nfloat) f;
1189 if (!nfloat.IsNaN (n))
1190 return 5;
1192 double d = double.NaN;
1193 n = (nfloat) d;
1194 if (!nfloat.IsNaN (n))
1195 return 6;
1197 return 0;
1200 static int test_0_nfloat_compareto ()
1202 if (((nfloat) 0).CompareTo ((nfloat) 0) != 0)
1203 return 1;
1204 if (((nfloat) 0).CompareTo ((nfloat) 1) != -1)
1205 return 2;
1206 if (((nfloat) 1).CompareTo ((nfloat) 0) != 1)
1207 return 3;
1209 if (((nfloat) 0).CompareTo ((object)(nfloat) 0) != 0)
1210 return 4;
1211 if (((nfloat) 0).CompareTo ((object)(nfloat) 1) != -1)
1212 return 5;
1213 if (((nfloat) 1).CompareTo ((object)(nfloat) 0) != 1)
1214 return 6;
1216 if (((nfloat) 1).CompareTo (null) != 1)
1217 return 7;
1219 return 0;
1222 static int test_0_nfloat_call_boxed_equals ()
1224 object x = new nfloat (10f);
1225 object y = new nfloat (10f);
1226 if (!x.Equals (y))
1227 return 1;
1228 return 0;
1231 static int test_0_nfloat_equals ()
1233 if (!((nfloat) 0).Equals ((nfloat) 0))
1234 return 1;
1235 if (!((nfloat) 0).Equals ((object) (nfloat) 0))
1236 return 2;
1237 if (((nfloat) 0).Equals (null))
1238 return 3;
1239 return 0;
1242 static int test_0_nfloat_call_boxed_funs ()
1244 object x = new nfloat (10f);
1245 object y = new nfloat (10f);
1246 if (x.GetHashCode () == 0)
1247 return 2;
1248 if (x.ToString () != "10")
1249 return 3;
1250 return 0;
1253 static int test_0_nfloat_tostring ()
1255 float x = 1337.0f;
1256 nfloat y = (nfloat) x;
1257 if (y.ToString () != "1337")
1258 return 1;
1259 x = -1337.0f;
1260 if (((nfloat) x).ToString () != "-1337")
1261 return 2;
1263 return 0;
1266 static int test_0_nfloat_explicit_decimal ()
1268 nfloat a = new nfloat (10);
1269 nfloat b = new nfloat (9);
1270 if (decimal_cmp ((decimal) a, (decimal) b))
1271 return 1;
1272 b += 1.0f;
1273 if (!decimal_cmp ((decimal) a, (decimal) b))
1274 return 2;
1275 if (!decimal_cmp ((decimal) (nfloat) 10.0f, (decimal) b))
1276 return 3;
1277 if (!decimal_cmp ((decimal) a, (decimal) (nfloat) 10.0f))
1278 return 4;
1279 return 0;
1282 static int test_0_nfloat_unboxed_member_calls ()
1284 var x = (nfloat)10f;
1285 #if FALSE
1286 if (!x.Equals (x))
1287 return 1;
1288 #endif
1289 if (x != nfloat.Parse ("10"))
1290 return 2;
1291 return 0;
1294 struct SomeNativeStructWithNfloat {
1295 public nfloat a;
1296 public static nfloat b;
1298 public SomeNativeStructWithNfloat (nfloat a)
1300 this.a = a;
1301 b = a + 1;
1304 public static nfloat GetAStatic (SomeNativeStructWithNfloat x)
1306 return x.a;
1309 public nfloat GetA ()
1311 return a;
1315 class SomeClassWithNfloat {
1316 public nfloat a;
1318 public SomeClassWithNfloat (nfloat a)
1320 this.a = a;
1323 public virtual nfloat GetAVirtual ()
1325 return a;
1329 static int test_0_nfloat_fieldload ()
1331 var x = new SomeNativeStructWithNfloat ((nfloat) 20f);
1333 if ((float) x.a != 20f)
1334 return 1;
1336 if ((int) x.a != 20)
1337 return 2;
1339 if ((float) SomeNativeStructWithNfloat.GetAStatic (x) != 20f)
1340 return 3;
1342 if ((float) x.GetA () != 20f)
1343 return 4;
1345 if ((int) SomeNativeStructWithNfloat.GetAStatic (x) != 20)
1346 return 5;
1348 if ((int) x.GetA () != 20)
1349 return 6;
1351 if ((float) SomeNativeStructWithNfloat.b != 21f)
1352 return 7;
1354 if ((int) SomeNativeStructWithNfloat.b != 21)
1355 return 8;
1357 SomeClassWithNfloat y = new SomeClassWithNfloat ((nfloat) 30f);
1359 if ((int) y.GetAVirtual () != 30)
1360 return 9;
1362 if ((float) y.GetAVirtual () != 30f)
1363 return 10;
1365 return 0;
1368 static int test_0_much_casting ()
1370 var notOof = (int)(float)1;
1371 if (notOof != 1)
1372 return 1;
1374 var notOof2 = (nint)(float)(nfloat)1;
1375 if (notOof2 != 1)
1376 return 2;
1378 var notOof3 = (nint)(int)(nfloat)1;
1379 if (notOof3 != 1)
1380 return 3;
1382 var oof = (nint)(nfloat)1;
1383 var oof2 = (int) oof - 1;
1384 if (oof2 != 0)
1385 return 4;
1387 var noof = (nfloat)(nint)1;
1388 var noof2 = (float) noof - 1;
1389 if (noof2 > 0.1)
1390 return 5;
1392 return 0;
1395 #if !__MOBILE__
1396 public static int Main (String[] args) {
1397 return TestDriver.RunTests (typeof (BuiltinTests), args);
1399 #endif
1403 // !!! WARNING - GENERATED CODE - DO NOT EDIT !!!
1405 // Generated by NativeTypes.tt, a T4 template.
1407 // NativeTypes.cs: basic types with 32 or 64 bit sizes:
1409 // - nint
1410 // - nuint
1411 // - nfloat
1413 // Authors:
1414 // Aaron Bockover <abock@xamarin.com>
1416 // Copyright 2013 Xamarin, Inc. All rights reserved.
1419 namespace System
1421 [Serializable]
1422 [DebuggerDisplay ("{v,nq}")]
1423 public unsafe struct nint : IFormattable, IConvertible, IComparable, IComparable<nint>, IEquatable <nint>
1425 internal nint (nint v) { this.v = v.v; }
1426 public nint (Int32 v) { this.v = v; }
1428 #if ARCH_32
1429 public static readonly int Size = 4;
1431 public static readonly nint MaxValue = Int32.MaxValue;
1432 public static readonly nint MinValue = Int32.MinValue;
1434 [DebuggerBrowsable (DebuggerBrowsableState.Never)]
1435 internal Int32 v;
1437 public nint (Int64 v) { this.v = (Int32)v; }
1438 #else
1439 public static readonly int Size = 8;
1441 public static readonly nint MaxValue = (nint) Int64.MaxValue; // 64-bit only codepath
1442 public static readonly nint MinValue = (nint) Int64.MinValue; // 64-bit only codepath
1444 [DebuggerBrowsable (DebuggerBrowsableState.Never)]
1445 internal Int64 v;
1447 public nint (Int64 v) { this.v = v; }
1448 #endif
1450 public static explicit operator nint (nuint v)
1452 #if NINT_JIT_OPTIMIZED
1453 throw new NotImplementedException ();
1454 #elif ARCH_32
1455 return new nint ((int)v.v);
1456 #else
1457 return new nint ((long)v.v);
1458 #endif
1461 public static explicit operator nuint (nint v)
1463 #if NINT_JIT_OPTIMIZED
1464 throw new NotImplementedException ();
1465 #elif ARCH_32
1466 return new nuint ((uint)v.v);
1467 #else
1468 return new nuint ((ulong)v.v);
1469 #endif
1472 public static explicit operator nint (nfloat v)
1474 #if NINT_JIT_OPTIMIZED
1475 throw new NotImplementedException ();
1476 #elif ARCH_32
1477 return new nint ((int)v.v);
1478 #else
1479 return new nint ((long)v.v);
1480 #endif
1483 public static implicit operator nfloat (nint v)
1485 #if NINT_JIT_OPTIMIZED
1486 throw new NotImplementedException ();
1487 #elif ARCH_32
1488 return new nfloat ((float)v.v);
1489 #else
1490 return new nfloat ((double)v.v);
1491 #endif
1494 public static explicit operator nint (IntPtr v)
1496 #if NINT_JIT_OPTIMIZED
1497 throw new NotImplementedException ();
1498 #elif ARCH_32
1499 return new nint (*((int *)&v));
1500 #else
1501 return new nint (*((long *)&v));
1502 #endif
1505 public static explicit operator IntPtr (nint v)
1507 #if NINT_JIT_OPTIMIZED
1508 throw new NotImplementedException ();
1509 #elif ARCH_32
1510 return *((IntPtr *)&v.v);
1511 #else
1512 return *((IntPtr *)&v.v);
1513 #endif
1516 public static implicit operator nint (sbyte v)
1518 #if NINT_JIT_OPTIMIZED
1519 throw new NotImplementedException ();
1520 #elif ARCH_32
1521 return new nint ((int)v);
1522 #else
1523 return new nint ((long)v);
1524 #endif
1527 public static explicit operator sbyte (nint v)
1529 #if NINT_JIT_OPTIMIZED
1530 throw new NotImplementedException ();
1531 #elif ARCH_32
1532 return (sbyte)v.v;
1533 #else
1534 return (sbyte)v.v;
1535 #endif
1538 public static implicit operator nint (byte v)
1540 #if NINT_JIT_OPTIMIZED
1541 throw new NotImplementedException ();
1542 #elif ARCH_32
1543 return new nint ((int)v);
1544 #else
1545 return new nint ((long)v);
1546 #endif
1549 public static explicit operator byte (nint v)
1551 #if NINT_JIT_OPTIMIZED
1552 throw new NotImplementedException ();
1553 #elif ARCH_32
1554 return (byte)v.v;
1555 #else
1556 return (byte)v.v;
1557 #endif
1560 public static implicit operator nint (char v)
1562 #if NINT_JIT_OPTIMIZED
1563 throw new NotImplementedException ();
1564 #elif ARCH_32
1565 return new nint ((int)v);
1566 #else
1567 return new nint ((long)v);
1568 #endif
1571 public static explicit operator char (nint v)
1573 #if NINT_JIT_OPTIMIZED
1574 throw new NotImplementedException ();
1575 #elif ARCH_32
1576 return (char)v.v;
1577 #else
1578 return (char)v.v;
1579 #endif
1582 public static implicit operator nint (short v)
1584 #if NINT_JIT_OPTIMIZED
1585 throw new NotImplementedException ();
1586 #elif ARCH_32
1587 return new nint ((int)v);
1588 #else
1589 return new nint ((long)v);
1590 #endif
1593 public static explicit operator short (nint v)
1595 #if NINT_JIT_OPTIMIZED
1596 throw new NotImplementedException ();
1597 #elif ARCH_32
1598 return (short)v.v;
1599 #else
1600 return (short)v.v;
1601 #endif
1604 public static explicit operator nint (ushort v)
1606 #if NINT_JIT_OPTIMIZED
1607 throw new NotImplementedException ();
1608 #elif ARCH_32
1609 return new nint ((int)v);
1610 #else
1611 return new nint ((long)v);
1612 #endif
1615 public static explicit operator ushort (nint v)
1617 #if NINT_JIT_OPTIMIZED
1618 throw new NotImplementedException ();
1619 #elif ARCH_32
1620 return (ushort)v.v;
1621 #else
1622 return (ushort)v.v;
1623 #endif
1626 public static implicit operator nint (int v)
1628 #if NINT_JIT_OPTIMIZED
1629 throw new NotImplementedException ();
1630 #elif ARCH_32
1631 return new nint ((int)v);
1632 #else
1633 return new nint ((long)v);
1634 #endif
1637 public static explicit operator int (nint v)
1639 #if NINT_JIT_OPTIMIZED
1640 throw new NotImplementedException ();
1641 #elif ARCH_32
1642 return (int)v.v;
1643 #else
1644 return (int)v.v;
1645 #endif
1648 public static explicit operator nint (uint v)
1650 #if NINT_JIT_OPTIMIZED
1651 throw new NotImplementedException ();
1652 #elif ARCH_32
1653 return new nint ((int)v);
1654 #else
1655 return new nint ((long)v);
1656 #endif
1659 public static explicit operator uint (nint v)
1661 #if NINT_JIT_OPTIMIZED
1662 throw new NotImplementedException ();
1663 #elif ARCH_32
1664 return (uint)v.v;
1665 #else
1666 return (uint)v.v;
1667 #endif
1670 public static implicit operator nint (long v)
1672 #if NINT_JIT_OPTIMIZED
1673 throw new NotImplementedException ();
1674 #elif ARCH_32
1675 return new nint ((int)v);
1676 #else
1677 return new nint ((long)v);
1678 #endif
1681 public static implicit operator long (nint v)
1683 #if NINT_JIT_OPTIMIZED
1684 throw new NotImplementedException ();
1685 #elif ARCH_32
1686 return (long)v.v;
1687 #else
1688 return (long)v.v;
1689 #endif
1692 public static explicit operator nint (ulong v)
1694 #if NINT_JIT_OPTIMIZED
1695 throw new NotImplementedException ();
1696 #elif ARCH_32
1697 return new nint ((int)v);
1698 #else
1699 return new nint ((long)v);
1700 #endif
1703 public static explicit operator ulong (nint v)
1705 #if NINT_JIT_OPTIMIZED
1706 throw new NotImplementedException ();
1707 #elif ARCH_32
1708 return (ulong)v.v;
1709 #else
1710 return (ulong)v.v;
1711 #endif
1714 public static explicit operator nint (float v)
1716 #if NINT_JIT_OPTIMIZED
1717 throw new NotImplementedException ();
1718 #elif ARCH_32
1719 return new nint ((int)v);
1720 #else
1721 return new nint ((long)v);
1722 #endif
1725 public static implicit operator float (nint v)
1727 #if NINT_JIT_OPTIMIZED
1728 throw new NotImplementedException ();
1729 #elif ARCH_32
1730 return (float)v.v;
1731 #else
1732 return (float)v.v;
1733 #endif
1736 public static explicit operator nint (double v)
1738 #if NINT_JIT_OPTIMIZED
1739 throw new NotImplementedException ();
1740 #elif ARCH_32
1741 return new nint ((int)v);
1742 #else
1743 return new nint ((long)v);
1744 #endif
1747 public static implicit operator double (nint v)
1749 #if NINT_JIT_OPTIMIZED
1750 throw new NotImplementedException ();
1751 #elif ARCH_32
1752 return (double)v.v;
1753 #else
1754 return (double)v.v;
1755 #endif
1758 public static explicit operator nint (decimal v)
1760 #if NINT_JIT_OPTIMIZED
1761 throw new NotImplementedException ();
1762 #elif ARCH_32
1763 return new nint ((int)v);
1764 #else
1765 return new nint ((long)v);
1766 #endif
1769 public static implicit operator decimal (nint v)
1771 #if NINT_JIT_OPTIMIZED
1772 throw new NotImplementedException ();
1773 #elif ARCH_32
1774 return (decimal)v.v;
1775 #else
1776 return (decimal)v.v;
1777 #endif
1780 #if NINT_JIT_OPTIMIZED
1781 public static nint operator + (nint v) { throw new NotImplementedException (); }
1782 public static nint operator - (nint v) { throw new NotImplementedException (); }
1783 public static nint operator ~ (nint v) { throw new NotImplementedException (); }
1784 #else
1785 public static nint operator + (nint v) { return new nint (+v.v); }
1786 public static nint operator - (nint v) { return new nint (-v.v); }
1787 public static nint operator ~ (nint v) { return new nint (~v.v); }
1788 #endif
1791 #if NINT_JIT_OPTIMIZED
1792 public static nint operator + (nint l, nint r) { throw new NotImplementedException (); }
1793 public static nint operator - (nint l, nint r) { throw new NotImplementedException (); }
1794 public static nint operator * (nint l, nint r) { throw new NotImplementedException (); }
1795 public static nint operator / (nint l, nint r) { throw new NotImplementedException (); }
1796 public static nint operator % (nint l, nint r) { throw new NotImplementedException (); }
1797 public static nint operator & (nint l, nint r) { throw new NotImplementedException (); }
1798 public static nint operator | (nint l, nint r) { throw new NotImplementedException (); }
1799 public static nint operator ^ (nint l, nint r) { throw new NotImplementedException (); }
1801 public static nint operator << (nint l, int r) { throw new NotImplementedException (); }
1802 public static nint operator >> (nint l, int r) { throw new NotImplementedException (); }
1803 #else
1804 public static nint operator + (nint l, nint r) { return new nint (l.v + r.v); }
1805 public static nint operator - (nint l, nint r) { return new nint (l.v - r.v); }
1806 public static nint operator * (nint l, nint r) { return new nint (l.v * r.v); }
1807 public static nint operator / (nint l, nint r) { return new nint (l.v / r.v); }
1808 public static nint operator % (nint l, nint r) { return new nint (l.v % r.v); }
1809 public static nint operator & (nint l, nint r) { return new nint (l.v & r.v); }
1810 public static nint operator | (nint l, nint r) { return new nint (l.v | r.v); }
1811 public static nint operator ^ (nint l, nint r) { return new nint (l.v ^ r.v); }
1813 public static nint operator << (nint l, int r) { return new nint (l.v << r); }
1814 public static nint operator >> (nint l, int r) { return new nint (l.v >> r); }
1815 #endif
1817 #if NINT_JIT_OPTIMIZED
1818 public static bool operator == (nint l, nint r) { throw new NotImplementedException (); }
1819 public static bool operator != (nint l, nint r) { throw new NotImplementedException (); }
1820 public static bool operator < (nint l, nint r) { throw new NotImplementedException (); }
1821 public static bool operator > (nint l, nint r) { throw new NotImplementedException (); }
1822 public static bool operator <= (nint l, nint r) { throw new NotImplementedException (); }
1823 public static bool operator >= (nint l, nint r) { throw new NotImplementedException (); }
1824 #else
1825 public static bool operator == (nint l, nint r) { return l.v == r.v; }
1826 public static bool operator != (nint l, nint r) { return l.v != r.v; }
1827 public static bool operator < (nint l, nint r) { return l.v < r.v; }
1828 public static bool operator > (nint l, nint r) { return l.v > r.v; }
1829 public static bool operator <= (nint l, nint r) { return l.v <= r.v; }
1830 public static bool operator >= (nint l, nint r) { return l.v >= r.v; }
1831 #endif
1833 public int CompareTo (nint value) { return v.CompareTo (value.v); }
1834 public int CompareTo (object value)
1836 if (value is nint)
1837 return v.CompareTo (((nint) value).v);
1838 return v.CompareTo (value);
1840 public bool Equals (nint obj) { return v.Equals (obj.v); }
1841 public override bool Equals (object obj)
1843 if (obj is nint)
1844 return v.Equals (((nint) obj).v);
1845 return v.Equals (obj);
1847 public override int GetHashCode () { return v.GetHashCode (); }
1849 #if ARCH_32
1850 public static nint Parse (string s, IFormatProvider provider) { return (nint)Int32.Parse (s, provider); }
1851 public static nint Parse (string s, NumberStyles style) { return (nint)Int32.Parse (s, style); }
1852 public static nint Parse (string s) { return (nint)Int32.Parse (s); }
1853 public static nint Parse (string s, NumberStyles style, IFormatProvider provider) {
1854 return (nint)Int32.Parse (s, style, provider);
1857 public static bool TryParse (string s, out nint result)
1859 Int32 v;
1860 var r = Int32.TryParse (s, out v);
1861 result = (nint)v;
1862 return r;
1865 public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nint result)
1867 Int32 v;
1868 var r = Int32.TryParse (s, style, provider, out v);
1869 result = (nint)v;
1870 return r;
1872 #else
1873 public static nint Parse (string s, IFormatProvider provider) { return (nint)Int64.Parse (s, provider); }
1874 public static nint Parse (string s, NumberStyles style) { return (nint)Int64.Parse (s, style); }
1875 public static nint Parse (string s) { return (nint)Int64.Parse (s); }
1876 public static nint Parse (string s, NumberStyles style, IFormatProvider provider) {
1877 return (nint)Int64.Parse (s, style, provider);
1880 public static bool TryParse (string s, out nint result)
1882 Int64 v;
1883 var r = Int64.TryParse (s, out v);
1884 result = (nint)v;
1885 return r;
1888 public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nint result)
1890 Int64 v;
1891 var r = Int64.TryParse (s, style, provider, out v);
1892 result = (nint)v;
1893 return r;
1895 #endif
1897 public override string ToString () { return v.ToString (); }
1898 public string ToString (IFormatProvider provider) { return v.ToString (provider); }
1899 public string ToString (string format) { return v.ToString (format); }
1900 public string ToString (string format, IFormatProvider provider) { return v.ToString (format, provider); }
1902 public TypeCode GetTypeCode () { return v.GetTypeCode (); }
1904 bool IConvertible.ToBoolean (IFormatProvider provider) { return ((IConvertible)v).ToBoolean (provider); }
1905 byte IConvertible.ToByte (IFormatProvider provider) { return ((IConvertible)v).ToByte (provider); }
1906 char IConvertible.ToChar (IFormatProvider provider) { return ((IConvertible)v).ToChar (provider); }
1907 DateTime IConvertible.ToDateTime (IFormatProvider provider) { return ((IConvertible)v).ToDateTime (provider); }
1908 decimal IConvertible.ToDecimal (IFormatProvider provider) { return ((IConvertible)v).ToDecimal (provider); }
1909 double IConvertible.ToDouble (IFormatProvider provider) { return ((IConvertible)v).ToDouble (provider); }
1910 short IConvertible.ToInt16 (IFormatProvider provider) { return ((IConvertible)v).ToInt16 (provider); }
1911 int IConvertible.ToInt32 (IFormatProvider provider) { return ((IConvertible)v).ToInt32 (provider); }
1912 long IConvertible.ToInt64 (IFormatProvider provider) { return ((IConvertible)v).ToInt64 (provider); }
1913 sbyte IConvertible.ToSByte (IFormatProvider provider) { return ((IConvertible)v).ToSByte (provider); }
1914 float IConvertible.ToSingle (IFormatProvider provider) { return ((IConvertible)v).ToSingle (provider); }
1915 ushort IConvertible.ToUInt16 (IFormatProvider provider) { return ((IConvertible)v).ToUInt16 (provider); }
1916 uint IConvertible.ToUInt32 (IFormatProvider provider) { return ((IConvertible)v).ToUInt32 (provider); }
1917 ulong IConvertible.ToUInt64 (IFormatProvider provider) { return ((IConvertible)v).ToUInt64 (provider); }
1919 object IConvertible.ToType (Type targetType, IFormatProvider provider) {
1920 return ((IConvertible)v).ToType (targetType, provider);
1923 public static void CopyArray (IntPtr source, nint [] destination, int startIndex, int length)
1925 if (source == IntPtr.Zero)
1926 throw new ArgumentNullException ("source");
1927 if (destination == null)
1928 throw new ArgumentNullException ("destination");
1929 if (destination.Rank != 1)
1930 throw new ArgumentException ("destination", "array is multi-dimensional");
1931 if (startIndex < 0)
1932 throw new ArgumentException ("startIndex", "must be >= 0");
1933 if (length < 0)
1934 throw new ArgumentException ("length", "must be >= 0");
1935 if (startIndex + length > destination.Length)
1936 throw new ArgumentException ("length", "startIndex + length > destination.Length");
1938 for (int i = 0; i < length; i++)
1939 destination [i + startIndex] = (nint)Marshal.ReadIntPtr (source, i * nint.Size);
1942 public static void CopyArray (nint [] source, int startIndex, IntPtr destination, int length)
1944 if (source == null)
1945 throw new ArgumentNullException ("source");
1946 if (destination == IntPtr.Zero)
1947 throw new ArgumentNullException ("destination");
1948 if (source.Rank != 1)
1949 throw new ArgumentException ("source", "array is multi-dimensional");
1950 if (startIndex < 0)
1951 throw new ArgumentException ("startIndex", "must be >= 0");
1952 if (length < 0)
1953 throw new ArgumentException ("length", "must be >= 0");
1954 if (startIndex + length > source.Length)
1955 throw new ArgumentException ("length", "startIndex + length > source.Length");
1957 for (int i = 0; i < length; i++)
1958 Marshal.WriteIntPtr (destination, i * nint.Size, (IntPtr)source [i + startIndex]);
1961 [Serializable]
1962 [DebuggerDisplay ("{v,nq}")]
1963 public unsafe struct nuint : IFormattable, IConvertible, IComparable, IComparable<nuint>, IEquatable <nuint>
1965 internal nuint (nuint v) { this.v = v.v; }
1966 public nuint (UInt32 v) { this.v = v; }
1968 #if ARCH_32
1969 public static readonly int Size = 4;
1971 public static readonly nuint MaxValue = UInt32.MaxValue;
1972 public static readonly nuint MinValue = UInt32.MinValue;
1974 [DebuggerBrowsable (DebuggerBrowsableState.Never)]
1975 internal UInt32 v;
1977 public nuint (UInt64 v) { this.v = (UInt32)v; }
1978 #else
1979 public static readonly int Size = 8;
1981 public static readonly nuint MaxValue = (nuint) UInt64.MaxValue; // 64-bit only codepath
1982 public static readonly nuint MinValue = (nuint) UInt64.MinValue; // 64-bit only codepath
1984 [DebuggerBrowsable (DebuggerBrowsableState.Never)]
1985 internal UInt64 v;
1987 public nuint (UInt64 v) { this.v = v; }
1988 #endif
1990 public static explicit operator nuint (nfloat v)
1992 #if NINT_JIT_OPTIMIZED
1993 throw new NotImplementedException ();
1994 #elif ARCH_32
1995 return new nuint ((uint)v.v);
1996 #else
1997 return new nuint ((ulong)v.v);
1998 #endif
2001 public static implicit operator nfloat (nuint v)
2003 #if NINT_JIT_OPTIMIZED
2004 throw new NotImplementedException ();
2005 #elif ARCH_32
2006 return new nfloat ((float)v.v);
2007 #else
2008 return new nfloat ((double)v.v);
2009 #endif
2012 public static explicit operator nuint (IntPtr v)
2014 #if NINT_JIT_OPTIMIZED
2015 throw new NotImplementedException ();
2016 #elif ARCH_32
2017 return new nuint (*((uint *)&v));
2018 #else
2019 return new nuint (*((ulong *)&v));
2020 #endif
2023 public static explicit operator IntPtr (nuint v)
2025 #if NINT_JIT_OPTIMIZED
2026 throw new NotImplementedException ();
2027 #elif ARCH_32
2028 return *((IntPtr *)&v.v);
2029 #else
2030 return *((IntPtr *)&v.v);
2031 #endif
2034 public static explicit operator nuint (sbyte v)
2036 #if NINT_JIT_OPTIMIZED
2037 throw new NotImplementedException ();
2038 #elif ARCH_32
2039 return new nuint ((uint)v);
2040 #else
2041 return new nuint ((ulong)v);
2042 #endif
2045 public static explicit operator sbyte (nuint v)
2047 #if NINT_JIT_OPTIMIZED
2048 throw new NotImplementedException ();
2049 #elif ARCH_32
2050 return (sbyte)v.v;
2051 #else
2052 return (sbyte)v.v;
2053 #endif
2056 public static implicit operator nuint (byte v)
2058 #if NINT_JIT_OPTIMIZED
2059 throw new NotImplementedException ();
2060 #elif ARCH_32
2061 return new nuint ((uint)v);
2062 #else
2063 return new nuint ((ulong)v);
2064 #endif
2067 public static explicit operator byte (nuint v)
2069 #if NINT_JIT_OPTIMIZED
2070 throw new NotImplementedException ();
2071 #elif ARCH_32
2072 return (byte)v.v;
2073 #else
2074 return (byte)v.v;
2075 #endif
2078 public static implicit operator nuint (char v)
2080 #if NINT_JIT_OPTIMIZED
2081 throw new NotImplementedException ();
2082 #elif ARCH_32
2083 return new nuint ((uint)v);
2084 #else
2085 return new nuint ((ulong)v);
2086 #endif
2089 public static explicit operator char (nuint v)
2091 #if NINT_JIT_OPTIMIZED
2092 throw new NotImplementedException ();
2093 #elif ARCH_32
2094 return (char)v.v;
2095 #else
2096 return (char)v.v;
2097 #endif
2100 public static explicit operator nuint (short v)
2102 #if NINT_JIT_OPTIMIZED
2103 throw new NotImplementedException ();
2104 #elif ARCH_32
2105 return new nuint ((uint)v);
2106 #else
2107 return new nuint ((ulong)v);
2108 #endif
2111 public static explicit operator short (nuint v)
2113 #if NINT_JIT_OPTIMIZED
2114 throw new NotImplementedException ();
2115 #elif ARCH_32
2116 return (short)v.v;
2117 #else
2118 return (short)v.v;
2119 #endif
2122 public static implicit operator nuint (ushort v)
2124 #if NINT_JIT_OPTIMIZED
2125 throw new NotImplementedException ();
2126 #elif ARCH_32
2127 return new nuint ((uint)v);
2128 #else
2129 return new nuint ((ulong)v);
2130 #endif
2133 public static explicit operator ushort (nuint v)
2135 #if NINT_JIT_OPTIMIZED
2136 throw new NotImplementedException ();
2137 #elif ARCH_32
2138 return (ushort)v.v;
2139 #else
2140 return (ushort)v.v;
2141 #endif
2144 public static explicit operator nuint (int v)
2146 #if NINT_JIT_OPTIMIZED
2147 throw new NotImplementedException ();
2148 #elif ARCH_32
2149 return new nuint ((uint)v);
2150 #else
2151 return new nuint ((ulong)v);
2152 #endif
2155 public static explicit operator int (nuint v)
2157 #if NINT_JIT_OPTIMIZED
2158 throw new NotImplementedException ();
2159 #elif ARCH_32
2160 return (int)v.v;
2161 #else
2162 return (int)v.v;
2163 #endif
2166 public static implicit operator nuint (uint v)
2168 #if NINT_JIT_OPTIMIZED
2169 throw new NotImplementedException ();
2170 #elif ARCH_32
2171 return new nuint ((uint)v);
2172 #else
2173 return new nuint ((ulong)v);
2174 #endif
2177 public static explicit operator uint (nuint v)
2179 #if NINT_JIT_OPTIMIZED
2180 throw new NotImplementedException ();
2181 #elif ARCH_32
2182 return (uint)v.v;
2183 #else
2184 return (uint)v.v;
2185 #endif
2188 public static explicit operator nuint (long v)
2190 #if NINT_JIT_OPTIMIZED
2191 throw new NotImplementedException ();
2192 #elif ARCH_32
2193 return new nuint ((uint)v);
2194 #else
2195 return new nuint ((ulong)v);
2196 #endif
2199 public static explicit operator long (nuint v)
2201 #if NINT_JIT_OPTIMIZED
2202 throw new NotImplementedException ();
2203 #elif ARCH_32
2204 return (long)v.v;
2205 #else
2206 return (long)v.v;
2207 #endif
2210 public static implicit operator nuint (ulong v)
2212 #if NINT_JIT_OPTIMIZED
2213 throw new NotImplementedException ();
2214 #elif ARCH_32
2215 return new nuint ((uint)v);
2216 #else
2217 return new nuint ((ulong)v);
2218 #endif
2221 public static implicit operator ulong (nuint v)
2223 #if NINT_JIT_OPTIMIZED
2224 throw new NotImplementedException ();
2225 #elif ARCH_32
2226 return (ulong)v.v;
2227 #else
2228 return (ulong)v.v;
2229 #endif
2232 public static explicit operator nuint (float v)
2234 #if NINT_JIT_OPTIMIZED
2235 throw new NotImplementedException ();
2236 #elif ARCH_32
2237 return new nuint ((uint)v);
2238 #else
2239 return new nuint ((ulong)v);
2240 #endif
2243 public static implicit operator float (nuint v)
2245 #if NINT_JIT_OPTIMIZED
2246 throw new NotImplementedException ();
2247 #elif ARCH_32
2248 return (float)v.v;
2249 #else
2250 return (float)v.v;
2251 #endif
2254 public static explicit operator nuint (double v)
2256 #if NINT_JIT_OPTIMIZED
2257 throw new NotImplementedException ();
2258 #elif ARCH_32
2259 return new nuint ((uint)v);
2260 #else
2261 return new nuint ((ulong)v);
2262 #endif
2265 public static implicit operator double (nuint v)
2267 #if NINT_JIT_OPTIMIZED
2268 throw new NotImplementedException ();
2269 #elif ARCH_32
2270 return (double)v.v;
2271 #else
2272 return (double)v.v;
2273 #endif
2276 public static explicit operator nuint (decimal v)
2278 #if NINT_JIT_OPTIMIZED
2279 throw new NotImplementedException ();
2280 #elif ARCH_32
2281 return new nuint ((uint)v);
2282 #else
2283 return new nuint ((ulong)v);
2284 #endif
2287 public static implicit operator decimal (nuint v)
2289 #if NINT_JIT_OPTIMIZED
2290 throw new NotImplementedException ();
2291 #elif ARCH_32
2292 return (decimal)v.v;
2293 #else
2294 return (decimal)v.v;
2295 #endif
2298 #if NINT_JIT_OPTIMIZED
2299 public static nuint operator + (nuint v) { throw new NotImplementedException (); }
2300 public static nuint operator ~ (nuint v) { throw new NotImplementedException (); }
2301 #else
2302 public static nuint operator + (nuint v) { return new nuint (+v.v); }
2303 public static nuint operator ~ (nuint v) { return new nuint (~v.v); }
2304 #endif
2306 #if NINT_JIT_OPTIMIZED
2307 public static nuint operator + (nuint l, nuint r) { throw new NotImplementedException (); }
2308 public static nuint operator - (nuint l, nuint r) { throw new NotImplementedException (); }
2309 public static nuint operator * (nuint l, nuint r) { throw new NotImplementedException (); }
2310 public static nuint operator / (nuint l, nuint r) { throw new NotImplementedException (); }
2311 public static nuint operator % (nuint l, nuint r) { throw new NotImplementedException (); }
2312 public static nuint operator & (nuint l, nuint r) { throw new NotImplementedException (); }
2313 public static nuint operator | (nuint l, nuint r) { throw new NotImplementedException (); }
2314 public static nuint operator ^ (nuint l, nuint r) { throw new NotImplementedException (); }
2316 public static nuint operator << (nuint l, int r) { throw new NotImplementedException (); }
2317 public static nuint operator >> (nuint l, int r) { throw new NotImplementedException (); }
2318 #else
2319 public static nuint operator + (nuint l, nuint r) { return new nuint (l.v + r.v); }
2320 public static nuint operator - (nuint l, nuint r) { return new nuint (l.v - r.v); }
2321 public static nuint operator * (nuint l, nuint r) { return new nuint (l.v * r.v); }
2322 public static nuint operator / (nuint l, nuint r) { return new nuint (l.v / r.v); }
2323 public static nuint operator % (nuint l, nuint r) { return new nuint (l.v % r.v); }
2324 public static nuint operator & (nuint l, nuint r) { return new nuint (l.v & r.v); }
2325 public static nuint operator | (nuint l, nuint r) { return new nuint (l.v | r.v); }
2326 public static nuint operator ^ (nuint l, nuint r) { return new nuint (l.v ^ r.v); }
2328 public static nuint operator << (nuint l, int r) { return new nuint (l.v << r); }
2329 public static nuint operator >> (nuint l, int r) { return new nuint (l.v >> r); }
2330 #endif
2332 #if NINT_JIT_OPTIMIZED
2333 public static bool operator == (nuint l, nuint r) { throw new NotImplementedException (); }
2334 public static bool operator != (nuint l, nuint r) { throw new NotImplementedException (); }
2335 public static bool operator < (nuint l, nuint r) { throw new NotImplementedException (); }
2336 public static bool operator > (nuint l, nuint r) { throw new NotImplementedException (); }
2337 public static bool operator <= (nuint l, nuint r) { throw new NotImplementedException (); }
2338 public static bool operator >= (nuint l, nuint r) { throw new NotImplementedException (); }
2339 #else
2340 public static bool operator == (nuint l, nuint r) { return l.v == r.v; }
2341 public static bool operator != (nuint l, nuint r) { return l.v != r.v; }
2342 public static bool operator < (nuint l, nuint r) { return l.v < r.v; }
2343 public static bool operator > (nuint l, nuint r) { return l.v > r.v; }
2344 public static bool operator <= (nuint l, nuint r) { return l.v <= r.v; }
2345 public static bool operator >= (nuint l, nuint r) { return l.v >= r.v; }
2346 #endif
2348 public int CompareTo (nuint value) { return v.CompareTo (value.v); }
2349 public int CompareTo (object value)
2351 if (value is nuint)
2352 return v.CompareTo (((nuint) value).v);
2353 return v.CompareTo (value);
2355 public bool Equals (nuint obj) { return v.Equals (obj.v); }
2356 public override bool Equals (object obj)
2358 if (obj is nuint)
2359 return v.Equals (((nuint) obj).v);
2360 return v.Equals (obj);
2362 public override int GetHashCode () { return v.GetHashCode (); }
2364 #if ARCH_32
2365 public static nuint Parse (string s, IFormatProvider provider) { return (nuint)UInt32.Parse (s, provider); }
2366 public static nuint Parse (string s, NumberStyles style) { return (nuint)UInt32.Parse (s, style); }
2367 public static nuint Parse (string s) { return (nuint)UInt32.Parse (s); }
2368 public static nuint Parse (string s, NumberStyles style, IFormatProvider provider) {
2369 return (nuint)UInt32.Parse (s, style, provider);
2372 public static bool TryParse (string s, out nuint result)
2374 UInt32 v;
2375 var r = UInt32.TryParse (s, out v);
2376 result = (nuint)v;
2377 return r;
2380 public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nuint result)
2382 UInt32 v;
2383 var r = UInt32.TryParse (s, style, provider, out v);
2384 result = (nuint)v;
2385 return r;
2387 #else
2388 public static nuint Parse (string s, IFormatProvider provider) { return (nuint)UInt64.Parse (s, provider); }
2389 public static nuint Parse (string s, NumberStyles style) { return (nuint)UInt64.Parse (s, style); }
2390 public static nuint Parse (string s) { return (nuint)UInt64.Parse (s); }
2391 public static nuint Parse (string s, NumberStyles style, IFormatProvider provider) {
2392 return (nuint)UInt64.Parse (s, style, provider);
2395 public static bool TryParse (string s, out nuint result)
2397 UInt64 v;
2398 var r = UInt64.TryParse (s, out v);
2399 result = (nuint)v;
2400 return r;
2403 public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nuint result)
2405 UInt64 v;
2406 var r = UInt64.TryParse (s, style, provider, out v);
2407 result = (nuint)v;
2408 return r;
2410 #endif
2412 public override string ToString () { return v.ToString (); }
2413 public string ToString (IFormatProvider provider) { return v.ToString (provider); }
2414 public string ToString (string format) { return v.ToString (format); }
2415 public string ToString (string format, IFormatProvider provider) { return v.ToString (format, provider); }
2417 public TypeCode GetTypeCode () { return v.GetTypeCode (); }
2419 bool IConvertible.ToBoolean (IFormatProvider provider) { return ((IConvertible)v).ToBoolean (provider); }
2420 byte IConvertible.ToByte (IFormatProvider provider) { return ((IConvertible)v).ToByte (provider); }
2421 char IConvertible.ToChar (IFormatProvider provider) { return ((IConvertible)v).ToChar (provider); }
2422 DateTime IConvertible.ToDateTime (IFormatProvider provider) { return ((IConvertible)v).ToDateTime (provider); }
2423 decimal IConvertible.ToDecimal (IFormatProvider provider) { return ((IConvertible)v).ToDecimal (provider); }
2424 double IConvertible.ToDouble (IFormatProvider provider) { return ((IConvertible)v).ToDouble (provider); }
2425 short IConvertible.ToInt16 (IFormatProvider provider) { return ((IConvertible)v).ToInt16 (provider); }
2426 int IConvertible.ToInt32 (IFormatProvider provider) { return ((IConvertible)v).ToInt32 (provider); }
2427 long IConvertible.ToInt64 (IFormatProvider provider) { return ((IConvertible)v).ToInt64 (provider); }
2428 sbyte IConvertible.ToSByte (IFormatProvider provider) { return ((IConvertible)v).ToSByte (provider); }
2429 float IConvertible.ToSingle (IFormatProvider provider) { return ((IConvertible)v).ToSingle (provider); }
2430 ushort IConvertible.ToUInt16 (IFormatProvider provider) { return ((IConvertible)v).ToUInt16 (provider); }
2431 uint IConvertible.ToUInt32 (IFormatProvider provider) { return ((IConvertible)v).ToUInt32 (provider); }
2432 ulong IConvertible.ToUInt64 (IFormatProvider provider) { return ((IConvertible)v).ToUInt64 (provider); }
2434 object IConvertible.ToType (Type targetType, IFormatProvider provider) {
2435 return ((IConvertible)v).ToType (targetType, provider);
2438 public static void CopyArray (IntPtr source, nuint [] destination, int startIndex, int length)
2440 if (source == IntPtr.Zero)
2441 throw new ArgumentNullException ("source");
2442 if (destination == null)
2443 throw new ArgumentNullException ("destination");
2444 if (destination.Rank != 1)
2445 throw new ArgumentException ("destination", "array is multi-dimensional");
2446 if (startIndex < 0)
2447 throw new ArgumentException ("startIndex", "must be >= 0");
2448 if (length < 0)
2449 throw new ArgumentException ("length", "must be >= 0");
2450 if (startIndex + length > destination.Length)
2451 throw new ArgumentException ("length", "startIndex + length > destination.Length");
2453 for (int i = 0; i < length; i++)
2454 destination [i + startIndex] = (nuint)Marshal.ReadIntPtr (source, i * nuint.Size);
2457 public static void CopyArray (nuint [] source, int startIndex, IntPtr destination, int length)
2459 if (source == null)
2460 throw new ArgumentNullException ("source");
2461 if (destination == IntPtr.Zero)
2462 throw new ArgumentNullException ("destination");
2463 if (source.Rank != 1)
2464 throw new ArgumentException ("source", "array is multi-dimensional");
2465 if (startIndex < 0)
2466 throw new ArgumentException ("startIndex", "must be >= 0");
2467 if (length < 0)
2468 throw new ArgumentException ("length", "must be >= 0");
2469 if (startIndex + length > source.Length)
2470 throw new ArgumentException ("length", "startIndex + length > source.Length");
2472 for (int i = 0; i < length; i++)
2473 Marshal.WriteIntPtr (destination, i * nuint.Size, (IntPtr)source [i + startIndex]);
2476 [Serializable]
2477 [DebuggerDisplay ("{v,nq}")]
2478 public unsafe struct nfloat : IFormattable, IConvertible, IComparable, IComparable<nfloat>, IEquatable <nfloat>
2480 internal nfloat (nfloat v) { this.v = v.v; }
2481 public nfloat (Single v) { this.v = v; }
2483 #if ARCH_32
2484 public static readonly int Size = 4;
2486 public static readonly nfloat MaxValue = Single.MaxValue;
2487 public static readonly nfloat MinValue = Single.MinValue;
2488 public static readonly nfloat Epsilon = (nfloat)Single.Epsilon;
2489 public static readonly nfloat NaN = (nfloat)Single.NaN;
2490 public static readonly nfloat NegativeInfinity = (nfloat)Single.NegativeInfinity;
2491 public static readonly nfloat PositiveInfinity = (nfloat)Single.PositiveInfinity;
2493 [DebuggerBrowsable (DebuggerBrowsableState.Never)]
2494 internal Single v;
2496 public nfloat (Double v) { this.v = (Single)v; }
2497 #else
2498 public static readonly int Size = 8;
2500 public static readonly nfloat MaxValue = (nfloat) Double.MaxValue; // 64-bit only codepath
2501 public static readonly nfloat MinValue = (nfloat) Double.MinValue; // 64-bit only codepath
2502 public static readonly nfloat Epsilon = (nfloat)Double.Epsilon;
2503 public static readonly nfloat NaN = (nfloat)Double.NaN;
2504 public static readonly nfloat NegativeInfinity = (nfloat)Double.NegativeInfinity;
2505 public static readonly nfloat PositiveInfinity = (nfloat)Double.PositiveInfinity;
2507 [DebuggerBrowsable (DebuggerBrowsableState.Never)]
2508 internal Double v;
2510 public nfloat (Double v) { this.v = v; }
2511 #endif
2513 public static explicit operator nfloat (IntPtr v)
2515 #if NINT_JIT_OPTIMIZED
2516 throw new NotImplementedException ();
2517 #elif ARCH_32
2518 return new nfloat (*((float *)&v));
2519 #else
2520 return new nfloat (*((double *)&v));
2521 #endif
2524 public static explicit operator IntPtr (nfloat v)
2526 #if NINT_JIT_OPTIMIZED
2527 throw new NotImplementedException ();
2528 #elif ARCH_32
2529 return *((IntPtr *)&v.v);
2530 #else
2531 return *((IntPtr *)&v.v);
2532 #endif
2535 public static implicit operator nfloat (sbyte v)
2537 #if NINT_JIT_OPTIMIZED
2538 throw new NotImplementedException ();
2539 #elif ARCH_32
2540 return new nfloat ((float)v);
2541 #else
2542 return new nfloat ((double)v);
2543 #endif
2546 public static explicit operator sbyte (nfloat v)
2548 #if NINT_JIT_OPTIMIZED
2549 throw new NotImplementedException ();
2550 #elif ARCH_32
2551 return (sbyte)v.v;
2552 #else
2553 return (sbyte)v.v;
2554 #endif
2557 public static implicit operator nfloat (byte v)
2559 #if NINT_JIT_OPTIMIZED
2560 throw new NotImplementedException ();
2561 #elif ARCH_32
2562 return new nfloat ((float)v);
2563 #else
2564 return new nfloat ((double)v);
2565 #endif
2568 public static explicit operator byte (nfloat v)
2570 #if NINT_JIT_OPTIMIZED
2571 throw new NotImplementedException ();
2572 #elif ARCH_32
2573 return (byte)v.v;
2574 #else
2575 return (byte)v.v;
2576 #endif
2579 public static implicit operator nfloat (char v)
2581 #if NINT_JIT_OPTIMIZED
2582 throw new NotImplementedException ();
2583 #elif ARCH_32
2584 return new nfloat ((float)v);
2585 #else
2586 return new nfloat ((double)v);
2587 #endif
2590 public static explicit operator char (nfloat v)
2592 #if NINT_JIT_OPTIMIZED
2593 throw new NotImplementedException ();
2594 #elif ARCH_32
2595 return (char)v.v;
2596 #else
2597 return (char)v.v;
2598 #endif
2601 public static implicit operator nfloat (short v)
2603 #if NINT_JIT_OPTIMIZED
2604 throw new NotImplementedException ();
2605 #elif ARCH_32
2606 return new nfloat ((float)v);
2607 #else
2608 return new nfloat ((double)v);
2609 #endif
2612 public static explicit operator short (nfloat v)
2614 #if NINT_JIT_OPTIMIZED
2615 throw new NotImplementedException ();
2616 #elif ARCH_32
2617 return (short)v.v;
2618 #else
2619 return (short)v.v;
2620 #endif
2623 public static implicit operator nfloat (ushort v)
2625 #if NINT_JIT_OPTIMIZED
2626 throw new NotImplementedException ();
2627 #elif ARCH_32
2628 return new nfloat ((float)v);
2629 #else
2630 return new nfloat ((double)v);
2631 #endif
2634 public static explicit operator ushort (nfloat v)
2636 #if NINT_JIT_OPTIMIZED
2637 throw new NotImplementedException ();
2638 #elif ARCH_32
2639 return (ushort)v.v;
2640 #else
2641 return (ushort)v.v;
2642 #endif
2645 public static implicit operator nfloat (int v)
2647 #if NINT_JIT_OPTIMIZED
2648 throw new NotImplementedException ();
2649 #elif ARCH_32
2650 return new nfloat ((float)v);
2651 #else
2652 return new nfloat ((double)v);
2653 #endif
2656 public static explicit operator int (nfloat v)
2658 #if NINT_JIT_OPTIMIZED
2659 throw new NotImplementedException ();
2660 #elif ARCH_32
2661 return (int)v.v;
2662 #else
2663 return (int)v.v;
2664 #endif
2667 public static implicit operator nfloat (uint v)
2669 #if NINT_JIT_OPTIMIZED
2670 throw new NotImplementedException ();
2671 #elif ARCH_32
2672 return new nfloat ((float)v);
2673 #else
2674 return new nfloat ((double)v);
2675 #endif
2678 public static explicit operator uint (nfloat v)
2680 #if NINT_JIT_OPTIMIZED
2681 throw new NotImplementedException ();
2682 #elif ARCH_32
2683 return (uint)v.v;
2684 #else
2685 return (uint)v.v;
2686 #endif
2689 public static implicit operator nfloat (long v)
2691 #if NINT_JIT_OPTIMIZED
2692 throw new NotImplementedException ();
2693 #elif ARCH_32
2694 return new nfloat ((float)v);
2695 #else
2696 return new nfloat ((double)v);
2697 #endif
2700 public static explicit operator long (nfloat v)
2702 #if NINT_JIT_OPTIMIZED
2703 throw new NotImplementedException ();
2704 #elif ARCH_32
2705 return (long)v.v;
2706 #else
2707 return (long)v.v;
2708 #endif
2711 public static implicit operator nfloat (ulong v)
2713 #if NINT_JIT_OPTIMIZED
2714 throw new NotImplementedException ();
2715 #elif ARCH_32
2716 return new nfloat ((float)v);
2717 #else
2718 return new nfloat ((double)v);
2719 #endif
2722 public static explicit operator ulong (nfloat v)
2724 #if NINT_JIT_OPTIMIZED
2725 throw new NotImplementedException ();
2726 #elif ARCH_32
2727 return (ulong)v.v;
2728 #else
2729 return (ulong)v.v;
2730 #endif
2733 public static implicit operator nfloat (float v)
2735 #if NINT_JIT_OPTIMIZED
2736 throw new NotImplementedException ();
2737 #elif ARCH_32
2738 return new nfloat ((float)v);
2739 #else
2740 return new nfloat ((double)v);
2741 #endif
2744 public static explicit operator float (nfloat v)
2746 #if NINT_JIT_OPTIMIZED
2747 throw new NotImplementedException ();
2748 #elif ARCH_32
2749 return (float)v.v;
2750 #else
2751 return (float)v.v;
2752 #endif
2755 public static explicit operator nfloat (double v)
2757 #if NINT_JIT_OPTIMIZED
2758 throw new NotImplementedException ();
2759 #elif ARCH_32
2760 return new nfloat ((float)v);
2761 #else
2762 return new nfloat ((double)v);
2763 #endif
2766 public static implicit operator double (nfloat v)
2768 #if NINT_JIT_OPTIMIZED
2769 throw new NotImplementedException ();
2770 #elif ARCH_32
2771 return (double)v.v;
2772 #else
2773 return (double)v.v;
2774 #endif
2777 public static explicit operator nfloat (decimal v)
2779 #if NINT_JIT_OPTIMIZED
2780 throw new NotImplementedException ();
2781 #elif ARCH_32
2782 return new nfloat ((float)v);
2783 #else
2784 return new nfloat ((double)v);
2785 #endif
2788 public static explicit operator decimal (nfloat v)
2790 #if NINT_JIT_OPTIMIZED
2791 throw new NotImplementedException ();
2792 #elif ARCH_32
2793 return (decimal)v.v;
2794 #else
2795 return (decimal)v.v;
2796 #endif
2799 #if NINT_JIT_OPTIMIZED
2800 public static nfloat operator + (nfloat v) { throw new NotImplementedException (); }
2801 public static nfloat operator - (nfloat v) { throw new NotImplementedException (); }
2802 #else
2803 public static nfloat operator + (nfloat v) { return new nfloat (+v.v); }
2804 public static nfloat operator - (nfloat v) { return new nfloat (-v.v); }
2805 #endif
2807 #if NINT_JIT_OPTIMIZED
2808 public static nfloat operator ++ (nfloat v) { throw new NotImplementedException (); }
2809 public static nfloat operator -- (nfloat v) { throw new NotImplementedException (); }
2810 #else
2811 public static nfloat operator ++ (nfloat v) { return new nfloat (v.v + 1); }
2812 public static nfloat operator -- (nfloat v) { return new nfloat (v.v - 1); }
2813 #endif
2815 #if NINT_JIT_OPTIMIZED
2816 public static nfloat operator + (nfloat l, nfloat r) { throw new NotImplementedException (); }
2817 public static nfloat operator - (nfloat l, nfloat r) { throw new NotImplementedException (); }
2818 public static nfloat operator * (nfloat l, nfloat r) { throw new NotImplementedException (); }
2819 public static nfloat operator / (nfloat l, nfloat r) { throw new NotImplementedException (); }
2820 public static nfloat operator % (nfloat l, nfloat r) { throw new NotImplementedException (); }
2821 #else
2822 public static nfloat operator + (nfloat l, nfloat r) { return new nfloat (l.v + r.v); }
2823 public static nfloat operator - (nfloat l, nfloat r) { return new nfloat (l.v - r.v); }
2824 public static nfloat operator * (nfloat l, nfloat r) { return new nfloat (l.v * r.v); }
2825 public static nfloat operator / (nfloat l, nfloat r) { return new nfloat (l.v / r.v); }
2826 public static nfloat operator % (nfloat l, nfloat r) { return new nfloat (l.v % r.v); }
2827 #endif
2829 #if NINT_JIT_OPTIMIZED
2830 public static bool operator == (nfloat l, nfloat r) { throw new NotImplementedException (); }
2831 public static bool operator != (nfloat l, nfloat r) { throw new NotImplementedException (); }
2832 public static bool operator < (nfloat l, nfloat r) { throw new NotImplementedException (); }
2833 public static bool operator > (nfloat l, nfloat r) { throw new NotImplementedException (); }
2834 public static bool operator <= (nfloat l, nfloat r) { throw new NotImplementedException (); }
2835 public static bool operator >= (nfloat l, nfloat r) { throw new NotImplementedException (); }
2836 #else
2837 public static bool operator == (nfloat l, nfloat r) { return l.v == r.v; }
2838 public static bool operator != (nfloat l, nfloat r) { return l.v != r.v; }
2839 public static bool operator < (nfloat l, nfloat r) { return l.v < r.v; }
2840 public static bool operator > (nfloat l, nfloat r) { return l.v > r.v; }
2841 public static bool operator <= (nfloat l, nfloat r) { return l.v <= r.v; }
2842 public static bool operator >= (nfloat l, nfloat r) { return l.v >= r.v; }
2843 #endif
2845 public int CompareTo (nfloat value) { return v.CompareTo (value.v); }
2846 public int CompareTo (object value)
2848 if (value is nfloat)
2849 return v.CompareTo (((nfloat) value).v);
2850 return v.CompareTo (value);
2852 public bool Equals (nfloat obj) { return v.Equals (obj.v); }
2853 public override bool Equals (object obj)
2855 if (obj is nfloat)
2856 return v.Equals (((nfloat) obj).v);
2857 return v.Equals (obj);
2859 public override int GetHashCode () { return v.GetHashCode (); }
2861 #if ARCH_32
2862 public static bool IsNaN (nfloat f) { return Single.IsNaN ((Single)f); }
2863 public static bool IsInfinity (nfloat f) { return Single.IsInfinity ((Single)f); }
2864 public static bool IsPositiveInfinity (nfloat f) { return Single.IsPositiveInfinity ((Single)f); }
2865 public static bool IsNegativeInfinity (nfloat f) { return Single.IsNegativeInfinity ((Single)f); }
2867 public static nfloat Parse (string s, IFormatProvider provider) { return (nfloat)Single.Parse (s, provider); }
2868 public static nfloat Parse (string s, NumberStyles style) { return (nfloat)Single.Parse (s, style); }
2869 public static nfloat Parse (string s) { return (nfloat)Single.Parse (s); }
2870 public static nfloat Parse (string s, NumberStyles style, IFormatProvider provider) {
2871 return (nfloat)Single.Parse (s, style, provider);
2874 public static bool TryParse (string s, out nfloat result)
2876 Single v;
2877 var r = Single.TryParse (s, out v);
2878 result = (nfloat)v;
2879 return r;
2882 public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nfloat result)
2884 Single v;
2885 var r = Single.TryParse (s, style, provider, out v);
2886 result = (nfloat)v;
2887 return r;
2889 #else
2890 public static bool IsNaN (nfloat f) { return Double.IsNaN ((Double)f); }
2891 public static bool IsInfinity (nfloat f) { return Double.IsInfinity ((Double)f); }
2892 public static bool IsPositiveInfinity (nfloat f) { return Double.IsPositiveInfinity ((Double)f); }
2893 public static bool IsNegativeInfinity (nfloat f) { return Double.IsNegativeInfinity ((Double)f); }
2895 public static nfloat Parse (string s, IFormatProvider provider) { return (nfloat)Double.Parse (s, provider); }
2896 public static nfloat Parse (string s, NumberStyles style) { return (nfloat)Double.Parse (s, style); }
2897 public static nfloat Parse (string s) { return (nfloat)Double.Parse (s); }
2898 public static nfloat Parse (string s, NumberStyles style, IFormatProvider provider) {
2899 return (nfloat)Double.Parse (s, style, provider);
2902 public static bool TryParse (string s, out nfloat result)
2904 Double v;
2905 var r = Double.TryParse (s, out v);
2906 result = (nfloat)v;
2907 return r;
2910 public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nfloat result)
2912 Double v;
2913 var r = Double.TryParse (s, style, provider, out v);
2914 result = (nfloat)v;
2915 return r;
2917 #endif
2919 public override string ToString () { return v.ToString (); }
2920 public string ToString (IFormatProvider provider) { return v.ToString (provider); }
2921 public string ToString (string format) { return v.ToString (format); }
2922 public string ToString (string format, IFormatProvider provider) { return v.ToString (format, provider); }
2924 public TypeCode GetTypeCode () { return v.GetTypeCode (); }
2926 bool IConvertible.ToBoolean (IFormatProvider provider) { return ((IConvertible)v).ToBoolean (provider); }
2927 byte IConvertible.ToByte (IFormatProvider provider) { return ((IConvertible)v).ToByte (provider); }
2928 char IConvertible.ToChar (IFormatProvider provider) { return ((IConvertible)v).ToChar (provider); }
2929 DateTime IConvertible.ToDateTime (IFormatProvider provider) { return ((IConvertible)v).ToDateTime (provider); }
2930 decimal IConvertible.ToDecimal (IFormatProvider provider) { return ((IConvertible)v).ToDecimal (provider); }
2931 double IConvertible.ToDouble (IFormatProvider provider) { return ((IConvertible)v).ToDouble (provider); }
2932 short IConvertible.ToInt16 (IFormatProvider provider) { return ((IConvertible)v).ToInt16 (provider); }
2933 int IConvertible.ToInt32 (IFormatProvider provider) { return ((IConvertible)v).ToInt32 (provider); }
2934 long IConvertible.ToInt64 (IFormatProvider provider) { return ((IConvertible)v).ToInt64 (provider); }
2935 sbyte IConvertible.ToSByte (IFormatProvider provider) { return ((IConvertible)v).ToSByte (provider); }
2936 float IConvertible.ToSingle (IFormatProvider provider) { return ((IConvertible)v).ToSingle (provider); }
2937 ushort IConvertible.ToUInt16 (IFormatProvider provider) { return ((IConvertible)v).ToUInt16 (provider); }
2938 uint IConvertible.ToUInt32 (IFormatProvider provider) { return ((IConvertible)v).ToUInt32 (provider); }
2939 ulong IConvertible.ToUInt64 (IFormatProvider provider) { return ((IConvertible)v).ToUInt64 (provider); }
2941 object IConvertible.ToType (Type targetType, IFormatProvider provider) {
2942 return ((IConvertible)v).ToType (targetType, provider);
2945 public static void CopyArray (IntPtr source, nfloat [] destination, int startIndex, int length)
2947 if (source == IntPtr.Zero)
2948 throw new ArgumentNullException ("source");
2949 if (destination == null)
2950 throw new ArgumentNullException ("destination");
2951 if (destination.Rank != 1)
2952 throw new ArgumentException ("destination", "array is multi-dimensional");
2953 if (startIndex < 0)
2954 throw new ArgumentException ("startIndex", "must be >= 0");
2955 if (length < 0)
2956 throw new ArgumentException ("length", "must be >= 0");
2957 if (startIndex + length > destination.Length)
2958 throw new ArgumentException ("length", "startIndex + length > destination.Length");
2960 for (int i = 0; i < length; i++)
2961 destination [i + startIndex] = (nfloat)Marshal.ReadIntPtr (source, i * nfloat.Size);
2964 public static void CopyArray (nfloat [] source, int startIndex, IntPtr destination, int length)
2966 if (source == null)
2967 throw new ArgumentNullException ("source");
2968 if (destination == IntPtr.Zero)
2969 throw new ArgumentNullException ("destination");
2970 if (source.Rank != 1)
2971 throw new ArgumentException ("source", "array is multi-dimensional");
2972 if (startIndex < 0)
2973 throw new ArgumentException ("startIndex", "must be >= 0");
2974 if (length < 0)
2975 throw new ArgumentException ("length", "must be >= 0");
2976 if (startIndex + length > source.Length)
2977 throw new ArgumentException ("length", "startIndex + length > source.Length");
2979 for (int i = 0; i < length; i++)
2980 Marshal.WriteIntPtr (destination, i * nfloat.Size, (IntPtr)source [i + startIndex]);