Skip to content

Commit 173c1e8

Browse files
committed
update: expanded Fixed64 operators
1 parent 9c92201 commit 173c1e8

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/FixedMathSharp/Numerics/Fixed64.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,30 @@ public static explicit operator decimal(Fixed64 value)
252252
}
253253

254254
/// <summary>
255-
/// Adds an int to y
255+
/// Adds an Fixed64 to x
256256
/// </summary>
257257
[MethodImpl(MethodImplOptions.AggressiveInlining)]
258258
public static Fixed64 operator +(int x, Fixed64 y)
259259
{
260260
return y + x;
261261
}
262262

263+
/// <summary>
264+
/// Adds a float to x
265+
/// </summary>
266+
public static Fixed64 operator +(Fixed64 x, float y)
267+
{
268+
return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) + y);
269+
}
270+
271+
/// <summary>
272+
/// Adds a Fixed64 to x
273+
/// </summary>
274+
public static Fixed64 operator +(float x, Fixed64 y)
275+
{
276+
return y + x;
277+
}
278+
263279
/// <summary>
264280
/// Subtracts one Fixed64 number from another, with saturating behavior in case of overflow.
265281
/// </summary>
@@ -284,12 +300,30 @@ public static explicit operator decimal(Fixed64 value)
284300
}
285301

286302
/// <summary>
287-
/// Subtracts an int from y
303+
/// Subtracts a Fixed64 from x
288304
/// </summary>
289305
[MethodImpl(MethodImplOptions.AggressiveInlining)]
290306
public static Fixed64 operator -(int x, Fixed64 y)
291307
{
292-
return y - x;
308+
return new Fixed64(x - (y.m_rawValue * FixedMath.SCALE_FACTOR_D));
309+
}
310+
311+
/// <summary>
312+
/// Subtracts a float from x
313+
/// </summary>
314+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
315+
public static Fixed64 operator -(Fixed64 x, float y)
316+
{
317+
return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) - y);
318+
}
319+
320+
/// <summary>
321+
/// Subtracts a Fixed64 from x
322+
/// </summary>
323+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
324+
public static Fixed64 operator -(float x, Fixed64 y)
325+
{
326+
return new Fixed64(x - (y.m_rawValue * FixedMath.SCALE_FACTOR_D));
293327
}
294328

295329
/// <summary>

0 commit comments

Comments
 (0)