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.
8 // #define NINT_JIT_OPTIMIZED
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);
23 var z
= new nint (new nint (20));
33 static int test_0_nint_casts ()
52 static int test_0_nint_plus ()
61 static int test_0_nint_neg ()
70 static int test_0_nint_comp ()
79 static int test_0_nint_inc ()
88 static int test_0_nint_dec ()
97 static int test_0_nint_add ()
107 static int test_0_nint_sub ()
117 static int test_0_nint_mul ()
127 static int test_0_nint_div ()
137 static int test_0_nint_rem ()
147 static int test_0_nint_and ()
157 static int test_0_nint_or ()
167 static int test_0_nint_xor ()
177 static int test_0_nint_shl ()
186 static int test_0_nint_shr ()
195 static int test_0_nint_cmp_same_val ()
214 static int test_0_nint_cmp_small_val ()
233 static int test_0_nint_cmp_large_val ()
252 static int test_0_nint_compareto ()
254 if (((nint
) 0).CompareTo ((nint
) 0) != 0)
256 if (((nint
) 0).CompareTo ((nint
) 1) != -1)
258 if (((nint
) 1).CompareTo ((nint
) 0) != 1)
261 if (((nint
) 0).CompareTo ((object)(nint
) 0) != 0)
263 if (((nint
) 0).CompareTo ((object)(nint
) 1) != -1)
265 if (((nint
) 1).CompareTo ((object)(nint
) 0) != 1)
268 if (((nint
) 1).CompareTo (null) != 1)
274 static int test_0_nint_call_boxed_equals ()
276 object x
= new nint (10);
277 object y
= new nint (10);
283 static int test_0_nint_equals ()
285 if (!((nint
) 0).Equals ((nint
) 0))
287 if (!((nint
) 0).Equals ((object) (nint
) 0))
289 if (((nint
) 0).Equals (null))
294 private sealed class MyGenericEqualityComparer
<T
> : EqualityComparer
<T
> where T
: IEquatable
<T
>
296 public sealed override bool Equals(T x
, T y
) {
307 public sealed override int GetHashCode(T obj
)
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))
320 if (!cmp
.Equals ((nint
) 4, (nint
) 4))
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)
331 if (x
.ToString () != "10")
336 static int test_0_nint_tostring ()
339 if (((nint
) x
).ToString () != "1337")
342 if (((nint
) x
).ToString () != "-1337")
348 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
349 static bool decimal_cmp (decimal a
, decimal b
)
354 static bool decimal_cmp_can_inline (decimal a
, decimal 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
))
366 if (!decimal_cmp (a
, b
))
368 if (!decimal_cmp ((nint
) 10, b
))
370 if (!decimal_cmp (a
, (nint
) 10))
375 static int test_0_nint_unboxed_member_calls ()
382 if (x
!= nint
.Parse ("10"))
387 struct SomeNativeStructWithNint
{
389 public static nint b
;
391 public SomeNativeStructWithNint (nint a
)
397 public static nint
GetAStatic (SomeNativeStructWithNint x
)
408 class SomeClassWithNint
{
411 public SomeClassWithNint (nint a
)
416 public virtual nint
GetAVirtual ()
422 static int test_0_nint_fieldload ()
424 var x
= new SomeNativeStructWithNint ((nint
) 20f
);
426 if ((float) x
.a
!= 20f
)
432 if ((float) SomeNativeStructWithNint
.GetAStatic (x
) != 20f
)
435 if ((float) x
.GetA () != 20f
)
438 if ((int) SomeNativeStructWithNint
.GetAStatic (x
) != 20)
441 if ((int) x
.GetA () != 20)
444 if ((float) SomeNativeStructWithNint
.b
!= 21f
)
447 if ((int) SomeNativeStructWithNint
.b
!= 21)
450 SomeClassWithNint y
= new SomeClassWithNint ((nint
) 30f
);
452 if ((int) y
.GetAVirtual () != 30)
455 if ((float) y
.GetAVirtual () != 30f
)
461 static int NuintConstructor (nuint cap
)
463 if (cap
> (ulong) nint
.MaxValue
)
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)
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));
494 static int test_0_nuint_casts ()
513 static int test_0_nuint_plus ()
522 // static int test_0_nuint_neg ()
524 // var x = (nuint)10;
526 // if ((uint)z != -10)
531 static int test_0_nuint_comp ()
540 static int test_0_nuint_inc ()
549 static int test_0_nuint_dec ()
558 static int test_0_nuint_add ()
568 static int test_0_nuint_sub ()
578 static int test_0_nuint_mul ()
588 static int test_0_nuint_div ()
598 static int test_0_nuint_rem ()
608 static int test_0_nuint_and ()
618 static int test_0_nuint_or ()
628 static int test_0_nuint_xor ()
638 static int test_0_nuint_shl ()
647 static int test_0_nuint_shr ()
656 static int test_0_nuint_cmp_same_val ()
675 static int test_0_nuint_cmp_small_val ()
694 static int test_0_nuint_cmp_large_val ()
713 static int test_0_nuint_compareto ()
715 if (((nuint
) 0).CompareTo ((nuint
) 0) != 0)
717 if (((nuint
) 0).CompareTo ((nuint
) 1) != -1)
719 if (((nuint
) 1).CompareTo ((nuint
) 0) != 1)
722 if (((nuint
) 0).CompareTo ((object)(nuint
) 0) != 0)
724 if (((nuint
) 0).CompareTo ((object)(nuint
) 1) != -1)
726 if (((nuint
) 1).CompareTo ((object)(nuint
) 0) != 1)
729 if (((nuint
) 1).CompareTo (null) != 1)
735 static int test_0_nuint_call_boxed_equals ()
737 object x
= new nuint (10);
738 object y
= new nuint (10);
744 static int test_0_nuint_equals ()
746 if (!((nuint
) 0).Equals ((nuint
) 0))
748 if (!((nuint
) 0).Equals ((object) (nuint
) 0))
750 if (((nuint
) 0).Equals (null))
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)
761 if (x
.ToString () != "10")
766 static int test_0_nuint_tostring ()
769 if (((nuint
) x
).ToString () != "1337")
772 if (((nuint
) x
).ToString () == "-1337")
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
))
785 if (!decimal_cmp (a
, b
))
787 if (!decimal_cmp ((nuint
) 10, b
))
789 if (!decimal_cmp (a
, (nuint
) 10))
794 static int test_0_nuint_unboxed_member_calls ()
801 if (x
!= nuint
.Parse ("10"))
806 struct SomeNativeStructWithNuint
{
808 public static nuint b
;
810 public SomeNativeStructWithNuint (nuint a
)
816 public static nuint
GetAStatic (SomeNativeStructWithNuint x
)
827 class SomeClassWithNuint
{
830 public SomeClassWithNuint (nuint a
)
835 public virtual nuint
GetAVirtual ()
841 static int test_0_nuint_fieldload ()
843 var x
= new SomeNativeStructWithNuint ((nuint
) 20f
);
845 if ((float) x
.a
!= 20f
)
851 if ((float) SomeNativeStructWithNuint
.GetAStatic (x
) != 20f
)
854 if ((float) x
.GetA () != 20f
)
857 if ((int) SomeNativeStructWithNuint
.GetAStatic (x
) != 20)
860 if ((int) x
.GetA () != 20)
863 if (!decimal_cmp_can_inline ((int) x
.GetA (), 20))
866 if ((float) SomeNativeStructWithNuint
.b
!= 21f
)
869 if ((int) SomeNativeStructWithNuint
.b
!= 21)
872 SomeClassWithNuint y
= new SomeClassWithNuint ((nuint
) 30f
);
874 if ((int) y
.GetAVirtual () != 30)
877 if ((float) y
.GetAVirtual () != 30f
)
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
));
897 static int test_0_nfloat_casts ()
913 if ((nfloat
) z
!= 30f
)
921 static int test_0_nfloat_plus ()
930 static int test_0_nfloat_neg ()
934 if ((float)z
!= -10f
)
940 static int test_0_nfloat_inc ()
944 if ((float)x
!= 11f
) {
945 Console
.WriteLine ((float)x
);
951 static int test_0_nfloat_dec ()
955 if ((float)x
!= 9f
) {
956 Console
.WriteLine ((float)x
);
963 static int test_0_nfloat_add ()
973 static int test_0_nfloat_sub ()
978 if ((float)z
!= -10f
)
983 static int test_0_nfloat_mul ()
988 if ((float)z
!= 200f
)
993 static int test_0_nfloat_div ()
1003 static int test_0_nfloat_rem ()
1005 var x
= (nfloat
)22f
;
1006 var y
= (nfloat
)10f
;
1013 static int test_0_nfloat_cmp_same_val ()
1015 var x
= (nfloat
)10f
;
1016 var y
= (nfloat
)10f
;
1032 static int test_0_nfloat_cmp_small_val ()
1035 var y
= (nfloat
)10f
;
1051 static int test_0_nfloat_cmp_large_val ()
1053 var x
= (nfloat
)20f
;
1054 var y
= (nfloat
)10f
;
1070 /* fails on arm64 */
1071 static int test_0_nfloat_cmp_left_nan ()
1073 var x
= (nfloat
)float.NaN
;
1074 var y
= (nfloat
)10f
;
1091 static int test_0_nfloat_cmp_right_nan ()
1093 var x
= (nfloat
)10f
;
1094 var y
= (nfloat
)float.NaN
;
1110 static int test_0_nfloat_isinfinity ()
1112 var x
= (nfloat
) float.NaN
;
1113 if (nfloat
.IsInfinity (x
))
1115 if (nfloat
.IsInfinity (12))
1117 if (!nfloat
.IsInfinity (nfloat
.PositiveInfinity
))
1119 if (!nfloat
.IsInfinity (nfloat
.NegativeInfinity
))
1125 static int test_0_nfloat_isnegativeinfinity ()
1127 var x
= (nfloat
) float.NaN
;
1128 if (nfloat
.IsNegativeInfinity (x
))
1130 if (nfloat
.IsNegativeInfinity (12))
1132 if (nfloat
.IsNegativeInfinity (nfloat
.PositiveInfinity
))
1134 if (!nfloat
.IsNegativeInfinity (nfloat
.NegativeInfinity
))
1137 float f
= float.NegativeInfinity
;
1138 nfloat n
= (nfloat
) f
;
1139 if (!nfloat
.IsNegativeInfinity (n
))
1142 double d
= double.NegativeInfinity
;
1144 if (!nfloat
.IsNegativeInfinity (n
))
1150 static int test_0_nfloat_ispositiveinfinity ()
1152 var x
= (nfloat
) float.NaN
;
1153 if (nfloat
.IsPositiveInfinity (x
))
1155 if (nfloat
.IsPositiveInfinity (12))
1157 if (!nfloat
.IsPositiveInfinity (nfloat
.PositiveInfinity
))
1159 if (nfloat
.IsPositiveInfinity (nfloat
.NegativeInfinity
))
1162 float f
= float.PositiveInfinity
;
1163 nfloat n
= (nfloat
) f
;
1164 if (!nfloat
.IsPositiveInfinity (n
))
1167 double d
= double.PositiveInfinity
;
1169 if (!nfloat
.IsPositiveInfinity (n
))
1175 static int test_0_nfloat_isnan ()
1177 var x
= (nfloat
) float.NaN
;
1178 if (!nfloat
.IsNaN (x
))
1180 if (nfloat
.IsNaN (12))
1182 if (nfloat
.IsNaN (nfloat
.PositiveInfinity
))
1184 if (nfloat
.IsNaN (nfloat
.NegativeInfinity
))
1187 float f
= float.NaN
;
1188 nfloat n
= (nfloat
) f
;
1189 if (!nfloat
.IsNaN (n
))
1192 double d
= double.NaN
;
1194 if (!nfloat
.IsNaN (n
))
1200 static int test_0_nfloat_compareto ()
1202 if (((nfloat
) 0).CompareTo ((nfloat
) 0) != 0)
1204 if (((nfloat
) 0).CompareTo ((nfloat
) 1) != -1)
1206 if (((nfloat
) 1).CompareTo ((nfloat
) 0) != 1)
1209 if (((nfloat
) 0).CompareTo ((object)(nfloat
) 0) != 0)
1211 if (((nfloat
) 0).CompareTo ((object)(nfloat
) 1) != -1)
1213 if (((nfloat
) 1).CompareTo ((object)(nfloat
) 0) != 1)
1216 if (((nfloat
) 1).CompareTo (null) != 1)
1222 static int test_0_nfloat_call_boxed_equals ()
1224 object x
= new nfloat (10f
);
1225 object y
= new nfloat (10f
);
1231 static int test_0_nfloat_equals ()
1233 if (!((nfloat
) 0).Equals ((nfloat
) 0))
1235 if (!((nfloat
) 0).Equals ((object) (nfloat
) 0))
1237 if (((nfloat
) 0).Equals (null))
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)
1248 if (x
.ToString () != "10")
1253 static int test_0_nfloat_tostring ()
1256 nfloat y
= (nfloat
) x
;
1257 if (y
.ToString () != "1337")
1260 if (((nfloat
) x
).ToString () != "-1337")
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
))
1273 if (!decimal_cmp ((decimal) a
, (decimal) b
))
1275 if (!decimal_cmp ((decimal) (nfloat
) 10.0f
, (decimal) b
))
1277 if (!decimal_cmp ((decimal) a
, (decimal) (nfloat
) 10.0f
))
1282 static int test_0_nfloat_unboxed_member_calls ()
1284 var x
= (nfloat
)10f
;
1289 if (x
!= nfloat
.Parse ("10"))
1294 struct SomeNativeStructWithNfloat
{
1296 public static nfloat b
;
1298 public SomeNativeStructWithNfloat (nfloat a
)
1304 public static nfloat
GetAStatic (SomeNativeStructWithNfloat x
)
1309 public nfloat
GetA ()
1315 class SomeClassWithNfloat
{
1318 public SomeClassWithNfloat (nfloat a
)
1323 public virtual nfloat
GetAVirtual ()
1329 static int test_0_nfloat_fieldload ()
1331 var x
= new SomeNativeStructWithNfloat ((nfloat
) 20f
);
1333 if ((float) x
.a
!= 20f
)
1336 if ((int) x
.a
!= 20)
1339 if ((float) SomeNativeStructWithNfloat
.GetAStatic (x
) != 20f
)
1342 if ((float) x
.GetA () != 20f
)
1345 if ((int) SomeNativeStructWithNfloat
.GetAStatic (x
) != 20)
1348 if ((int) x
.GetA () != 20)
1351 if ((float) SomeNativeStructWithNfloat
.b
!= 21f
)
1354 if ((int) SomeNativeStructWithNfloat
.b
!= 21)
1357 SomeClassWithNfloat y
= new SomeClassWithNfloat ((nfloat
) 30f
);
1359 if ((int) y
.GetAVirtual () != 30)
1362 if ((float) y
.GetAVirtual () != 30f
)
1368 static int test_0_much_casting ()
1370 var notOof
= (int)(float)1;
1374 var notOof2
= (nint
)(float)(nfloat
)1;
1378 var notOof3
= (nint
)(int)(nfloat
)1;
1382 var oof
= (nint
)(nfloat
)1;
1383 var oof2
= (int) oof
- 1;
1387 var noof
= (nfloat
)(nint
)1;
1388 var noof2
= (float) noof
- 1;
1396 public static int Main (String
[] args
) {
1397 return TestDriver
.RunTests (typeof (BuiltinTests
), args
);
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:
1414 // Aaron Bockover <abock@xamarin.com>
1416 // Copyright 2013 Xamarin, Inc. All rights reserved.
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; }
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
)]
1437 public nint (Int64 v
) { this.v = (Int32)v; }
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
)]
1447 public nint (Int64 v
) { this.v = v; }
1450 public static explicit operator nint (nuint v
)
1452 #if NINT_JIT_OPTIMIZED
1453 throw new NotImplementedException ();
1455 return new nint ((int)v
.v
);
1457 return new nint ((long)v
.v
);
1461 public static explicit operator nuint (nint v
)
1463 #if NINT_JIT_OPTIMIZED
1464 throw new NotImplementedException ();
1466 return new nuint ((uint)v
.v
);
1468 return new nuint ((ulong)v
.v
);
1472 public static explicit operator nint (nfloat v
)
1474 #if NINT_JIT_OPTIMIZED
1475 throw new NotImplementedException ();
1477 return new nint ((int)v
.v
);
1479 return new nint ((long)v
.v
);
1483 public static implicit operator nfloat (nint v
)
1485 #if NINT_JIT_OPTIMIZED
1486 throw new NotImplementedException ();
1488 return new nfloat ((float)v
.v
);
1490 return new nfloat ((double)v
.v
);
1494 public static explicit operator nint (IntPtr v
)
1496 #if NINT_JIT_OPTIMIZED
1497 throw new NotImplementedException ();
1499 return new nint (*((int *)&v
));
1501 return new nint (*((long *)&v
));
1505 public static explicit operator IntPtr (nint v
)
1507 #if NINT_JIT_OPTIMIZED
1508 throw new NotImplementedException ();
1510 return *((IntPtr
*)&v
.v
);
1512 return *((IntPtr
*)&v
.v
);
1516 public static implicit operator nint (sbyte v
)
1518 #if NINT_JIT_OPTIMIZED
1519 throw new NotImplementedException ();
1521 return new nint ((int)v
);
1523 return new nint ((long)v
);
1527 public static explicit operator sbyte (nint v
)
1529 #if NINT_JIT_OPTIMIZED
1530 throw new NotImplementedException ();
1538 public static implicit operator nint (byte v
)
1540 #if NINT_JIT_OPTIMIZED
1541 throw new NotImplementedException ();
1543 return new nint ((int)v
);
1545 return new nint ((long)v
);
1549 public static explicit operator byte (nint v
)
1551 #if NINT_JIT_OPTIMIZED
1552 throw new NotImplementedException ();
1560 public static implicit operator nint (char v
)
1562 #if NINT_JIT_OPTIMIZED
1563 throw new NotImplementedException ();
1565 return new nint ((int)v
);
1567 return new nint ((long)v
);
1571 public static explicit operator char (nint v
)
1573 #if NINT_JIT_OPTIMIZED
1574 throw new NotImplementedException ();
1582 public static implicit operator nint (short v
)
1584 #if NINT_JIT_OPTIMIZED
1585 throw new NotImplementedException ();
1587 return new nint ((int)v
);
1589 return new nint ((long)v
);
1593 public static explicit operator short (nint v
)
1595 #if NINT_JIT_OPTIMIZED
1596 throw new NotImplementedException ();
1604 public static explicit operator nint (ushort v
)
1606 #if NINT_JIT_OPTIMIZED
1607 throw new NotImplementedException ();
1609 return new nint ((int)v
);
1611 return new nint ((long)v
);
1615 public static explicit operator ushort (nint v
)
1617 #if NINT_JIT_OPTIMIZED
1618 throw new NotImplementedException ();
1626 public static implicit operator nint (int v
)
1628 #if NINT_JIT_OPTIMIZED
1629 throw new NotImplementedException ();
1631 return new nint ((int)v
);
1633 return new nint ((long)v
);
1637 public static explicit operator int (nint v
)
1639 #if NINT_JIT_OPTIMIZED
1640 throw new NotImplementedException ();
1648 public static explicit operator nint (uint v
)
1650 #if NINT_JIT_OPTIMIZED
1651 throw new NotImplementedException ();
1653 return new nint ((int)v
);
1655 return new nint ((long)v
);
1659 public static explicit operator uint (nint v
)
1661 #if NINT_JIT_OPTIMIZED
1662 throw new NotImplementedException ();
1670 public static implicit operator nint (long v
)
1672 #if NINT_JIT_OPTIMIZED
1673 throw new NotImplementedException ();
1675 return new nint ((int)v
);
1677 return new nint ((long)v
);
1681 public static implicit operator long (nint v
)
1683 #if NINT_JIT_OPTIMIZED
1684 throw new NotImplementedException ();
1692 public static explicit operator nint (ulong v
)
1694 #if NINT_JIT_OPTIMIZED
1695 throw new NotImplementedException ();
1697 return new nint ((int)v
);
1699 return new nint ((long)v
);
1703 public static explicit operator ulong (nint v
)
1705 #if NINT_JIT_OPTIMIZED
1706 throw new NotImplementedException ();
1714 public static explicit operator nint (float v
)
1716 #if NINT_JIT_OPTIMIZED
1717 throw new NotImplementedException ();
1719 return new nint ((int)v
);
1721 return new nint ((long)v
);
1725 public static implicit operator float (nint v
)
1727 #if NINT_JIT_OPTIMIZED
1728 throw new NotImplementedException ();
1736 public static explicit operator nint (double v
)
1738 #if NINT_JIT_OPTIMIZED
1739 throw new NotImplementedException ();
1741 return new nint ((int)v
);
1743 return new nint ((long)v
);
1747 public static implicit operator double (nint v
)
1749 #if NINT_JIT_OPTIMIZED
1750 throw new NotImplementedException ();
1758 public static explicit operator nint (decimal v
)
1760 #if NINT_JIT_OPTIMIZED
1761 throw new NotImplementedException ();
1763 return new nint ((int)v
);
1765 return new nint ((long)v
);
1769 public static implicit operator decimal (nint v
)
1771 #if NINT_JIT_OPTIMIZED
1772 throw new NotImplementedException ();
1774 return (decimal)v
.v
;
1776 return (decimal)v
.v
;
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 (); }
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); }
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 (); }
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); }
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 (); }
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; }
1833 public int CompareTo (nint
value) { return v.CompareTo (value.v); }
1834 public int CompareTo (object value)
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
)
1844 return v
.Equals (((nint
) obj
).v
);
1845 return v
.Equals (obj
);
1847 public override int GetHashCode () { return v.GetHashCode (); }
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
)
1860 var r
= Int32
.TryParse (s
, out v
);
1865 public static bool TryParse (string s
, NumberStyles style
, IFormatProvider provider
, out nint result
)
1868 var r
= Int32
.TryParse (s
, style
, provider
, out v
);
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
)
1883 var r
= Int64
.TryParse (s
, out v
);
1888 public static bool TryParse (string s
, NumberStyles style
, IFormatProvider provider
, out nint result
)
1891 var r
= Int64
.TryParse (s
, style
, provider
, out v
);
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");
1932 throw new ArgumentException ("startIndex", "must be >= 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
)
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");
1951 throw new ArgumentException ("startIndex", "must be >= 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
]);
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; }
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
)]
1977 public nuint (UInt64 v
) { this.v = (UInt32)v; }
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
)]
1987 public nuint (UInt64 v
) { this.v = v; }
1990 public static explicit operator nuint (nfloat v
)
1992 #if NINT_JIT_OPTIMIZED
1993 throw new NotImplementedException ();
1995 return new nuint ((uint)v
.v
);
1997 return new nuint ((ulong)v
.v
);
2001 public static implicit operator nfloat (nuint v
)
2003 #if NINT_JIT_OPTIMIZED
2004 throw new NotImplementedException ();
2006 return new nfloat ((float)v
.v
);
2008 return new nfloat ((double)v
.v
);
2012 public static explicit operator nuint (IntPtr v
)
2014 #if NINT_JIT_OPTIMIZED
2015 throw new NotImplementedException ();
2017 return new nuint (*((uint *)&v
));
2019 return new nuint (*((ulong *)&v
));
2023 public static explicit operator IntPtr (nuint v
)
2025 #if NINT_JIT_OPTIMIZED
2026 throw new NotImplementedException ();
2028 return *((IntPtr
*)&v
.v
);
2030 return *((IntPtr
*)&v
.v
);
2034 public static explicit operator nuint (sbyte v
)
2036 #if NINT_JIT_OPTIMIZED
2037 throw new NotImplementedException ();
2039 return new nuint ((uint)v
);
2041 return new nuint ((ulong)v
);
2045 public static explicit operator sbyte (nuint v
)
2047 #if NINT_JIT_OPTIMIZED
2048 throw new NotImplementedException ();
2056 public static implicit operator nuint (byte v
)
2058 #if NINT_JIT_OPTIMIZED
2059 throw new NotImplementedException ();
2061 return new nuint ((uint)v
);
2063 return new nuint ((ulong)v
);
2067 public static explicit operator byte (nuint v
)
2069 #if NINT_JIT_OPTIMIZED
2070 throw new NotImplementedException ();
2078 public static implicit operator nuint (char v
)
2080 #if NINT_JIT_OPTIMIZED
2081 throw new NotImplementedException ();
2083 return new nuint ((uint)v
);
2085 return new nuint ((ulong)v
);
2089 public static explicit operator char (nuint v
)
2091 #if NINT_JIT_OPTIMIZED
2092 throw new NotImplementedException ();
2100 public static explicit operator nuint (short v
)
2102 #if NINT_JIT_OPTIMIZED
2103 throw new NotImplementedException ();
2105 return new nuint ((uint)v
);
2107 return new nuint ((ulong)v
);
2111 public static explicit operator short (nuint v
)
2113 #if NINT_JIT_OPTIMIZED
2114 throw new NotImplementedException ();
2122 public static implicit operator nuint (ushort v
)
2124 #if NINT_JIT_OPTIMIZED
2125 throw new NotImplementedException ();
2127 return new nuint ((uint)v
);
2129 return new nuint ((ulong)v
);
2133 public static explicit operator ushort (nuint v
)
2135 #if NINT_JIT_OPTIMIZED
2136 throw new NotImplementedException ();
2144 public static explicit operator nuint (int v
)
2146 #if NINT_JIT_OPTIMIZED
2147 throw new NotImplementedException ();
2149 return new nuint ((uint)v
);
2151 return new nuint ((ulong)v
);
2155 public static explicit operator int (nuint v
)
2157 #if NINT_JIT_OPTIMIZED
2158 throw new NotImplementedException ();
2166 public static implicit operator nuint (uint v
)
2168 #if NINT_JIT_OPTIMIZED
2169 throw new NotImplementedException ();
2171 return new nuint ((uint)v
);
2173 return new nuint ((ulong)v
);
2177 public static explicit operator uint (nuint v
)
2179 #if NINT_JIT_OPTIMIZED
2180 throw new NotImplementedException ();
2188 public static explicit operator nuint (long v
)
2190 #if NINT_JIT_OPTIMIZED
2191 throw new NotImplementedException ();
2193 return new nuint ((uint)v
);
2195 return new nuint ((ulong)v
);
2199 public static explicit operator long (nuint v
)
2201 #if NINT_JIT_OPTIMIZED
2202 throw new NotImplementedException ();
2210 public static implicit operator nuint (ulong v
)
2212 #if NINT_JIT_OPTIMIZED
2213 throw new NotImplementedException ();
2215 return new nuint ((uint)v
);
2217 return new nuint ((ulong)v
);
2221 public static implicit operator ulong (nuint v
)
2223 #if NINT_JIT_OPTIMIZED
2224 throw new NotImplementedException ();
2232 public static explicit operator nuint (float v
)
2234 #if NINT_JIT_OPTIMIZED
2235 throw new NotImplementedException ();
2237 return new nuint ((uint)v
);
2239 return new nuint ((ulong)v
);
2243 public static implicit operator float (nuint v
)
2245 #if NINT_JIT_OPTIMIZED
2246 throw new NotImplementedException ();
2254 public static explicit operator nuint (double v
)
2256 #if NINT_JIT_OPTIMIZED
2257 throw new NotImplementedException ();
2259 return new nuint ((uint)v
);
2261 return new nuint ((ulong)v
);
2265 public static implicit operator double (nuint v
)
2267 #if NINT_JIT_OPTIMIZED
2268 throw new NotImplementedException ();
2276 public static explicit operator nuint (decimal v
)
2278 #if NINT_JIT_OPTIMIZED
2279 throw new NotImplementedException ();
2281 return new nuint ((uint)v
);
2283 return new nuint ((ulong)v
);
2287 public static implicit operator decimal (nuint v
)
2289 #if NINT_JIT_OPTIMIZED
2290 throw new NotImplementedException ();
2292 return (decimal)v
.v
;
2294 return (decimal)v
.v
;
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 (); }
2302 public static nuint
operator + (nuint v
) { return new nuint (+v.v); }
2303 public static nuint
operator ~
(nuint v
) { return new nuint (~v.v); }
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 (); }
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); }
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 (); }
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; }
2348 public int CompareTo (nuint
value) { return v.CompareTo (value.v); }
2349 public int CompareTo (object value)
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
)
2359 return v
.Equals (((nuint
) obj
).v
);
2360 return v
.Equals (obj
);
2362 public override int GetHashCode () { return v.GetHashCode (); }
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
)
2375 var r
= UInt32
.TryParse (s
, out v
);
2380 public static bool TryParse (string s
, NumberStyles style
, IFormatProvider provider
, out nuint result
)
2383 var r
= UInt32
.TryParse (s
, style
, provider
, out v
);
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
)
2398 var r
= UInt64
.TryParse (s
, out v
);
2403 public static bool TryParse (string s
, NumberStyles style
, IFormatProvider provider
, out nuint result
)
2406 var r
= UInt64
.TryParse (s
, style
, provider
, out v
);
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");
2447 throw new ArgumentException ("startIndex", "must be >= 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
)
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");
2466 throw new ArgumentException ("startIndex", "must be >= 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
]);
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; }
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
)]
2496 public nfloat (Double v
) { this.v = (Single)v; }
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
)]
2510 public nfloat (Double v
) { this.v = v; }
2513 public static explicit operator nfloat (IntPtr v
)
2515 #if NINT_JIT_OPTIMIZED
2516 throw new NotImplementedException ();
2518 return new nfloat (*((float *)&v
));
2520 return new nfloat (*((double *)&v
));
2524 public static explicit operator IntPtr (nfloat v
)
2526 #if NINT_JIT_OPTIMIZED
2527 throw new NotImplementedException ();
2529 return *((IntPtr
*)&v
.v
);
2531 return *((IntPtr
*)&v
.v
);
2535 public static implicit operator nfloat (sbyte v
)
2537 #if NINT_JIT_OPTIMIZED
2538 throw new NotImplementedException ();
2540 return new nfloat ((float)v
);
2542 return new nfloat ((double)v
);
2546 public static explicit operator sbyte (nfloat v
)
2548 #if NINT_JIT_OPTIMIZED
2549 throw new NotImplementedException ();
2557 public static implicit operator nfloat (byte v
)
2559 #if NINT_JIT_OPTIMIZED
2560 throw new NotImplementedException ();
2562 return new nfloat ((float)v
);
2564 return new nfloat ((double)v
);
2568 public static explicit operator byte (nfloat v
)
2570 #if NINT_JIT_OPTIMIZED
2571 throw new NotImplementedException ();
2579 public static implicit operator nfloat (char v
)
2581 #if NINT_JIT_OPTIMIZED
2582 throw new NotImplementedException ();
2584 return new nfloat ((float)v
);
2586 return new nfloat ((double)v
);
2590 public static explicit operator char (nfloat v
)
2592 #if NINT_JIT_OPTIMIZED
2593 throw new NotImplementedException ();
2601 public static implicit operator nfloat (short v
)
2603 #if NINT_JIT_OPTIMIZED
2604 throw new NotImplementedException ();
2606 return new nfloat ((float)v
);
2608 return new nfloat ((double)v
);
2612 public static explicit operator short (nfloat v
)
2614 #if NINT_JIT_OPTIMIZED
2615 throw new NotImplementedException ();
2623 public static implicit operator nfloat (ushort v
)
2625 #if NINT_JIT_OPTIMIZED
2626 throw new NotImplementedException ();
2628 return new nfloat ((float)v
);
2630 return new nfloat ((double)v
);
2634 public static explicit operator ushort (nfloat v
)
2636 #if NINT_JIT_OPTIMIZED
2637 throw new NotImplementedException ();
2645 public static implicit operator nfloat (int v
)
2647 #if NINT_JIT_OPTIMIZED
2648 throw new NotImplementedException ();
2650 return new nfloat ((float)v
);
2652 return new nfloat ((double)v
);
2656 public static explicit operator int (nfloat v
)
2658 #if NINT_JIT_OPTIMIZED
2659 throw new NotImplementedException ();
2667 public static implicit operator nfloat (uint v
)
2669 #if NINT_JIT_OPTIMIZED
2670 throw new NotImplementedException ();
2672 return new nfloat ((float)v
);
2674 return new nfloat ((double)v
);
2678 public static explicit operator uint (nfloat v
)
2680 #if NINT_JIT_OPTIMIZED
2681 throw new NotImplementedException ();
2689 public static implicit operator nfloat (long v
)
2691 #if NINT_JIT_OPTIMIZED
2692 throw new NotImplementedException ();
2694 return new nfloat ((float)v
);
2696 return new nfloat ((double)v
);
2700 public static explicit operator long (nfloat v
)
2702 #if NINT_JIT_OPTIMIZED
2703 throw new NotImplementedException ();
2711 public static implicit operator nfloat (ulong v
)
2713 #if NINT_JIT_OPTIMIZED
2714 throw new NotImplementedException ();
2716 return new nfloat ((float)v
);
2718 return new nfloat ((double)v
);
2722 public static explicit operator ulong (nfloat v
)
2724 #if NINT_JIT_OPTIMIZED
2725 throw new NotImplementedException ();
2733 public static implicit operator nfloat (float v
)
2735 #if NINT_JIT_OPTIMIZED
2736 throw new NotImplementedException ();
2738 return new nfloat ((float)v
);
2740 return new nfloat ((double)v
);
2744 public static explicit operator float (nfloat v
)
2746 #if NINT_JIT_OPTIMIZED
2747 throw new NotImplementedException ();
2755 public static explicit operator nfloat (double v
)
2757 #if NINT_JIT_OPTIMIZED
2758 throw new NotImplementedException ();
2760 return new nfloat ((float)v
);
2762 return new nfloat ((double)v
);
2766 public static implicit operator double (nfloat v
)
2768 #if NINT_JIT_OPTIMIZED
2769 throw new NotImplementedException ();
2777 public static explicit operator nfloat (decimal v
)
2779 #if NINT_JIT_OPTIMIZED
2780 throw new NotImplementedException ();
2782 return new nfloat ((float)v
);
2784 return new nfloat ((double)v
);
2788 public static explicit operator decimal (nfloat v
)
2790 #if NINT_JIT_OPTIMIZED
2791 throw new NotImplementedException ();
2793 return (decimal)v
.v
;
2795 return (decimal)v
.v
;
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 (); }
2803 public static nfloat
operator + (nfloat v
) { return new nfloat (+v.v); }
2804 public static nfloat
operator - (nfloat v
) { return new nfloat (-v.v); }
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 (); }
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); }
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 (); }
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); }
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 (); }
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; }
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
)
2856 return v
.Equals (((nfloat
) obj
).v
);
2857 return v
.Equals (obj
);
2859 public override int GetHashCode () { return v.GetHashCode (); }
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
)
2877 var r
= Single
.TryParse (s
, out v
);
2882 public static bool TryParse (string s
, NumberStyles style
, IFormatProvider provider
, out nfloat result
)
2885 var r
= Single
.TryParse (s
, style
, provider
, out v
);
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
)
2905 var r
= Double
.TryParse (s
, out v
);
2910 public static bool TryParse (string s
, NumberStyles style
, IFormatProvider provider
, out nfloat result
)
2913 var r
= Double
.TryParse (s
, style
, provider
, out v
);
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");
2954 throw new ArgumentException ("startIndex", "must be >= 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
)
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");
2973 throw new ArgumentException ("startIndex", "must be >= 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
]);