Author Topic: BigNumNum Cruncher  (Read 30488 times)

0 Members and 1 Guest are viewing this topic.

Offline sammyMaX

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 204
  • Rating: +9/-0
    • View Profile
BigNumNum Cruncher
« on: August 13, 2011, 04:19:36 pm »
BigNumNum Cruncher is a bignum program for the Nspire, written in C. It should be able to handle numbers as big as the Nspire's RAM allows it to be, with one digit per byte. (This may not mean output being up to (number of available bytes of RAM) digits long, since in the instance 2^1000000, it would need to store 2^999999 to get to 2^1000000) I have finished the addition and multiplication functions, and have the basic GUI going, but a lot of work has to be done (Powers in beta testing for now) I have no school on 9/29/11, so hopefully some major work can be done.

BigNumNum Cruncher originally started in Lua but since then, I have moved over to C, since Lua was far too slow for this program. Numbers are stored in my program as arrays of ints, with only 4 digits able to be used in each int because of overflow. (Perhaps there is a way to fully utilize the RAM and double capacity?)

Spoiler For Changelog:
Version 0.01 Lua with GUI done
Version 0.02 Lua with addition
Version 0.03 Lua with subtraction
Version 0.04 Lua with multiplication and powers
Version 0.05 Lua with bug fixes

Version 0.10 C with GUI and addition
Version 0.11 C with less bugs
Version 0.12 C with multiplication
Version 0.13 C with powers and results less than 37 digits
Version 0.14 C with major speed up in addition and subtraction algorithms
Version 0.15 C major release memory allocation bug fixed
« Last Edit: January 20, 2012, 05:03:14 pm by sammyMaX »

Are you wondering who Sammy is? My avatar is Sammy.
   

Offline sammyMaX

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 204
  • Rating: +9/-0
    • View Profile
Re: [Lua] BigNumNum Cruncher
« Reply #1 on: August 14, 2011, 11:05:34 am »
Update: I have decided to move over and start the program in C with Ndless 2.0. It will be much faster, and when Ndless 3.0 comes out, only a few minor changes will have to be made. Expect an alpha in three to four days.

Are you wondering who Sammy is? My avatar is Sammy.
   

Offline sammyMaX

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 204
  • Rating: +9/-0
    • View Profile
Re: [Lua] BigNumNum Cruncher
« Reply #2 on: August 21, 2011, 04:47:55 pm »
Here is the UI in C (so far not functional):
On a side note, I am having a lot of trouble implementing the GMP-style limbs and branches, (Ndless isn't letting me do divison or mods) so I will revert back to my old system of numbers.
« Last Edit: August 21, 2011, 09:58:27 pm by sammyMaX »

Are you wondering who Sammy is? My avatar is Sammy.
   

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: [Lua] BigNumNum Cruncher
« Reply #3 on: August 21, 2011, 08:53:46 pm »
Awesome looking! (Why would you even need to calculate numbers this big anyways? :P)

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: [Lua] BigNumNum Cruncher
« Reply #4 on: August 21, 2011, 09:35:34 pm »
Are you having trouble with 64-bit (or possibly 32-bit) integer division? Is there a compiler error when you do so?
« Last Edit: August 21, 2011, 09:35:54 pm by t0xic_kitt3n »

Offline sammyMaX

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 204
  • Rating: +9/-0
    • View Profile
Re: [Lua] BigNumNum Cruncher
« Reply #5 on: August 21, 2011, 10:03:41 pm »
Spyro - Thanks! Most people won't need it, but it could be cool to show to your friends, and for those in math competitions (like Mathcounts) it could be a life saver.

Toxic kitten - yes, I am getting an error when doing mod (%) and division. I get compiler errors like "undefined reference to '__aeabi_idivmod'" or "undefined reference to '__aeabi_uidiv'". It would really help if you could explain this to me.

Are you wondering who Sammy is? My avatar is Sammy.
   

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: [Lua] BigNumNum Cruncher
« Reply #6 on: August 22, 2011, 01:00:04 am »
You are getting errors from newlib then. Make sure you have the latest version of GCC.

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [Lua] BigNumNum Cruncher
« Reply #7 on: August 22, 2011, 01:36:32 am »
Quote
"undefined reference to '__aeabi_idivmod'" or "undefined reference to '__aeabi_uidiv'". It would really help if you could explain this to me.
Don't use the -nostdlib compiler option :)
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: [Lua] BigNumNum Cruncher
« Reply #8 on: August 22, 2011, 07:14:31 am »
Spyro - Thanks! Most people won't need it, but it could be cool to show to your friends
Most of my friends don't even know what a graphing calculator is. :P

Offline sammyMaX

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 204
  • Rating: +9/-0
    • View Profile
Re: [Lua] BigNumNum Cruncher
« Reply #9 on: August 22, 2011, 08:43:06 am »
The -nostdlib option was the problem. (from me just modifying the makefile of the Hello sample and never catching on to that) Thanks guys!

Lol Spyro, in my school graphing calculators are required for 9th grade and above math. TI must make a lot of money off that...

Are you wondering who Sammy is? My avatar is Sammy.
   

Offline sammyMaX

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 204
  • Rating: +9/-0
    • View Profile
Re: [Ndless] BigNumNum Cruncher
« Reply #10 on: August 22, 2011, 10:35:39 am »
Some random tidbits about Lua vs. C (for Nspire programming)
1. C is much better for input, because it keys being pressed instead of the character a button corresponds to (which is sometimes a weird, non-standard character)
2. C is MUCH faster
3. Lua supports color and developing for it is much easier
4. For my program, where the input is a variable length, C is HORRIBLY hard to code. In Lua a string can be any length; getting C to create a string that can be a variable size (but stays the same length after declaration) requires malloc(), and when the string length changes each time you type... UGH!!!

Are you wondering who Sammy is? My avatar is Sammy.
   

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: [Ndless] BigNumNum Cruncher
« Reply #11 on: August 22, 2011, 12:25:48 pm »
getting C to create a string that can be a variable size (but stays the same length after declaration) requires malloc(), and when the string length changes each time you type... UGH!!!
Try using realloc(), that will resize a buffer without modifying its contents (and may return a new pointer if the buffer couldn't be resized in-place). Of course, you may not want to reallocate for every character typed, so you could probably increase/decrease the size by, for example, 32 bytes at a time.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline sammyMaX

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 204
  • Rating: +9/-0
    • View Profile
Re: [Ndless] BigNumNum Cruncher
« Reply #12 on: August 25, 2011, 08:17:19 pm »
True... I really don't know what I was thinking when I wrote that post ??? because I had thought of realloc(), but for some reason it still seemed like a pain in the butt to write.

An update: I have 3-4 weeks to finish (at least get the most important power, factorial and multiplication functions done) before school starts. I plan on writing division and nth root approximation, but I haven't really learned that yet, so it may be far later in development when that gets implemented.

Are you wondering who Sammy is? My avatar is Sammy.
   

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: [Ndless] BigNumNum Cruncher
« Reply #13 on: August 26, 2011, 12:48:09 am »
I just make my string buffers long enough for whatever may occur. I never thought of using realloc :P

Offline sammyMaX

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 204
  • Rating: +9/-0
    • View Profile
Re: [Ndless] BigNumNum Cruncher
« Reply #14 on: August 26, 2011, 10:51:35 am »
Yeah, that works, but it isn't very elegant (seriously, using up like half a KB of RAM is not really a worry, it just doesn't seem pretty)

Are you wondering who Sammy is? My avatar is Sammy.