You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
VB does bankers' rounding but C# does truncation when converting floating points to integers.
Starting with Visual Basic 15.8, the performance of Double-to-integer conversion is optimized if you pass the value returned by the Truncate method to the any of the integral conversion functions, or if the Double value returned by Truncate is automatically converted to an integer with Option Strict set to Off. This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. The following example illustrates such an optimized conversion:
Activity
GrahamTheCoder commentedon Jun 28, 2023
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?
tats-u commentedon Jun 28, 2023
Those methods return values whose types are same as input.
VB does bankers' rounding but C# does truncation when converting floating points to integers.
[-]VB -> C#: Optimize Double/Decimal-to-Integer conversion[/-][+]VB -> C#: Optimize Double(/Decimal)-to-Integer conversion[/+]tats-u commentedon Jun 28, 2023
https://sharplab.io/#v2:DYLgbgRgNAJiDUAfAkgWwA4HsBOAXAzgAQDKAnvrgKaoCwAUPQAoCuEwAlgMaEDCwAhviIBBeoXGEWbLiQAW/bJRglWhALL92AOwAUASjESjAEXapCAM0yZCAXkIAGAHQA2Q0fGnzEBXd7ItXB0NXFknABVsZi1OfiodK0w9AzoPCS9CHwAvPx4AoJCwnkp2Di0AcwTrZPcPHkwtfExgSicAdWx2KgAZbUodH2wUtPF6xubWjq7KXq1+7OGJAFEtZWJWehXlPkF8IA==
https://learn.microsoft.com/en-us/dotnet/api/system.math.truncate?view=net-7.0
tats-u commentedon Apr 10, 2024
https://sharplab.io/#v2:DYLgbgRgPgkgtgBwPYCcAuBnABAZQJ4ZoCmcAsAFAUAKArhMAJYDGWAwsAIYbYCCFWArLXrNcACw4oiAE1x0sAWQ4MAdgAoAlP0E6AIgzhYAZkiRYAvFgAMAOgBs2nQP2GIki2xgq0apWjE2ACooNCpMHMRqJkgaWuROgi5YbgBeHqxePn4BrEQMjCoA5lGmsY5OrEgqGEjARDYA6igMxAAyqkRqbihxCQKV1bX1TS1E7Sqdqb2CAKIqsjh0FHOy7FwYQA==
VB compiler (LocalRewriter) in Roslyn has already done this optimization for
Double. However, it has no plan forDecimalin the future.https://sourceroslyn.io/#Microsoft.CodeAnalysis.VisualBasic/Lowering/LocalRewriter/LocalRewriter_Conversion.vb,921944f13b116c29,references