quagmt / udecimal

A high-performance, high precision, zero allocation fixed-point decimal library for financial applications
https://quagmt.github.io/udecimal/
BSD 3-Clause "New" or "Revised" License
111 stars 4 forks source link

fix: correct negative zero result for Decimal subtraction #11

Closed mdawar closed 1 month ago

mdawar commented 1 month ago

This is a possible fix for #10.

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 94.53%. Comparing base (9d5eef5) to head (85f2a9f).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #11 +/- ## ======================================= Coverage 94.53% 94.53% ======================================= Files 5 5 Lines 1263 1263 ======================================= Hits 1194 1194 Misses 37 37 Partials 32 32 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

quagmt commented 1 month ago

Thanks for reporting this bug. However, this fix doesn't solve the case where two decimal numbers are equal, but they have different precision, for example:

a := MustFromInt64(100,1)
b:= MustFromInt64(10000,3)

udecimal.Zero == a.Sub(b) // false

I think the correct solution should be making zero value consistent across all operations. I'll create a fix for it

mdawar commented 1 month ago

Thanks for reviewing my PR.

I'll close it in favor of your solution, I wasn't sure about it anyway and you are more familiar with the codebase.