@@ -262,17 +262,12 @@ public static explicit operator Half(Int128 value)
262262 /// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="Int128" />.</exception>
263263 public static explicit operator checked short ( Int128 value )
264264 {
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 )
272267 {
273268 ThrowHelper . ThrowOverflowException ( ) ;
274269 }
275- return checked ( ( short ) value . _lower ) ;
270+ return checked ( ( short ) lower ) ;
276271 }
277272
278273 /// <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)
286281 /// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="Int128" />.</exception>
287282 public static explicit operator checked int ( Int128 value )
288283 {
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 )
296286 {
297287 ThrowHelper . ThrowOverflowException ( ) ;
298288 }
299- return checked ( ( int ) value . _lower ) ;
289+ return checked ( ( int ) lower ) ;
300290 }
301291
302292 /// <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)
310300 /// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="Int128" />.</exception>
311301 public static explicit operator checked long ( Int128 value )
312302 {
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 )
320305 {
321306 ThrowHelper . ThrowOverflowException ( ) ;
322307 }
323- return checked ( ( long ) value . _lower ) ;
308+ return lower ;
324309 }
325310
326311 /// <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)
334319 /// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="Int128" />.</exception>
335320 public static explicit operator checked nint ( Int128 value )
336321 {
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 )
344324 {
345325 ThrowHelper . ThrowOverflowException ( ) ;
346326 }
347- return checked ( ( nint ) value . _lower ) ;
327+ return checked ( ( nint ) lower ) ;
348328 }
349329
350330 /// <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)
360340 [ CLSCompliant ( false ) ]
361341 public static explicit operator checked sbyte ( Int128 value )
362342 {
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 )
370345 {
371346 ThrowHelper . ThrowOverflowException ( ) ;
372347 }
373- return checked ( ( sbyte ) value . _lower ) ;
348+ return checked ( ( sbyte ) lower ) ;
374349 }
375350
376351 /// <summary>Explicitly converts a 128-bit signed integer to a <see cref="float" /> value.</summary>
0 commit comments