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

Attach an adapter for BigDecimal for extension methods. #9

Open
TheSquidCombatant opened this issue Oct 22, 2023 · 2 comments
Open
Labels
long This may take a few weeks medium This requires being a programmer

Comments

@TheSquidCombatant
Copy link
Owner

TheSquidCombatant commented Oct 22, 2023

It is assumed that it is possible to add extension methods for BigDecimal by converting BigDecimal to BigInteger and reusing extension methods for BigInteger.

We should check what is currently available on the BigDecimal data type in C#, see how other libraries work with it.

If there is nothing suitable, then, perhaps, implement the BigDecimal data type yourself. And add implementations of mathematical methods to this class.

@TheSquidCombatant TheSquidCombatant added the hard This requires being not only a programmer, but also mathematics label Oct 22, 2023
@TheSquidCombatant
Copy link
Owner Author

TheSquidCombatant commented Nov 5, 2023

If you have to release the BigDecimal type yourself, I suggest the following. Store it in memory as a structure with fields: uint field for the number of decimal places after the decimal point, and BigInteger field for storing the value itself and its sign. In binary form, first serialize 4 bytes of the uint field, then the BigInteger as is. In text form, serialize as a number with the number of decimal places equal to uint field value, even if this results in writing insignificant zeros.

@TheSquidCombatant
Copy link
Owner Author

If you have to release the BigDecimal type yourself, it is worth to put this type in namespace TheSquid.Numerics, do it in a separate repository TheSquid.Numerics and release as a separate assembly, which can be used in the assembly TheSquid.Numerics.Extensions.

@TheSquidCombatant TheSquidCombatant added the long This may take a few weeks label Nov 5, 2023
@TheSquidCombatant TheSquidCombatant added medium This requires being a programmer and removed hard This requires being not only a programmer, but also mathematics labels Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
long This may take a few weeks medium This requires being a programmer
Projects
None yet
Development

No branches or pull requests

1 participant