This repository was archived by the owner on Nov 1, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-12
lines changed
src/System.Private.CoreLib/shared/System Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -658,15 +658,18 @@ public static double MaxMagnitude(double x, double y)
658658 }
659659
660660 // We do this comparison first and separately to handle the -0.0 to +0.0 comparision
661- // * Doing (x < y ) first could get transformed into (y >= x ) by the JIT which would
661+ // * Doing (ax < ay ) first could get transformed into (ay >= ax ) by the JIT which would
662662 // then return an incorrect value
663663
664- if ( x == y )
664+ double ax = Abs ( x ) ;
665+ double ay = Abs ( y ) ;
666+
667+ if ( ax == ay )
665668 {
666669 return double . IsNegative ( x ) ? y : x ;
667670 }
668671
669- return ( Abs ( x ) < Abs ( y ) ) ? y : x ;
672+ return ( ax < ay ) ? y : x ;
670673 }
671674
672675 [ NonVersionable ]
@@ -803,15 +806,18 @@ public static double MinMagnitude(double x, double y)
803806 }
804807
805808 // We do this comparison first and separately to handle the -0.0 to +0.0 comparision
806- // * Doing (x < y ) first could get transformed into (y >= x ) by the JIT which would
809+ // * Doing (ax < ay ) first could get transformed into (ay >= ax ) by the JIT which would
807810 // then return an incorrect value
808811
809- if ( x == y )
812+ double ax = Abs ( x ) ;
813+ double ay = Abs ( y ) ;
814+
815+ if ( ax == ay )
810816 {
811817 return double . IsNegative ( x ) ? x : y ;
812818 }
813819
814- return ( Abs ( x ) < Abs ( y ) ) ? x : y ;
820+ return ( ax < ay ) ? x : y ;
815821 }
816822
817823 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
Original file line number Diff line number Diff line change @@ -206,15 +206,18 @@ public static float MaxMagnitude(float x, float y)
206206 }
207207
208208 // We do this comparison first and separately to handle the -0.0 to +0.0 comparision
209- // * Doing (x < y ) first could get transformed into (y >= x ) by the JIT which would
209+ // * Doing (ax < ay ) first could get transformed into (ay >= ax ) by the JIT which would
210210 // then return an incorrect value
211211
212- if ( x == y )
212+ float ax = Abs ( x ) ;
213+ float ay = Abs ( y ) ;
214+
215+ if ( ax == ay )
213216 {
214217 return float . IsNegative ( x ) ? y : x ;
215218 }
216219
217- return ( Abs ( x ) < Abs ( y ) ) ? y : x ;
220+ return ( ax < ay ) ? y : x ;
218221 }
219222
220223 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
@@ -241,15 +244,18 @@ public static float MinMagnitude(float x, float y)
241244 }
242245
243246 // We do this comparison first and separately to handle the -0.0 to +0.0 comparision
244- // * Doing (x < y ) first could get transformed into (y >= x ) by the JIT which would
247+ // * Doing (ax < ay ) first could get transformed into (ay >= ax ) by the JIT which would
245248 // then return an incorrect value
246249
247- if ( x == y )
250+ float ax = Abs ( x ) ;
251+ float ay = Abs ( y ) ;
252+
253+ if ( ax == ay )
248254 {
249255 return float . IsNegative ( x ) ? x : y ;
250256 }
251257
252- return ( Abs ( x ) < Abs ( y ) ) ? x : y ;
258+ return ( ax < ay ) ? x : y ;
253259 }
254260
255261 [ Intrinsic ]
You can’t perform that action at this time.
0 commit comments