Mathematical calculations with numbers greater than 65535 and a picaxe 18m2

miglio

New Member
Hi I'm Roberto, I'm new to picaxe, I'm experimenting with an 18m2 and I should do this calculation divide in 4 bytes the number 558947043. Do you have any ideas? Actually that's the result of this calculation 16270000 * 4294967296 / 125000000 which I don't know if the 18m2 will allow me to do. Thank you all for any answers
 
This is a set of X2 32-bit arithmetic routines for addition, subtraction, multiplication and division, plus some test and shift routines. Not particularly well-documented, but I'm happy to explain more if it is useful. NOTE: the X2 arithmetic allows the use of the shift operators >> and << which have to be replaced by appropriate divisions or multiplications for use in an M2 chip. I don't have an 18M2 but I see no reason why the principles cannot be applied. I've had to add a .txt extension to allow it to be uploaded.
 

Attachments

Hi,
.. that's the result of this calculation 16270000 * 4294967296 / 125000000 which I don't know if the 18m2 will allow me to do.
4294967296 is actually 232 so cannot be contained in a 32-bit word and obviously the intermediate calculation 16270000 * 4294967296 would need to use 64-bit maths and then a 64-bit division routine to divide by the 125000000. However, the calculation could be simplified by pre-dividing the numerator and divisor by 10000 first, but I think still exceeds 32-bit maths.

A problem with doing very long binary calculations is that the numbers may need to be converted back to "meaningful" (denary/decimal) numbers, for example it wasn't obvious to me the value of 232 was used until I calculated it. However, I have written a number of 32-bit maths routines, for example for the code snippets section HERE (which includes methods for 32-bit multiplication, division, addition and subtraction) and perhaps this very complex thread HERE.

An alternative method is to use "ASCII Arithmetic" which uses a separate memory location (byte) to store each (weighted) digit of 0 - 9 to perform the normal schoolboy-type "Longhand" calculations, or an old mechanical calculating machine. PICaxe has more than enough "indirect" RAM (using PEEK/POKE or @BPTR constructs) but I'm not aware that anybody has actually written any such Programs for the PICaxe. These calculations are likely to be very slow with a PICaxe!

Cheers, Alan.
 
Thank you Aries and Alan, I will read carefully and then if I succeed I will let you know the developments.



Thanks Roberto
 
Hi Roberto.

I would use a microcontroller that can do floating point math's such as pic32mx series of controllers or raspberry pico controller.

A program like MMbasic can be installed on ether devices and is very similar to picaxe basic. For more information refer to
The backshed forum.


Firware and manual for mmbasic and the pico.


https://geoffg.net/picomite.html


Bill
 
Last edited:
Hi Roberto.



I would use a microcontroller that can do floating point math's such as pic32mx series of controllers or raspberry pico controller.



A program like MMbasic can be installed on ether devices and is very similar to picaxe basic. For more information refer to

The backshed forum.






Firware and manual for mmbasic and the pico.





https://geoffg.net/picomite.html





Bill
Very interesting Bill. Many thanks
 
Back
Top