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

An incorrect double value is returned from a static method of the .NET type via interop #1142

Closed
Taritsyn opened this issue Apr 22, 2022 · 4 comments · Fixed by #1143
Closed
Labels

Comments

@Taritsyn
Copy link
Contributor

Hello!

In Jint version 3.0.0 Beta 2038 an incorrect double value is returned from a static method of the .NET type via interop. Moreover, this error occurs only in version for .NET Framework (everything works correctly in .NET Core). If you run the following console application:

using System;

using Jint;
using Jint.Runtime.Interop;

namespace TestJint
{
    class Program
    {
        static void Main(string[] args)
        {
            var engine = new Engine();
            TypeReference mathTypeReference = TypeReference.CreateTypeReference(engine, typeof(Math));
            engine.SetValue("Math2", mathTypeReference);
            double result = engine.Evaluate("Math2.Max(5.37, 5.56)").AsNumber();

            Console.WriteLine("Result: {0}", result);
        }
    }
}

Previous version (version 3.0.0 Beta 2037) and current version for .NET Core output a correct result:

Result: 5,56

Current version for .NET Framework outputs an incorrect result:

Result: 5,55999994277954
@lahma lahma added the bug label Apr 22, 2022
@lahma
Copy link
Collaborator

lahma commented Apr 22, 2022

Thanks for the bug report, you seem to have quite the QA harness 🙂 I think this is probably something caused by adding support for BigInt...

@Taritsyn
Copy link
Contributor Author

Hello, Marko!

…, you seem to have quite the QA harness 🙂

I just have a large set of tests to guarantee the identical results of work of different JS engines.

@lahma
Copy link
Collaborator

lahma commented Apr 22, 2022

The culprit was changes to method parameter scoring logic. Math.Max(float, float) was chosen instead of Math.Max(double, double) in this case and conversions were being made.

@Taritsyn
Copy link
Contributor Author

@lahma Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants