Skip to content

Commit 5011566

Browse files
committed
Moving some Is* methods down to INumber so DIMs can be provided for more functions
1 parent 44bb2aa commit 5011566

File tree

1 file changed

+73
-20
lines changed

1 file changed

+73
-20
lines changed

accepted/2021/statics-in-interfaces/README.md

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,22 +1074,6 @@ namespace System.Numerics
10741074

10751075
static abstract TSelf PositiveInfinity { get; }
10761076

1077-
// The following methods are exposed on the floating-point types today
1078-
1079-
static abstract bool IsFinite(TSelf value);
1080-
1081-
static abstract bool IsInfinity(TSelf value);
1082-
1083-
static abstract bool IsNaN(TSelf value);
1084-
1085-
static abstract bool IsNegativeInfinity(TSelf value);
1086-
1087-
static abstract bool IsNormal(TSelf value);
1088-
1089-
static abstract bool IsPositiveInfinity(TSelf value);
1090-
1091-
static abstract bool IsSubnormal(TSelf value);
1092-
10931077
public static virtual TSelf MaxMagnitudeNumber(TSelf x, TSelf y)
10941078
{
10951079
TSelf ax = Abs(x);
@@ -1364,15 +1348,84 @@ namespace System.Numerics
13641348

13651349
// IsEven, IsOdd, IsZero
13661350
1351+
static abstract bool IsFinite(TSelf value);
1352+
1353+
static abstract bool IsInfinity(TSelf value);
1354+
1355+
static abstract bool IsNaN(TSelf value);
1356+
13671357
static abstract bool IsNegative(TSelf value);
13681358

1369-
static abstract TSelf Max(TSelf x, TSelf y);
1359+
public static virtual bool IsNegativeInfinity(TSelf value) => IsNegative(value) && IsInfinity(value);
1360+
1361+
static abstract bool IsNormal(TSelf value);
13701362

1371-
static abstract TSelf MaxMagnitude(TSelf x, TSelf y);
1363+
public static virtual bool IsPositive(TSelf value) => !IsNegative(value);
13721364

1373-
static abstract TSelf Min(TSelf x, TSelf y);
1365+
public static virtual bool IsPositiveInfinity(TSelf value) => IsPositive(value) && IsInfinity(value);
1366+
1367+
static abstract bool IsSubnormal(TSelf value);
13741368

1375-
static abstract TSelf MinMagnitude(TSelf x, TSelf y);
1369+
public static virtual TSelf Max(TSelf x, TSelf y)
1370+
{
1371+
if (val1 != val2)
1372+
{
1373+
if (!IsNaN(val1))
1374+
{
1375+
return val2 < val1 ? val1 : val2;
1376+
}
1377+
1378+
return val1;
1379+
}
1380+
1381+
return IsNegative(val2) ? val1 : val2;
1382+
}
1383+
1384+
public static virtual TSelf MaxMagnitude(TSelf x, TSelf y)
1385+
{
1386+
TSelf ax = Abs(x);
1387+
TSelf ay = Abs(y);
1388+
1389+
if ((ax > ay) || IsNaN(ax))
1390+
{
1391+
return x;
1392+
}
1393+
1394+
if (ax == ay)
1395+
{
1396+
return IsNegative(x) ? y : x;
1397+
}
1398+
1399+
return y;
1400+
}
1401+
1402+
public static virtual TSelf Min(TSelf x, TSelf y)
1403+
{
1404+
if (val1 != val2 && !IsNaN(val1))
1405+
{
1406+
return val1 < val2 ? val1 : val2;
1407+
}
1408+
1409+
return IsNegative(val1) ? val1 : val2;
1410+
}
1411+
1412+
public static virtual TSelf MinMagnitude(TSelf x, TSelf y)
1413+
{
1414+
TSelf ax = Abs(x);
1415+
TSelf ay = Abs(y);
1416+
1417+
if ((ax < ay) || IsNaN(ax))
1418+
{
1419+
return x;
1420+
}
1421+
1422+
if (ax == ay)
1423+
{
1424+
return IsNegative(x) ? x : y;
1425+
}
1426+
1427+
return y;
1428+
}
13761429

13771430
static abstract TSelf Parse(string s, NumberStyles style, IFormatProvider? provider);
13781431

0 commit comments

Comments
 (0)