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

Bug: f(z)=z and c=1/3-i/3 produces f(c)= -i/3 rather than f(c) = 1/3 - i/3 #69

Closed
sadqiang opened this issue Dec 18, 2018 · 4 comments
Closed

Comments

@sadqiang
Copy link

sadqiang commented Dec 18, 2018

The following code snippet produces (0,-0.33333) rather than (0.33333,-0.33333).

using System;
using static MathNet.Symbolics.SymbolicExpression;
using static System.Console;
using static System.Numerics.Complex;
using Complex = System.Numerics.Complex;

namespace MathNetSymbolicsCompile
{
    class Program
    {
        static readonly Complex i = ImaginaryOne;

        static void Main(string[] args)
        {
            var z = Variable("z");
            Func<Complex, Complex> f = (z).CompileComplex("z");
            Complex c = 1/3 - i/3 ;
            WriteLine(f(c));
        }
    }
}

The following information might be irrelevant.
I successfully tested it with Xamarin.Forms for UWP, Android and iOS. It is really multi platform library.

@sadqiang
Copy link
Author

I tried again with real numbers, the same bug occurs.

var x = Variable("x");
Func<double, double> f = (x).Compile("x");
double c = 1 / 3;
Result.Text = f(c).ToString();

@sadqiang
Copy link
Author

Oh... I think I know the solution.

@FoggyFinder
Copy link
Contributor

1/3 = 0 - integer division

@sadqiang
Copy link
Author

@FoggyFinder : That is what I was thinking several seconds ago.

@sadqiang sadqiang reopened this Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants