Skip to content
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

C# -> VB: Math.Truncate is not added when converting Double(/Decimal) to Integer #1021

Open
tats-u opened this issue Jul 2, 2023 · 0 comments
Labels
C# -> VB Specific to C# -> VB conversion output logic error A bug where the converted output behaves differently to the input code

Comments

@tats-u
Copy link

tats-u commented Jul 2, 2023

Input code

using System;

public partial class A
{
    public static void Main()
    {
        double foo = 0.6d;
        int bar = (int)foo;
        int baz = (int)Math.Ceiling(foo);
        Console.WriteLine(bar);
        Console.WriteLine(baz);
    }
}

https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYCMBYAUH1AZgAIAHAQzGAEtyAbYjYgQTwG89ivH11PuOubsOJwA9hABGdAKbEAZmLHEAvMQAMAOgBscANz8RxalGDFJlVcQAUJ4AEpFYg0KPHT58gC8rt0/YBZcmAAC00AYRlqOhMAc2snexc3RkwATmsLMCTDEVR0zO8c1y4AXzxSoA==

Produces:

0
1

Erroneous output

Imports System

Public Partial Class A
    Public Shared Sub Main()
        Dim foo = 0.6R
        Dim bar As Integer = foo
        Dim baz As Integer = Math.Ceiling(foo)
        Console.WriteLine(bar)
        Console.WriteLine(baz)
    End Sub
End Class

https://sharplab.io/#v2:DYLgbgRgNALiBOBXAdlAJiA1AHwJIFsAHAe3hgGcACAZQE9yYBTfAWACh2AFRCYASwDGlTgEMyfEcEoBhYCPJUAgu0qrhPfkOoALMYzQ0elALIi+yABQBKFWrsARPvkoAzYsUoBeSgAYAdABsAEq2dqqOzhBilIpUuMhMAOaM8F6u7qFhEZRRAF4xcQmMyanepjDaftKMfPzIiRZuxDZsYWrSxMjkxMCMfgDq8HxMADLmjBZR8C1tqh1dPX2Dw4xjyBN5M2oAosgG1Dzsuway8uTsQA=

Produces:

1
1

Expected output

Imports System

Public Partial Class A
    Public Shared Sub Main()
        Dim foo = 0.6R
        Dim bar As Integer = Math.Truncate(foo)
        Dim baz As Integer = Math.Ceiling(foo)
        Console.WriteLine(bar)
        Console.WriteLine(baz)
    End Sub
End Class

https://sharplab.io/#v2:DYLgbgRgNALiBOBXAdlAJiA1AHwJIFsAHAe3hgGcACAZQE9yYBTfAWACh2AFRCYASwDGlTgEMyfEcEoBhYCPJUAgu0qrhPfkOoALMYzQ0elALIi+yABQBKFWrsARPvkoAzYsUoBeSgAYAdABsAEq2dqqOzhBilIpUuMhMAOaM8F4mIjDafgAqSMgCGYwWbsQ2bGFqEZRRAF4xcQmMyaneppl+0ox8/MiJxe5lFarSxMjkxMCMfgDq8HxMADLmRVHwg0MjYxNTs/OMS8grIjXrqgCiyAbUPOwXBrLy5EA

Produces:

0
1

Details

Reverse conversion of #1020

@tats-u tats-u added the C# -> VB Specific to C# -> VB conversion label Jul 2, 2023
@GrahamTheCoder GrahamTheCoder added the output logic error A bug where the converted output behaves differently to the input code label Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# -> VB Specific to C# -> VB conversion output logic error A bug where the converted output behaves differently to the input code
Projects
None yet
Development

No branches or pull requests

2 participants