HP Forums
Searching for decimal library for RP Pico - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: Not HP Calculators (/forum-7.html)
+--- Forum: Not quite HP Calculators - but related (/forum-8.html)
+--- Thread: Searching for decimal library for RP Pico (/thread-20396.html)



Searching for decimal library for RP Pico - blackjetrock - 08-26-2023 05:15 AM

I'm looking for a decimal library that I can use on the raspberry Pi Pico. This microcontroller has 250K or so of RAM and 2M byte of flash.

I've tried the Intel decimal library and that is just too big. Adding the 147000 line file full of constants push it over the limit of flash by 855K bytes.

I've also tried libbf which worked fine until I tried 1000 sqrts in a loop and got a memory error. I suspect either a memory leak or fragmentation problems there.

I'm not really after arbitrary precision, just a decimal encoding of numbers so that I can code a calculator. A library that has 13-32 digits, or is configurable at compile time and decimal encoding would be perfect. And small enough to fit in a microcontroller and preferably having no malloc() calls. And in C.

Andrew


RE: Searching for decimal library for RP Pico - Over_score - 08-26-2023 07:20 AM

You can try decNumber https://speleotrove.com/decimal/ used by WP34S, WP43 and C47
There is also mpdecimal https://www.bytereef.org/mpdecimal/
And others https://en.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software


RE: Searching for decimal library for RP Pico - EdS2 - 08-26-2023 07:51 AM

Great links - thanks!

blackjetrock, I'd be interested to hear about your progress, and what package you choose and what size it is.


RE: Searching for decimal library for RP Pico - blackjetrock - 08-26-2023 05:14 PM

(08-26-2023 07:20 AM)Over_score Wrote:  You can try decNumber https://speleotrove.com/decimal/ used by WP34S, WP43 and C47
There is also mpdecimal https://www.bytereef.org/mpdecimal/
And others https://en.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software

Yes, I've looked at mpdecimal and decnumber but I don't think they do trig or transcendental functions.

I looked at the wikipedia list, that was where I found libbf, but that is a list of arbitrary precision libraries which tend to use malloc a lot, and I think that cause sme problems. I'm not really after arbitrary precision, but fixed precision decima


RE: Searching for decimal library for RP Pico - blackjetrock - 08-26-2023 05:17 PM

(08-26-2023 07:51 AM)EdS2 Wrote:  Great links - thanks!

blackjetrock, I'd be interested to hear about your progress, and what package you choose and what size it is.

I wish I could jump forward and find out about my progress, too, it's a bit slow. What I can tell you is that the Intel library is massive (compared to a Pico) and libbf is nice, but as it's arbitrary precision uses a lot of mallocs. I don't know exactly why I was getting a memory error, whether I was doing something wrong or there is a memory leak, or fragmentation was occuring. Libbf would do what I need, if it was fixed to some precision or other at compile time. maybe I can adjust it?


RE: Searching for decimal library for RP Pico - blackjetrock - 08-26-2023 05:19 PM

Actually, there was a third option I tried and that was to look at using the Intel library that the Swiss Micros calculators use. That was a bit odd as it's a compiled library and seems too small to be the full Intel library. I then looked at the Intel library but found it was too big. i suspect the SM version of the Intel library is squashed somehow.


RE: Searching for decimal library for RP Pico - ijabbott - 08-26-2023 09:11 PM

(08-26-2023 05:19 PM)blackjetrock Wrote:  Actually, there was a third option I tried and that was to look at using the Intel library that the Swiss Micros calculators use. That was a bit odd as it's a compiled library and seems too small to be the full Intel library. I then looked at the Intel library but found it was too big. i suspect the SM version of the Intel library is squashed somehow.

I have a vague memory that the Intel library included two copies of the constants for some reason, probably unnecessarily. So perhaps SM made it work with one copy of the constants.


RE: Searching for decimal library for RP Pico - blackjetrock - 08-31-2023 01:49 PM

(08-26-2023 07:51 AM)EdS2 Wrote:  Great links - thanks!

blackjetrock, I'd be interested to hear about your progress, and what package you choose and what size it is.

I found this repository:

https://github.com/edwig/BCD/tree/master

which has a couple of libraries that looked to be close to what I was after. One is BCD and the other is ICD (Integer Coded Decimal). They are both C++ for some microsoft dialect, so I have mangled the Icd library so that it compiles under Linux and also ported it over to the Pio where it does indeed run.

My mangled code is here:

https://github.com/blackjetrock/bcd.git

This is definitely a mangled work in progress. I've run some quick tests on the Pico and it appears to work.

That's the good news. The bad news is that it doesn't do exponents, and so the range is about +/- 1E38 to +/- 1E-38. So almost what I am after. I think it might do.