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

Library does not work with more than 38 digits. #10

Open
blackjetrock opened this issue Dec 5, 2023 · 4 comments
Open

Library does not work with more than 38 digits. #10

blackjetrock opened this issue Dec 5, 2023 · 4 comments

Comments

@blackjetrock
Copy link

No description provided.

@blackjetrock
Copy link
Author

I would like to use this library with 200 digits, 100 before the decimal point and 100 after. That would be equivalent to 1E99 to 1E-99 and allows me to use it for calculators with that range of numbers. At the moment it doesn't work above 38 digits, and there is a comment to that effect in the code.
Is it known what the reason for the 38 digit limit is?

@edwig
Copy link
Owner

edwig commented Dec 9, 2023

Have a look at bcd.h at lines 52-56. There are two constants that control this behaviour:
bcdDigits : The number of digits per integer (here 8)
bcdLength: The number of integers in the mantissa (here 5)
Currently the values are so that the maximum (unrounded) number of mantissa = 8 * 5 = 40 digits (38 rounded)
To increase the mantissa considder to increase the bcdLenght to more integers. For 200 that would be 200/8 = 25.
And then you should be able to use mantissa's of 200 digits.

@edwig edwig closed this as completed Dec 9, 2023
@blackjetrock
Copy link
Author

Hello,

I have done this and unfortunately the code crashes. I have ported the code to the RP Pico and above 38 digits I get an error that I don't understand yet. I also expected it to work for any number of digits. The comment that mentions a rash is actually one that I put in the code. the problem is in DividePositive but isn't a divide by zero. I think it's some form of overflow of the digits outside the mdata array bounds. Maybe.

@edwig
Copy link
Owner

edwig commented Dec 11, 2023

Hello blackjetrock,

The proof of the pudding is in the eating.
So…..
I checked in an extra class “bcd200” with a 200 digits mantissa.
Pull the latest from https://github.com/edwig/bcd
The unit tests of bcd are copied to UnitTestsBCD200.

Besides the bcdLength the following changes were made

  • Static PI() -> Larger precision
  • Static LN2() -> Larger precision
  • Static LN10() -> Larger precision
  • The unit tests ‘expected’ variables now all have a higher precision

All unit tests of bcd200 run in the green!

Have fun!

@edwig edwig reopened this Dec 11, 2023
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

2 participants