Skip to content

Commit 1d8fc7c

Browse files
authored
Support Numeric IntPtr
1 parent 45a9e72 commit 1d8fc7c

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

standard/expressions.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ As an example of numeric promotion, consider the predefined implementations of t
287287
```csharp
288288
int operator *(int x, int y);
289289
uint operator *(uint x, uint y);
290+
nint operator *(nint x, nint y);
291+
nuint operator *(nuint x, nuint y);
290292
long operator *(long x, long y);
291293
ulong operator *(ulong x, ulong y);
292294
float operator *(float x, float y);
@@ -298,8 +300,6 @@ When overload resolution rules ([§12.6.4](expressions.md#1264-overload-resoluti
298300

299301
> *Example*: For the operation `b * s`, where `b` is a `byte` and `s` is a `short`, overload resolution selects `operator *(int, int)` as the best operator. Thus, the effect is that `b` and `s` are converted to `int`, and the type of the result is `int`. Likewise, for the operation `i * d`, where `i` is an `int` and `d` is a `double`, `overload` resolution selects `operator *(double, double)` as the best operator. *end example*
300302
301-
There are no predefined operators for dealing with native integer ([§8.3.6](types.md#836-integral-types)). Instead, `nint` and `nuint` values shall be promoted to `long` and `ulong`, respectively, and the resulting corresponding predefined operators used instead.
302-
303303
**End of informative text.**
304304

305305
#### 12.4.7.2 Unary numeric promotions
@@ -3733,6 +3733,8 @@ For an operation of the form `+x`, unary operator overload resolution ([§12.4.
37333733
```csharp
37343734
int operator +(int x);
37353735
uint operator +(uint x);
3736+
nint operator +(nint x);
3737+
nuint operator +(nuint x);
37363738
long operator +(long x);
37373739
ulong operator +(ulong x);
37383740
float operator +(float x);
@@ -3752,6 +3754,7 @@ For an operation of the form `–x`, unary operator overload resolution ([§12.
37523754

37533755
```csharp
37543756
int operator –(int x);
3757+
nint operator –(nint x);
37553758
long operator –(long x);
37563759
```
37573760

@@ -3801,6 +3804,8 @@ For an operation of the form `~x`, unary operator overload resolution ([§12.4.4
38013804
```csharp
38023805
int operator ~(int x);
38033806
uint operator ~(uint x);
3807+
nint operator ~(nint x);
3808+
nuint operator ~(nuint x);
38043809
long operator ~(long x);
38053810
ulong operator ~(ulong x);
38063811
```
@@ -4146,6 +4151,8 @@ The predefined multiplication operators are listed below. The operators all comp
41464151
```csharp
41474152
int operator *(int x, int y);
41484153
uint operator *(uint x, uint y);
4154+
nint operator *(nint x, nint y);
4155+
nuint operator *(nuint x, nuint y);
41494156
long operator *(long x, long y);
41504157
ulong operator *(ulong x, ulong y);
41514158
```
@@ -4193,6 +4200,8 @@ The predefined division operators are listed below. The operators all compute th
41934200
```csharp
41944201
int operator /(int x, int y);
41954202
uint operator /(uint x, uint y);
4203+
nint operator /(nint x, nint y);
4204+
nuint operator /(nuint x, nuint y);
41964205
long operator /(long x, long y);
41974206
ulong operator /(ulong x, ulong y);
41984207
```
@@ -4244,6 +4253,8 @@ The predefined remainder operators are listed below. The operators all compute t
42444253
```csharp
42454254
int operator %(int x, int y);
42464255
uint operator %(uint x, uint y);
4256+
nint operator %(nint x, nint y);
4257+
nuint operator %(nuint x, nuint y);
42474258
long operator %(long x, long y);
42484259
ulong operator %(ulong x, ulong y);
42494260
```
@@ -4294,6 +4305,8 @@ The predefined addition operators are listed below. For numeric and enumeration
42944305
```csharp
42954306
int operator +(int x, int y);
42964307
uint operator +(uint x, uint y);
4308+
nint operator +(nint x, nint y);
4309+
nuint operator +(nuint x, nuint y);
42974310
long operator +(long x, long y);
42984311
ulong operator +(ulong x, ulong y);
42994312
```
@@ -4396,6 +4409,8 @@ The predefined subtraction operators are listed below. The operators all subtrac
43964409
```csharp
43974410
int operator –(int x, int y);
43984411
uint operator –(uint x, uint y);
4412+
nint operator –(nint x, nint y);
4413+
nuint operator –(nuint x, nuint y);
43994414
long operator –(long x, long y);
44004415
ulong operator –(ulong x, ulong y
44014416
```
@@ -4521,6 +4536,8 @@ The predefined shift operators are listed below.
45214536
```csharp
45224537
int operator <<(int x, int count);
45234538
uint operator <<(uint x, int count);
4539+
nint operator <<(nint x, int count);
4540+
nuint operator <<(nuint x, int count);
45244541
long operator <<(long x, int count);
45254542
ulong operator <<(ulong x, int count);
45264543
```
@@ -4533,6 +4550,8 @@ The predefined shift operators are listed below.
45334550
```csharp
45344551
int operator >>(int x, int count);
45354552
uint operator >>(uint x, int count);
4553+
nint operator >>(nint x, int count);
4554+
nuint operator >>(nuint x, int count);
45364555
long operator >>(long x, int count);
45374556
ulong operator >>(ulong x, int count);
45384557
```
@@ -4619,31 +4638,43 @@ The predefined integer comparison operators are:
46194638
```csharp
46204639
bool operator ==(int x, int y);
46214640
bool operator ==(uint x, uint y);
4641+
bool operator ==(nint x, nint y);
4642+
bool operator ==(nuint x, nuint y);
46224643
bool operator ==(long x, long y);
46234644
bool operator ==(ulong x, ulong y);
46244645

46254646
bool operator !=(int x, int y);
46264647
bool operator !=(uint x, uint y);
4648+
bool operator !=(nint x, nint y);
4649+
bool operator !=(nuint x, nuint y);
46274650
bool operator !=(long x, long y);
46284651
bool operator !=(ulong x, ulong y);
46294652

46304653
bool operator <(int x, int y);
46314654
bool operator <(uint x, uint y);
4655+
bool operator <(nint x, nint y);
4656+
bool operator <(nuint x, nuint y);
46324657
bool operator <(long x, long y);
46334658
bool operator <(ulong x, ulong y);
46344659

46354660
bool operator >(int x, int y);
46364661
bool operator >(uint x, uint y);
4662+
bool operator >(nint x, nint y);
4663+
bool operator >(nuint x, nuint y);
46374664
bool operator >(long x, long y);
46384665
bool operator >(ulong x, ulong y);
46394666

46404667
bool operator <=(int x, int y);
46414668
bool operator <=(uint x, uint y);
4669+
bool operator <=(nint x, nint y);
4670+
bool operator <=(nuint x, nuint y);
46424671
bool operator <=(long x, long y);
46434672
bool operator <=(ulong x, ulong y);
46444673

46454674
bool operator >=(int x, int y);
46464675
bool operator >=(uint x, uint y);
4676+
bool operator >=(nint x, nint y);
4677+
bool operator >=(nuint x, nuint y);
46474678
bool operator >=(long x, long y);
46484679
bool operator >=(ulong x, ulong y);
46494680
```
@@ -5098,16 +5129,22 @@ The predefined integer logical operators are:
50985129
```csharp
50995130
int operator &(int x, int y);
51005131
uint operator &(uint x, uint y);
5132+
nint operator &(nint x, nint y);
5133+
nuint operator &(nuint x, nuint y);
51015134
long operator &(long x, long y);
51025135
ulong operator &(ulong x, ulong y);
51035136

51045137
int operator |(int x, int y);
51055138
uint operator |(uint x, uint y);
5139+
nint operator |(nint x, nint y);
5140+
nuint operator |(nuint x, nuint y);
51065141
long operator |(long x, long y);
51075142
ulong operator |(ulong x, ulong y);
51085143

51095144
int operator ^(int x, int y);
51105145
uint operator ^(uint x, uint y);
5146+
nint operator ^(nint x, nint y);
5147+
nuint operator ^(nuint x, nuint y);
51115148
long operator ^(long x, long y);
51125149
ulong operator ^(ulong x, ulong y);
51135150
```

0 commit comments

Comments
 (0)