Exemplo n.º 1
0
        public GetDscrmnntRoots GetEquationSolution(InputDataBL datas)
        {
            var    dscrmnntAndRoots = new GetDscrmnntRoots();
            double x1           = default;
            double x2           = default;
            var    discriminant = Math.Pow(datas.B, 2) - 4 * datas.A * datas.C;

            dscrmnntAndRoots.Dscrmnnt = discriminant;
            if (discriminant > 0)
            {
                x1 = (-datas.B + Math.Sqrt(discriminant)) / (2 * datas.A);
                x2 = (-datas.B - Math.Sqrt(discriminant)) / (2 * datas.A);
            }
            else if (discriminant == 0)
            {
                x1 = (-datas.B) / (2 * datas.A);
                x2 = x1;
            }
            dscrmnntAndRoots.X1 = x1;
            dscrmnntAndRoots.X2 = x2;

            var equationBL = new EquationBL()
            {
                A = datas.A, B = datas.B, C = datas.C, Dscrmnnt = dscrmnntAndRoots.Dscrmnnt, X1 = dscrmnntAndRoots.X1, X2 = dscrmnntAndRoots.X2
            };
            var equationDal = _mapper.Map <Equation>(equationBL);

            _dataRepozitory.CreateEquationWithRoots(equationDal);
            return(dscrmnntAndRoots);
        }
Exemplo n.º 2
0
        public double CalculateDiscriminant(InputDataBL datas)
        {
            var discriminant = Math.Pow(datas.B, 2) - 4 * datas.A * datas.C;

            return(discriminant);
        }