deveel-math icon indicating copy to clipboard operation
deveel-math copied to clipboard

Library is broken

Open sublimator opened this issue 9 years ago • 7 comments

Assert.AreEqual(16, 
               BigDecimal.Parse("9999,9999,9999,9999".Replace(",", ""))
                           .StripTrailingZeros().Precision);

It fails, with the actual value being 17 ... Yikes! Something to do with StripTrailingZeros ...

I've also seen issues with unnecessary rounding, when Parsing strings with a MathContext with a precision of 16, and where there's only been 16 digits. Probably negative numbers, cause I've seen negative numbers created using a big integer constructor, with a Precision of 17 when there's clearly only 16 digits, and that when you Abs() the value the Precision is 16.

I'm using <package id="dmath" version="1.5.66" targetFramework="net45" />

I feel like this package needs a lot more testing? I don't really have the time at the moment.

sublimator avatar Dec 15 '15 18:12 sublimator

@sublimator thank you the report: this must be an issue that should be addressed.

As I specified, this library is a port of Harmony's Math package, that I adapted for .NET (for the code and the style), integrating it with some contributions for the big math functions. I used the same test suite as Harmony, that didn't include the test you've done.

It would be precious if you could help out fixing some things.

Thank you for the support.

tsutomi avatar Dec 16 '15 15:12 tsutomi

I think this is a super useful project, but sadly there seems to be a few quirks.

If I can get some time I'll happily help out :)

sublimator avatar Dec 16 '15 16:12 sublimator

Thank you for acknowledging the importance: it's actually a missing piece in .NET (even after 4.0 the decimals and astronomical numbers are missing). I've implemented it to support DeveelDB, so I've never dedicated much time to it, as I should, also because my math knowledge is limited to few courses at the university

I wish to thank you for any support you might give: I will try inspecting any case you will rise up

tsutomi avatar Dec 16 '15 16:12 tsutomi

Maybe we can somehow use a Java bridge / J# runtime or something and generate a heap of tests, to match up the implementations ? And expose issues

sublimator avatar Dec 16 '15 16:12 sublimator

It's a matter of licensing: I used Harmony's version of the Java Math package because it was licensed under MIT, while Java is not so lose on license. This allowed me to use the library also in loose (or commercial) projects.

tsutomi avatar Dec 16 '15 16:12 tsutomi

How did you do the code conversion?

sublimator avatar Dec 19 '15 05:12 sublimator

the old way: manually. :)

once it was ported and tested according to the test suite provided, I changed the design a bit, to make it more .NET fashion (.Parse, .TryParse, properties, etc.)

tsutomi avatar Dec 19 '15 11:12 tsutomi