Skip to content

Commit 4492596

Browse files
authored
Fix (s)byte & (u)short code (#410)
1 parent 6c0c368 commit 4492596

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

src/Maths/Silk.NET.Maths.Tests/PowIntTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void Pow2Minus4()
4545
{
4646
var a = 2;
4747
var b = -4;
48-
var expected = (int)(1f / (2 << 3));
48+
var expected = Scalar.Reciprocal(2 << 3);
4949
Assert.Equal(expected, Scalar.Pow(a, b));
5050
}
5151
}

src/Maths/Silk.NET.Maths/Scalar.BaseOps.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ static T SByte(T left, T right)
14391439
{
14401440
if (typeof(T) == typeof(sbyte))
14411441
{
1442-
return (T) (object) ((sbyte) (object) left + (sbyte) (object) right);
1442+
return (T) (object) (sbyte) ((sbyte) (object) left + (sbyte) (object) right);
14431443
}
14441444

14451445
return Byte(left, right);
@@ -1450,7 +1450,7 @@ static T Byte(T left, T right)
14501450
{
14511451
if (typeof(T) == typeof(byte))
14521452
{
1453-
return (T) (object) ((byte) (object) left + (byte) (object) right);
1453+
return (T) (object) (byte) ((byte) (object) left + (byte) (object) right);
14541454
}
14551455

14561456
return Short(left, right);
@@ -1461,7 +1461,7 @@ static T Short(T left, T right)
14611461
{
14621462
if (typeof(T) == typeof(short))
14631463
{
1464-
return (T) (object) ((short) (object) left + (short) (object) right);
1464+
return (T) (object) (short) ((short) (object) left + (short) (object) right);
14651465
}
14661466

14671467
return UShort(left, right);
@@ -1472,7 +1472,7 @@ static T UShort(T left, T right)
14721472
{
14731473
if (typeof(T) == typeof(ushort))
14741474
{
1475-
return (T) (object) ((ushort) (object) left + (ushort) (object) right);
1475+
return (T) (object) (ushort) ((ushort) (object) left + (ushort) (object) right);
14761476
}
14771477

14781478
return Int(left, right);
@@ -1579,7 +1579,7 @@ static T SByte(T left, T right)
15791579
{
15801580
if (typeof(T) == typeof(sbyte))
15811581
{
1582-
return (T) (object) ((sbyte) (object) left - (sbyte) (object) right);
1582+
return (T) (object) (sbyte) ((sbyte) (object) left - (sbyte) (object) right);
15831583
}
15841584

15851585
return Byte(left, right);
@@ -1590,7 +1590,7 @@ static T Byte(T left, T right)
15901590
{
15911591
if (typeof(T) == typeof(byte))
15921592
{
1593-
return (T) (object) ((byte) (object) left - (byte) (object) right);
1593+
return (T) (object) (byte) ((byte) (object) left - (byte) (object) right);
15941594
}
15951595

15961596
return Short(left, right);
@@ -1601,7 +1601,7 @@ static T Short(T left, T right)
16011601
{
16021602
if (typeof(T) == typeof(short))
16031603
{
1604-
return (T) (object) ((short) (object) left - (short) (object) right);
1604+
return (T) (object) (short) ((short) (object) left - (short) (object) right);
16051605
}
16061606

16071607
return UShort(left, right);
@@ -1612,7 +1612,7 @@ static T UShort(T left, T right)
16121612
{
16131613
if (typeof(T) == typeof(ushort))
16141614
{
1615-
return (T) (object) ((ushort) (object) left - (ushort) (object) right);
1615+
return (T) (object) (ushort) ((ushort) (object) left - (ushort) (object) right);
16161616
}
16171617

16181618
return Int(left, right);
@@ -1719,7 +1719,7 @@ static T SByte(T left, T right)
17191719
{
17201720
if (typeof(T) == typeof(sbyte))
17211721
{
1722-
return (T) (object) ((sbyte) (object) left * (sbyte) (object) right);
1722+
return (T) (object) (sbyte) ((sbyte) (object) left * (sbyte) (object) right);
17231723
}
17241724

17251725
return Byte(left, right);
@@ -1730,7 +1730,7 @@ static T Byte(T left, T right)
17301730
{
17311731
if (typeof(T) == typeof(byte))
17321732
{
1733-
return (T) (object) ((byte) (object) left * (byte) (object) right);
1733+
return (T) (object) (byte) ((byte) (object) left * (byte) (object) right);
17341734
}
17351735

17361736
return Short(left, right);
@@ -1741,7 +1741,7 @@ static T Short(T left, T right)
17411741
{
17421742
if (typeof(T) == typeof(short))
17431743
{
1744-
return (T) (object) ((short) (object) left * (short) (object) right);
1744+
return (T) (object) (short) ((short) (object) left * (short) (object) right);
17451745
}
17461746

17471747
return UShort(left, right);
@@ -1752,7 +1752,7 @@ static T UShort(T left, T right)
17521752
{
17531753
if (typeof(T) == typeof(ushort))
17541754
{
1755-
return (T) (object) ((ushort) (object) left * (ushort) (object) right);
1755+
return (T) (object) (ushort) ((ushort) (object) left * (ushort) (object) right);
17561756
}
17571757

17581758
return Int(left, right);
@@ -1859,7 +1859,7 @@ static T SByte(T left, T right)
18591859
{
18601860
if (typeof(T) == typeof(sbyte))
18611861
{
1862-
return (T) (object) ((sbyte) (object) left / (sbyte) (object) right);
1862+
return (T) (object) (sbyte) ((sbyte) (object) left / (sbyte) (object) right);
18631863
}
18641864

18651865
return Byte(left, right);
@@ -1870,7 +1870,7 @@ static T Byte(T left, T right)
18701870
{
18711871
if (typeof(T) == typeof(byte))
18721872
{
1873-
return (T) (object) ((byte) (object) left / (byte) (object) right);
1873+
return (T) (object) (byte) ((byte) (object) left / (byte) (object) right);
18741874
}
18751875

18761876
return Short(left, right);
@@ -1881,7 +1881,7 @@ static T Short(T left, T right)
18811881
{
18821882
if (typeof(T) == typeof(short))
18831883
{
1884-
return (T) (object) ((short) (object) left / (short) (object) right);
1884+
return (T) (object) (short) ((short) (object) left / (short) (object) right);
18851885
}
18861886

18871887
return UShort(left, right);
@@ -1892,7 +1892,7 @@ static T UShort(T left, T right)
18921892
{
18931893
if (typeof(T) == typeof(ushort))
18941894
{
1895-
return (T) (object) ((ushort) (object) left / (ushort) (object) right);
1895+
return (T) (object) (ushort) ((ushort) (object) left / (ushort) (object) right);
18961896
}
18971897

18981898
return Int(left, right);

src/Maths/Silk.NET.Maths/Scalar.Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ static Scalar()
224224
PositiveInfinity = default;
225225
One = (T) (object) (sbyte) 1;
226226
Two = (T) (object) (sbyte) 2;
227+
MinusOne = (T) (object) (sbyte) -1;
228+
MinusTwo = (T) (object) (sbyte) -2;
227229
E = (T) (object) (sbyte) FloatE;
228230
Pi = (T) (object) (sbyte) FloatPi;
229231
Tau = (T) (object) (sbyte) FloatTau;

src/Maths/Silk.NET.Maths/Scalar.Inverse.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static T SByte(T x)
6464
{
6565
if (typeof(T) == typeof(sbyte))
6666
{
67-
return (T) (object) (((sbyte) 1) / (sbyte) (object) x);
67+
return (T) (object) (sbyte) (((sbyte) 1) / (sbyte) (object) x);
6868
}
6969

7070
return Byte(x);
@@ -75,7 +75,7 @@ static T Byte(T x)
7575
{
7676
if (typeof(T) == typeof(byte))
7777
{
78-
return (T) (object) (((byte) 1) / (byte) (object) x);
78+
return (T) (object) (byte) (((byte) 1) / (byte) (object) x);
7979
}
8080

8181
return UShort(x);
@@ -86,7 +86,7 @@ static T UShort(T x)
8686
{
8787
if (typeof(T) == typeof(ushort))
8888
{
89-
return (T) (object) (((ushort) 1) / (ushort) (object) x);
89+
return (T) (object) (ushort) (((ushort) 1) / (ushort) (object) x);
9090
}
9191

9292
return Short(x);
@@ -97,7 +97,7 @@ static T Short(T x)
9797
{
9898
if (typeof(T) == typeof(short))
9999
{
100-
return (T) (object) (((short) 1) / (short) (object) x);
100+
return (T) (object) (short) (((short) 1) / (short) (object) x);
101101
}
102102

103103
return UInt(x);

src/Maths/Silk.NET.Maths/Scalar.MathFPort.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4568,7 +4568,7 @@ static T ULong(T x, T y)
45684568
/// ## Remarks
45694569
/// The following table indicates the return value when various values or ranges of values are specified for the `x` and `y` parameters. For more information, see <xref:System.Single.PositiveInfinity?displayProperty=nameWithType>, <xref:System.Single.NegativeInfinity?displayProperty=nameWithType>, and <xref:System.Single.NaN?displayProperty=nameWithType>.
45704570
///
4571-
/// |Parameters|Return value|
4571+
/// |Parameters|Return value|
45724572
/// |----------------|------------------|
45734573
/// |`x` or `y` = `NaN`.|`NaN`|
45744574
/// |`x` = Any value except `NaN`; `y` = 0.|1|
@@ -4657,7 +4657,7 @@ static T SByte(T x, T y)
46574657

46584658
if (oabsy == py)
46594659
return (T) (object) result;
4660-
return (T) (object) (sbyte) (1f / result);
4660+
return (T) (object) (sbyte) Scalar.Reciprocal(result);
46614661
}
46624662
else
46634663
{
@@ -4727,7 +4727,7 @@ static T Short(T x, T y)
47274727

47284728
if (oabsy == py)
47294729
return (T) (object) result;
4730-
return (T) (object) (short) (1f / result);
4730+
return (T) (object) (short) Scalar.Reciprocal(result);
47314731
}
47324732
else
47334733
{
@@ -4797,7 +4797,7 @@ static T Int(T x, T y)
47974797

47984798
if (oabsy == py)
47994799
return (T) (object) result;
4800-
return (T) (object) (int) (1f / result);
4800+
return (T) (object) (int) Scalar.Reciprocal(result);
48014801
}
48024802
else
48034803
{
@@ -4867,7 +4867,7 @@ static T Long(T x, T y)
48674867

48684868
if (oabsy == py)
48694869
return (T) (object) result;
4870-
return (T) (object) (long) (1f / result);
4870+
return (T) (object) (long) Scalar.Reciprocal(result);
48714871
}
48724872
else
48734873
{

0 commit comments

Comments
 (0)