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# interactive producing incorrect results #51030

Closed
vsfeedback opened this issue Feb 5, 2021 · 6 comments
Closed

C# interactive producing incorrect results #51030

vsfeedback opened this issue Feb 5, 2021 · 6 comments
Labels
Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:I'm unable to use this version]
The following expression incorrectly returns "0" when evaluated in C# interactive:
TimeSpan.FromSeconds(0.00005). Ticks

It should return 500, as it does when called in a normal .NET process.

If my calculator started producing the wrong values I would throw it in the trash. I don't want to throw C# interactive in the trash.


Original Comments

Feedback Bot on 2/4/2021, 10:16 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 5, 2021
@MarkPflug
Copy link

TimeSpan.FromSeconds(0.0005).Ticks
produces 10000, should be 5000
TimeSpan.FromSeconds(0.005).Ticks
Correctly produces 50000

Wish I could see a pattern, but I don't.

@ufcpp
Copy link
Contributor

ufcpp commented Feb 6, 2021

Seems like this is a problem of .NET Framework.

using System;

Console.WriteLine(TimeSpan.FromSeconds(0.000005).Ticks);
Console.WriteLine(TimeSpan.FromSeconds(0.00005).Ticks);
Console.WriteLine(TimeSpan.FromSeconds(0.0005).Ticks);

The result is

0
0
10000

in net48 and

50
500
5000

in net5.0.

In C# Interactive, you can use .NET Core by using #reset core directive.

> #reset core
Resetting execution engine.
> TimeSpan.FromSeconds(0.00005).Ticks
500

@ufcpp
Copy link
Contributor

ufcpp commented Feb 6, 2021

https://docs.microsoft.com/en-us/dotnet/api/system.timespan.fromseconds?view=net-5.0

According to the document saying "the specification is accurate to the nearest millisecond", this is by design and the result in .NET 5 is rather incorrect.

@ufcpp
Copy link
Contributor

ufcpp commented Feb 6, 2021

see: dotnet/runtime#13230 (comment)

@MarkPflug
Copy link

Sounds like this is dotnet/runtime issue then. Hope they choose to update the docs and not revert the change in behavior. I can think of no reason that API shouldn't offer resolution down to the tick for situations like this. Rounding to the millisecond would make it less useful.

Anyway, good to know the scope of the issue and that I can continue to depend on the interactive window. Thanks for investigating and thanks for the pointer about "#reset core", wasn't aware of that feature.

@CyrusNajmabadi
Copy link
Member

Closing out as this is not an issue with interactive and the underlying cause is known and already tracked with the right team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

4 participants