-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FPL Abs bug #144
Comments
I think the result of FPL16.Abs cannot be negative. // Decompile the code // Modified // dotnet source code System.Math.Abs throw exception, if value equal long.MinValue. Console.WriteLine(Math.Abs(float.MinValue)); // 3.4028235E+38 Are fixed point and decimal more similar? |
Hi, sorry for not replying to this. I suggest adding an extension method for this. I definitely don't want to throw an exception like |
I'm currently clone and modified the repository source code. I also didn't test the performance...
|
PL16 value = FPL16.MinValue;
FPL16 absValue = value.Abs();
Console.WriteLine($"{value}, {absValue}"); // -140737488355328, -140737488355328
value = new FPL16(-1);
absValue = value.Abs();
Console.WriteLine($"{value}, {absValue}"); // -1, 1
long testValue = long.MinValue;
Console.WriteLine($"{long.MinValue}, {-testValue}"); // -9223372036854775808, -9223372036854775808
try
{
Math.Abs(testValue);
}
catch (Exception ex)
{
// System.OverflowException: Negating the minimum value of a twos complement number is invalid.
Console.WriteLine(ex.ToString());
}
The text was updated successfully, but these errors were encountered: