Arbitrary Precision Decimal Arithmetic by Arduino

Hi. I recently published a new calculator project for Arduino arithmetic and decimal computing like humans do and it needs being improved for AI. Thanks for all advices and contributions. Sincerly giocip.

1 Like

Is there an actual question here? The question doesn't make much sense to me.

You might want to look at this How to get the best out of this forum before you proceed any further.
We only know what you tell us, and without knowing what you have, and why you want to do this, we don't stand a chance.

What does that mean?

1 Like

Hi @grumpy_mike and others, i mean the two mostly AI cutting edge features like voice and commands recognition integration Arduino project or tutorial and visual recognition ones!

First of all, use the forum standard technique when tagging others as @Grumpy_Mike. Secondly, use AI to give your writing a little help; your word salad makes no sense and is debatable. I HATE VOICE operating mode, as do almost all my peers, so some social research is missing from your project.

suggest you post code as uploadable text instead of screen shots that are too small and hard to read

What do you mean by "arbitrary precision"? For example, what controls the number of digits in the result of calculating 1/7?

By using n7 Arbitrary Precision Decimal Calculator if you input division command:

n7 : 1.0 7.0
result => 0.1428571428571428571428571428571428571428 (40 floating point digits by default)

but this other division command:

n7 div 1.0 7.0 1000
result => 0.142857142857142857142857142857142857142857142857142 ...1428571428

with 1k floating point digits.

You could specify till 2^32-1 (more than 2 billion of floating point digits) limited only
by your own Arduino static RAM and time requested by division C++ algorithm.

Ok.

Tell me if you need one or more specific n7 arithmetic operation command in text format.

Interesting homework.

Expect the next assignment will be about significant digits.
This is about absolute and relative errors, rounding and that kind of math in practice.

Minimalistic explanation of significant

1.0 : 7.0 = 0.14 as both numerator and denumerator only have 2 significant digits.

Test understanding significant:

What is 1.00 : 7.00


Note: div is in the programming world an integer division (close relative to mod).

Homework: implement mod == modulo % or remainder e.g. 35 mod 3 = 2

Arduino n7 calculator can actually perform:

n7 : 1 7
result => 0.1428571428571428571428571428571428571428

n7 rnd 0.1428571428571428571428571428571428571428 2
result => 0.14

n7 : 1.0 7.0
is equivalent to
n7 : 1.00 7.00
both result => 0.1428571428571428571428571428571428571428

For significant digits perhaps the n7 command:

n7 div 1.00 7.00 5
result => 0.14285

and then n7 command:

n7 rnd 0.14285 4
result => 0.1429

could solve it?

For the Homework question n7 command:

n7 % 35 3
result => 2.0

should done it!

if it is just 1 digit after the dot, then an answer with 2 digits makes no sense :))).
Should be 0.1 :slight_smile:

Another more complex Arbitrary Precision Division example could be 3.141592654 divided 2.718281828 with 1000 floating point digits by n7 calculator command:

n7 div 3.141592654 2.718281828 1000
result => 1.1557273501369998490090336578595558341053663549709018619095149982365993288021936480384696888022605726664188993724899374193954991189383031110782969189609724308542153120702832436401807855517180023616006014811205955646774091593566728578373147259990438342436654805904842328953684930420687784548585813523674116987107342719579112015459494879130685929744588646825181218847481476081883294700081407452943470142640412044869101777330499816003625949266361353904470864895175983201989017600863717358448970950483799503956364601058577212399331832637333144103996857532610485449634547606592026998607445349849868473608469415850430355008796387392102302646155202123508438507649840346134999803265432417112858689205790474791048781568796184440372162911725869801900467253537479778936299463059207119122896185582711403830199169473313346227468508096136969061914355703076127101269795193583584520066916328589016340950207021727549877878225656887259300031637484794310297688529447065118665098179805070602120068324276786505449868312918

why not two steps n7 calculator commands:

n7 : 1.0 7.0
result => 0.1428571428571428571428571428571428571428

n7 rnd 0.1428571428571428571428571428571428571428 1
result => 0.1 :innocent:

How many significant digits has 2346.0 : 23.0 ? 1 digits behind the dot?
How many significant digits has 2346 : 23 ? no digits behind the dot?

Do you have a link that explains that only digits behind the dots count?

In my schooldays I learned that there are

  • exact numbers with no errors (e.g. 7 days in a week) and
  • measurements (e.g. 7.0 liter in a bucket).
  • exact numbers for which we do not have all digits (e.g PI, handle as measurements).

Exact numbers have an unlimited amount of significant digits.
Measurements had to be interpreted with a set of rules (these four IIRC).

  1. all non zero digits are significant
  2. all zeros between two non zero digits are significant
  3. all trailing zeros are significant.
  4. leading zeros are not significant.

When an operator is applied to two numbers the number of significant digits of the answer is the minimum of the significant digits of the operands.

This can be proved when you add the absolute errors to the number
e.g 2346.0 ==> 2346.0 +- 0.05 (in effect a range)
Using the error notation a single addition or subtraction had to be done 4 times to see the possible range of the answer. This shows the above rule works.
Other operators e.g. multiply and division need to use the relative errors.

And when we covered the above the teacher continued about all things that could go wrong with measurements, systematic errors and random errors, about calibration, physical effects that affect measurements (e.g. temperature of boiling water depends on air pressure and salinity of the water etc), limited accuracy of computer representations etc.

1 Like

I queried ChatGPT for your valuable questions and AI reports:

2346.0÷23.0=102.000 => 102
2346÷23=102.0 => 100

About "... about all things that could go wrong" this Arduino n7 calculator overcomes
"limited accuracy of computer representations" by using Arbitrary Precision Decimal Arithmetic algorithms. :tiger_face:

@robtillaart is right to question your claim, because it is wrong.

The number of significant digits is determined by error propagation analysis.

For a calculated result y with inputs xk (k = 1,...,n)

y = f(x1, x2, x3,..., xn)

the uncertainty in y (denoted Uy) depends on the input uncertainties as follows:

Uy = [Σ(∂f/∂xk·Uk)2]½

where Uk is the uncertainty in the input value xk, and ∂f/∂xk denotes the partial derivative of the function f with respect to the variable xk (holding all other input arguments constant); the sum is taken over k = 1,...,n. The above result assumes that the input uncertainties are independent (uncorrelated).

The least significant digit of the computed result y is then going to have the same order of magnitude (i.e., the same position relative to the decimal point) as the most significant digit of the uncertainty Uy.

For simple arithmetic operations, this typically boils down to:

  • Addition/Subtraction: The least significant digit of the sum/difference generally matches the least significant digit of the input that has the lowest absolute precision (e.g., the fewest number of decimals after the decimal point). For example: 1234.5 + 0.12 = 1234.6).
  • Multiplication/Division: The total number of significant digits in the product/quotient generally matches the lowest number of significant digits among the inputs. For example: 2π×2.54×0.01000 = 0.160).
1 Like

Should be 102 if the inputs are exact integer values, or 1.0×102 (which is not the same as "100") if the two inputs have uncertainty in the final digit.

and then for a real n7 calculator two steps commands input:

n7 x 2 3.1415 2.54 0.01000
result => 0.1595882

n7 rnd 0.1595882 4
result => 0.1596

additional n7 calculator detail commands:

n7 : 2346 23
result (exact integer values) => 102.0

n7 rnd 102.0 -1
result (uncertainty in the final digit) => 100.0