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 #1

Open
scholtz opened this issue Aug 29, 2017 · 1 comment
Open

Bug #1

scholtz opened this issue Aug 29, 2017 · 1 comment

Comments

@scholtz
Copy link

scholtz commented Aug 29, 2017

There is a bug in

openfastdotnet/OpenFast/DecimalValue.cs

    public override Decimal ToBigDecimal()
    {
        return (decimal) (Mantissa/Math.Pow(10, - Exponent));
    }

It should be :
public override Decimal ToBigDecimal()
{
return (decimal) (Mantissa/Math.Pow(10, Exponent));
}

@scholtz
Copy link
Author

scholtz commented Aug 30, 2017

After further investigating, the issue was not in function ToBigDecimal, but in initializing value from decimal value..

Test case:

[TestMethod]
        public void FromDecimalToDecimalTest()
        {
            decimal[] testValues = new decimal[] { 100.1M, 0M, -20.3M, 123456789.123456M };
            foreach (var value in testValues) {

                var val = new OpenFAST.DecimalValue(value);
                var test = val.ToBigDecimal();
                Assert.AreEqual(value, test);
            }
        }
        [TestMethod]
        public void FromDecimalToDoubleTest()
        {
            decimal[] testValues = new decimal[] { 100.1M, 0M, -20.3M, 123456789.123456M };
            foreach (var value in testValues) {

                var val = new OpenFAST.DecimalValue(value);
                var test = (decimal) Math.Round(val.ToDouble(),6);
                Assert.AreEqual(value, test);
            }
        }
        [TestMethod]
        public void FromDoubleToDecimalTest()
        {
            double[] testValues = new double[] { 100.1, 0.0, -20.3, 123456789.123456 };
            foreach (var value in testValues) {

                var val = new OpenFAST.DecimalValue(value);
                var test = Math.Round((double) val.ToBigDecimal(),6);
                Assert.AreEqual(value, test);
            }
        }
        [TestMethod]
        public void FromDoubleToDoubleTest()
        {
            double[] testValues = new double[] { 100.1, 0.0, -20.3, 123456789.123456 };
            foreach (var value in testValues) {

                var val = new OpenFAST.DecimalValue(value);
                var test = Math.Round(val.ToDouble(),6);
                Assert.AreEqual(value, test);
            }
        }

I am suggesting bugfix at line 65:

        public DecimalValue(Decimal bigDecimal)
        {
            Mantissa = Util.BigDecimalUnScaledValue(bigDecimal);
            Exponent = -1 * Util.BigDecimalScale(bigDecimal);
        }

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

1 participant