@@ -336,6 +336,13 @@ public static TVectorDouble HypotDouble<TVectorDouble, TVectorUInt64>(TVectorDou
336
336
337
337
TVectorUInt64 expDiff = xExp - yExp ;
338
338
339
+ // Cover cases where x or y is insignifican compared to the other
340
+ TVectorDouble insignificanMask = Unsafe . BitCast < TVectorUInt64 , TVectorDouble > (
341
+ TVectorUInt64 . GreaterThanOrEqual ( expDiff , TVectorUInt64 . Create ( double . SignificandLength + 1 ) ) &
342
+ TVectorUInt64 . LessThanOrEqual ( expDiff , TVectorUInt64 . Create ( unchecked ( ( ulong ) ( - double . SignificandLength - 1 ) ) ) )
343
+ ) ;
344
+ TVectorDouble insignificantResult = ax + ay ;
345
+
339
346
// To prevent overflow, scale down by 2^+600
340
347
TVectorUInt64 expBiasP500 = TVectorUInt64 . Create ( double . ExponentBias + 500 ) ;
341
348
TVectorUInt64 scaleDownMask = TVectorUInt64 . GreaterThan ( xExp , expBiasP500 ) | TVectorUInt64 . GreaterThan ( yExp , expBiasP500 ) ;
@@ -427,6 +434,7 @@ public static TVectorDouble HypotDouble<TVectorDouble, TVectorUInt64>(TVectorDou
427
434
// the inputs is NaN. Otherwise if either input
428
435
// is NaN, we return NaN
429
436
437
+ result = TVectorDouble . ConditionalSelect ( insignificanMask , insignificantResult , result ) ;
430
438
result = TVectorDouble . ConditionalSelect ( nanMask , TVectorDouble . Create ( double . NaN ) , result ) ;
431
439
result = TVectorDouble . ConditionalSelect ( infinityMask , TVectorDouble . Create ( double . PositiveInfinity ) , result ) ;
432
440
@@ -1179,7 +1187,7 @@ public static TVector MaxMagnitudeNumber<TVector, T>(TVector x, TVector y)
1179
1187
|| ( typeof ( T ) == typeof ( nint ) ) ) ;
1180
1188
1181
1189
return TVector . ConditionalSelect (
1182
- ( TVector . GreaterThan ( xMag , yMag ) & TVector . IsPositive ( yMag ) ) | TVector . IsNegative ( xMag ) ,
1190
+ ( TVector . LessThan ( xMag , yMag ) & TVector . IsPositive ( xMag ) ) | ( TVector . Equals ( xMag , yMag ) & TVector . IsNegative ( x ) ) | TVector . IsNegative ( yMag ) ,
1183
1191
x ,
1184
1192
y
1185
1193
) ;
@@ -1266,7 +1274,7 @@ public static TVector MinMagnitudeNumber<TVector, T>(TVector x, TVector y)
1266
1274
|| ( typeof ( T ) == typeof ( nint ) ) ) ;
1267
1275
1268
1276
return TVector . ConditionalSelect (
1269
- ( TVector . LessThan ( xMag , yMag ) & TVector . IsPositive ( xMag ) ) | TVector . IsNegative ( yMag ) ,
1277
+ ( TVector . LessThan ( xMag , yMag ) & TVector . IsPositive ( xMag ) ) | ( TVector . Equals ( xMag , yMag ) & TVector . IsNegative ( x ) ) | TVector . IsNegative ( yMag ) ,
1270
1278
x ,
1271
1279
y
1272
1280
) ;
0 commit comments