Skip to content

Commit a517663

Browse files
committed
Address operator feedback
1. Arithmetic operator code blocks (all add nint/nuint between uint/ulong and long/ulong lines): - added nint operator *(nint x, nint y); and nuint operator *(nuint x, nuint y); - added nint/nuint division operators - added nint/nuint remainder operators - added nint/nuint addition operators - added nint/nuint subtraction operators (also fixed missing closing paren on ulong line) 2. Shift operator code blocks: - added nint operator <<(nint x, int count); and nuint operator <<(nuint x, int count); - added nint operator >>(nint x, int count); and nuint operator >>(nuint x, int count); 3. Unary minus operator: - added nint operator –(nint x); - updated to mention nint: "(−2³¹ for int, the corresponding value for nint, or −2⁶³ for long)"
1 parent b14f438 commit a517663

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

standard/expressions.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,11 +3612,12 @@ For an operation of the form `-x`, unary operator overload resolution ([§12.4.
36123612

36133613
```csharp
36143614
int operator –(int x);
3615+
nint operator –(nint x);
36153616
long operator –(long x);
36163617
```
36173618

3618-
The result is computed by subtracting `X` from zero. If the value of `X` is the smallest representable value of the operand type (−2³¹ for `int` or −2⁶³ for `long`), then the mathematical negation of `X` is not representable within the operand type. If this occurs within a `checked` context, a `System.OverflowException` is thrown; if it occurs within an `unchecked` context, the result is the value of the operand and the overflow is not reported.
3619-
3619+
The result is computed by subtracting `X` from zero. If the value of `X` is the smallest representable value of the operand type (−2³¹ for `int`, the corresponding value for `nint`, or −2⁶³ for `long`), then the mathematical negation of `X` is not representable within the operand type. If this occurs within a `checked` context, a `System.OverflowException` is thrown; if it occurs within an `unchecked` context, the result is the value of the operand and the overflow is not reported.
3620+
36203621
If the operand of the negation operator is of type `uint`, it is converted to type `long`, and the type of the result is `long`. An exception is the rule that permits the `int` value `−2147483648` (−2³¹) to be written as a decimal integer literal ([§6.4.5.3](lexical-structure.md#6453-integer-literals)).
36213622

36223623
If the operand of the negation operator is of type `nuint`, a compile-time error occurs.
@@ -3971,6 +3972,8 @@ The predefined multiplication operators are listed below. The operators all comp
39713972
```csharp
39723973
int operator *(int x, int y);
39733974
uint operator *(uint x, uint y);
3975+
nint operator *(nint x, nint y);
3976+
nuint operator *(nuint x, nuint y);
39743977
long operator *(long x, long y);
39753978
ulong operator *(ulong x, ulong y);
39763979
```
@@ -4018,6 +4021,8 @@ The predefined division operators are listed below. The operators all compute th
40184021
```csharp
40194022
int operator /(int x, int y);
40204023
uint operator /(uint x, uint y);
4024+
nint operator /(nint x, nint y);
4025+
nuint operator /(nuint x, nuint y);
40214026
long operator /(long x, long y);
40224027
ulong operator /(ulong x, ulong y);
40234028
```
@@ -4069,6 +4074,8 @@ The predefined remainder operators are listed below. The operators all compute t
40694074
```csharp
40704075
int operator %(int x, int y);
40714076
uint operator %(uint x, uint y);
4077+
nint operator %(nint x, nint y);
4078+
nuint operator %(nuint x, nuint y);
40724079
long operator %(long x, long y);
40734080
ulong operator %(ulong x, ulong y);
40744081
```
@@ -4119,6 +4126,8 @@ The predefined addition operators are listed below. For numeric and enumeration
41194126
```csharp
41204127
int operator +(int x, int y);
41214128
uint operator +(uint x, uint y);
4129+
nint operator +(nint x, nint y);
4130+
nuint operator +(nuint x, nuint y);
41224131
long operator +(long x, long y);
41234132
ulong operator +(ulong x, ulong y);
41244133
```
@@ -4221,8 +4230,10 @@ The predefined subtraction operators are listed below. The operators all subtrac
42214230
```csharp
42224231
int operator –(int x, int y);
42234232
uint operator –(uint x, uint y);
4233+
nint operator –(nint x, nint y);
4234+
nuint operator –(nuint x, nuint y);
42244235
long operator –(long x, long y);
4225-
ulong operator –(ulong x, ulong y
4236+
ulong operator –(ulong x, ulong y);
42264237
```
42274238

42284239
In a `checked` context, if the difference is outside the range of the result type, a `System.OverflowException` is thrown. In an `unchecked` context, overflows are not reported and any significant high-order bits outside the range of the result type are discarded.
@@ -4346,6 +4357,8 @@ The predefined shift operators are listed below.
43464357
```csharp
43474358
int operator <<(int x, int count);
43484359
uint operator <<(uint x, int count);
4360+
nint operator <<(nint x, int count);
4361+
nuint operator <<(nuint x, int count);
43494362
long operator <<(long x, int count);
43504363
ulong operator <<(ulong x, int count);
43514364
```
@@ -4358,6 +4371,8 @@ The predefined shift operators are listed below.
43584371
```csharp
43594372
int operator >>(int x, int count);
43604373
uint operator >>(uint x, int count);
4374+
nint operator >>(nint x, int count);
4375+
nuint operator >>(nuint x, int count);
43614376
long operator >>(long x, int count);
43624377
ulong operator >>(ulong x, int count);
43634378
```

0 commit comments

Comments
 (0)