You've probably moved on, but I forked the micropython-decimal-number library so it worked more smoothly with CircuitPython too. It gives you more than enough precision.I am not getting what I expect
I tested it on a Adafruit Fruit Jam, and it passes both the accuracy and speed tests:
Code:
+-------------------------------------------------------------------------+| SYSTEM INFORMATION |+-------------------------------------------------------------------------+Implementation name: circuitpythonImplementation version: 10.0.0Implementation platform: RP2350CPU frequency: 150 Mhz+-------------------------------------------------------------------------+| PERFORMANCE WITH SCALE = 16 |+-------------------------------------------------------------------------+Scale (max. decimals): 16Iterations per test: 1000Number 1: 85385487522.6765840381861828Number 2: -4426111642.7466210026335771Addition (n1 + n2): 0.735 msSubtraction (n1 - n2): 0.896 msMultiplication (n1 * n2): 0.666 msDivision (n1 / n2): 0.619 msSquare root abs(n1): 2.253 msPower: (pi/2) ** 15 5.118 msDecimalNumber from int: 0.166 msDecimalNumber from string: 1.959 msIterations per test: 10Sine: sin(0.54321) 42.4 msCosine: cos(0.54321) 42.5 msTangent: tan(0.54321) 106.4 msArcsine: asin(0.54321) 137.5 msArccosine: acos(0.65432) 242.6 msArctangent: atan(1.2345) 261.7 msArctangent2: atan2(2.3456, 1.2334) 200.5 msExponential: exp(12.345) 82.9 msNatural logarithm: ln(12.345) 83.3 ms+-------------------------------------------------------------------------+| PERFORMANCE WITH SCALE = 50 |+-------------------------------------------------------------------------+Scale (max. decimals): 50Iterations per test: 400Number 1: 2177576182622613151315155417461352345042302802.40824144134477848263541280471658163042823336366688Number 2: 5482117000436836414246685274838603281647788.60315167056576870258683375630387828415735413036625Addition (n1 + n2): 1.0125 msSubtraction (n1 - n2): 1.2225 msMultiplication (n1 * n2): 0.8825 msDivision (n1 / n2): 0.72 msSquare root abs(n1): 8.4425 msPower: (pi/2) ** 15 6.345 msDecimalNumber from int: 0.19 msDecimalNumber from string: 6.6 msIterations per test: 4Sine: sin(0.54321) 94.75 msCosine: cos(0.54321) 94.75 msTangent: tan(0.54321) 211.75 msArcsine: asin(0.54321) 442.25 msArccosine: acos(0.65432) 710.0 msArctangent: atan(1.2345) 765.5 msArctangent2: atan2(2.3456, 1.2334) 524.25 msExponential: exp(12.345) 160.0 msNatural logarithm: ln(12.345) 159.0 ms+-------------------------------------------------------------------------+| CALCULATING PI |+-------------------------------------------------------------------------+Pi with 300 decimals: 3.027 s3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141274Statistics: Posted by scruss — Thu Sep 25, 2025 11:08 pm