-
Notifications
You must be signed in to change notification settings - Fork 215
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
VB -> C#: Optimize Double(/Decimal)-to-Integer conversion #1020
Comments
Just to make sure I understand, I assume you mean that methods already returning integers (floor, ceiling, truncate, round) don't need an additional round to be added? |
Those methods return values whose types are same as input. |
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue | DebuggableAttribute.DebuggingModes.DisableOptimizations)]
[assembly: AssemblyVersion("0.0.0.0")]
public class A
{
public static void Main()
{
double num = 0.6;
checked
{
int value = (int)num;
int value2 = (int)Math.Ceiling(num);
Console.WriteLine(value);
Console.WriteLine(value2);
}
}
} https://learn.microsoft.com/en-us/dotnet/api/system.math.truncate?view=net-7.0
|
VB compiler (LocalRewriter) in Roslyn has already done this optimization for |
VB.Net input code
Erroneous output
Extra verbose
Math.Round
Expected output
Decimal
is not optimized by the latest VB compiler but I think it can be.CInt(Decimal)
→System.Convert.ToInt32
(similar as(int)Math.Round
)Details
The text was updated successfully, but these errors were encountered: