Author Topic: Working with Large Numbers?  (Read 5388 times)

0 Members and 1 Guest are viewing this topic.

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Working with Large Numbers?
« on: November 15, 2010, 12:27:37 am »
Hello: I'm working on a project that involves manipulating numbers larger then 65535, and Axe obviously doesn't have built-in support for that.
However, I do know that programs like Cabamap can push around absurdly large numbers - how can I manually do that in Axe?
For example, how could I write a routine that could handle something like 365940/367153?
Is it possible to set up some free ram in such a way that I could use (for example) four bytes to get numbers up to 256^4-1 (4294967295)?
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Working with Large Numbers?
« Reply #1 on: November 15, 2010, 12:33:19 am »
You'd probably have to designate each variable as a certain number of bytes and write the overhead to manipulate each collection of bytes as a single number.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Working with Large Numbers?
« Reply #2 on: November 15, 2010, 05:56:25 am »
Axe actually does have some support for larger numbers.  You will want to look into the *^ (high order multiplication) routine as it captures the overflow when the numbers don't fit into a single variable.  Addition overflows can also be detected by checking if the result after the addition was smaller than the original number.  I'm sure calc84maniac could help you out with the routines, but basically its just like how you would do "long" multiplication by hand but instead of digits, you have 16-bit numbers.  The algorithm is the same as the one you were taught in elementary school, you just never really think about it like that.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Working with Large Numbers?
« Reply #3 on: November 15, 2010, 11:55:41 am »
Hmm I would like to know more about how to use that... It might be handy in the future if I ever work with RPGs with numbers that goes beyond the 2 byte range. Is it very large?

Offline calcforth

  • LV3 Member (Next: 100)
  • ***
  • Posts: 62
  • Rating: +4/-4
    • View Profile
Re: Working with Large Numbers?
« Reply #4 on: November 15, 2010, 12:46:55 pm »
Hmm I would like to know more about how to use that... It might be handy in the future if I ever work with RPGs with numbers that goes beyond the 2 byte range. Is it very large?
You can take a look on Learn TI-83 Plus Assembly In 28 Days. It explains how to do this effeciently in ASM and Axe is a thin wrapper thus the same principle apply. Of course all this will not help the topic starter: addition/subtraction of long integers are trivial, multiplication is harder but division is a bitch to write correctly. What is relatively easy to write is division of long integer by small (less then 16bit) integer - and it's MUCH faster too. Stay away from long divisions if it all possible!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Working with Large Numbers?
« Reply #5 on: November 15, 2010, 07:37:28 pm »
Well I meant in Axe language, not ASM language.

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Working with Large Numbers?
« Reply #6 on: November 15, 2010, 08:16:33 pm »
So basically, I have to convert my input to base 16, then use an algorithm similar to multiplying/dividing by hand in order to manipulate my numbers?
Hmm, working with base 16 might be a bit painful...
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Working with Large Numbers?
« Reply #7 on: November 15, 2010, 09:28:48 pm »
So basically, I have to convert my input to base 16, then use an algorithm similar to multiplying/dividing by hand in order to manipulate my numbers?
Hmm, working with base 16 might be a bit painful...
Not base 16, 16-bit. You treat a whole 16-bit variable like a digit. Then with 32-bit, you're working with "two-digit" values at the most.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Working with Large Numbers?
« Reply #8 on: November 15, 2010, 10:01:46 pm »
So basically, I have to convert my input to base 16, then use an algorithm similar to multiplying/dividing by hand in order to manipulate my numbers?
Hmm, working with base 16 might be a bit painful...
Not base 16, 16-bit. You treat a whole 16-bit variable like a digit. Then with 32-bit, you're working with "two-digit" values at the most.
?
Is there a difference?
By 16 bit, each digit ranges from 0-F?  Isn't this identical to base 16?
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Working with Large Numbers?
« Reply #9 on: November 15, 2010, 10:04:55 pm »
16-bit means 16 bits, so 4 hexadecimal digits (each is 4 bits)
Base 16 means that the sixteenth number from 1 is 10h.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Working with Large Numbers?
« Reply #10 on: November 15, 2010, 10:05:38 pm »
Ah.  I see.
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.