@@ -262,17 +262,12 @@ public static explicit operator Half(Int128 value)
262
262
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="Int128" />.</exception>
263
263
public static explicit operator checked short ( Int128 value )
264
264
{
265
- if ( ~ value . _upper == 0 )
266
- {
267
- long lower = ( long ) value . _lower ;
268
- return checked ( ( short ) lower ) ;
269
- }
270
-
271
- if ( value . _upper != 0 )
265
+ long lower = ( long ) value . _lower ;
266
+ if ( ( long ) value . _upper != lower >> 63 )
272
267
{
273
268
ThrowHelper . ThrowOverflowException ( ) ;
274
269
}
275
- return checked ( ( short ) value . _lower ) ;
270
+ return checked ( ( short ) lower ) ;
276
271
}
277
272
278
273
/// <summary>Explicitly converts a 128-bit signed integer to a <see cref="int" /> value.</summary>
@@ -286,17 +281,12 @@ public static explicit operator checked short(Int128 value)
286
281
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="Int128" />.</exception>
287
282
public static explicit operator checked int ( Int128 value )
288
283
{
289
- if ( ~ value . _upper == 0 )
290
- {
291
- long lower = ( long ) value . _lower ;
292
- return checked ( ( int ) lower ) ;
293
- }
294
-
295
- if ( value . _upper != 0 )
284
+ long lower = ( long ) value . _lower ;
285
+ if ( ( long ) value . _upper != lower >> 63 )
296
286
{
297
287
ThrowHelper . ThrowOverflowException ( ) ;
298
288
}
299
- return checked ( ( int ) value . _lower ) ;
289
+ return checked ( ( int ) lower ) ;
300
290
}
301
291
302
292
/// <summary>Explicitly converts a 128-bit signed integer to a <see cref="long" /> value.</summary>
@@ -310,17 +300,12 @@ public static explicit operator checked int(Int128 value)
310
300
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="Int128" />.</exception>
311
301
public static explicit operator checked long ( Int128 value )
312
302
{
313
- if ( ~ value . _upper == 0 )
314
- {
315
- long lower = ( long ) value . _lower ;
316
- return lower ;
317
- }
318
-
319
- if ( value . _upper != 0 )
303
+ long lower = ( long ) value . _lower ;
304
+ if ( ( long ) value . _upper != lower >> 63 )
320
305
{
321
306
ThrowHelper . ThrowOverflowException ( ) ;
322
307
}
323
- return checked ( ( long ) value . _lower ) ;
308
+ return lower ;
324
309
}
325
310
326
311
/// <summary>Explicitly converts a 128-bit signed integer to a <see cref="IntPtr" /> value.</summary>
@@ -334,17 +319,12 @@ public static explicit operator checked long(Int128 value)
334
319
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="Int128" />.</exception>
335
320
public static explicit operator checked nint ( Int128 value )
336
321
{
337
- if ( ~ value . _upper == 0 )
338
- {
339
- long lower = ( long ) value . _lower ;
340
- return checked ( ( nint ) lower ) ;
341
- }
342
-
343
- if ( value . _upper != 0 )
322
+ long lower = ( long ) value . _lower ;
323
+ if ( ( long ) value . _upper != lower >> 63 )
344
324
{
345
325
ThrowHelper . ThrowOverflowException ( ) ;
346
326
}
347
- return checked ( ( nint ) value . _lower ) ;
327
+ return checked ( ( nint ) lower ) ;
348
328
}
349
329
350
330
/// <summary>Explicitly converts a 128-bit signed integer to a <see cref="sbyte" /> value.</summary>
@@ -360,17 +340,12 @@ public static explicit operator checked nint(Int128 value)
360
340
[ CLSCompliant ( false ) ]
361
341
public static explicit operator checked sbyte ( Int128 value )
362
342
{
363
- if ( ~ value . _upper == 0 )
364
- {
365
- long lower = ( long ) value . _lower ;
366
- return checked ( ( sbyte ) lower ) ;
367
- }
368
-
369
- if ( value . _upper != 0 )
343
+ long lower = ( long ) value . _lower ;
344
+ if ( ( long ) value . _upper != lower >> 63 )
370
345
{
371
346
ThrowHelper . ThrowOverflowException ( ) ;
372
347
}
373
- return checked ( ( sbyte ) value . _lower ) ;
348
+ return checked ( ( sbyte ) lower ) ;
374
349
}
375
350
376
351
/// <summary>Explicitly converts a 128-bit signed integer to a <see cref="float" /> value.</summary>
0 commit comments