Post Reply 
Searching for decimal library for RP Pico
08-26-2023, 05:15 AM
Post: #1
Searching for decimal library for RP Pico
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
Find all posts by this user
Quote this message in a reply
08-26-2023, 07:20 AM
Post: #2
RE: Searching for decimal library for RP Pico
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_ar...c_software
Find all posts by this user
Quote this message in a reply
08-26-2023, 07:51 AM
Post: #3
RE: Searching for decimal library for RP Pico
Great links - thanks!

blackjetrock, I'd be interested to hear about your progress, and what package you choose and what size it is.
Find all posts by this user
Quote this message in a reply
08-26-2023, 05:14 PM
Post: #4
RE: Searching for decimal library for RP Pico
(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_ar...c_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
Find all posts by this user
Quote this message in a reply
08-26-2023, 05:17 PM
Post: #5
RE: Searching for decimal library for RP Pico
(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?
Find all posts by this user
Quote this message in a reply
08-26-2023, 05:19 PM
Post: #6
RE: Searching for decimal library for RP Pico
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.
Find all posts by this user
Quote this message in a reply
08-26-2023, 09:11 PM
Post: #7
RE: Searching for decimal library for RP Pico
(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.

— Ian Abbott
Find all posts by this user
Quote this message in a reply
08-31-2023, 01:49 PM
Post: #8
RE: Searching for decimal library for RP Pico
(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.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)