Arbitrarily Big Integer Routines

User projects written in or related to FreeBASIC.
stephanbrunker
Posts: 62
Joined: Nov 02, 2013 14:57

Re: Arbitrarily Big Integer Routines

Post by stephanbrunker »

@ur_naz: Speed is something very difficult to get with FB generally. I made a few crypto implementations and they all are slower than their counterparts. And so that is not what I had in mind as I improved this datatype from terrible to acceptable. The idea was to make an easy access to big integer calculating and I think it cannot be easier than this, which works just like an integer. I am no expert on the inner workings of the FB compiler, but I'd bet that has to do with the string handling. It's the same there: as easy as the STRING is in usage, it is not very fast. I have worked around that as far as I could without to clog the code but the handicap remains. But I don't think any sane full-time programmer tasked to write an performance-critical application will resort to FB anyway. But if you (like me) just write a few lines of code once or twice a year, it is far easier to get into the stuff. I have an application for Android written in Java out there and I have to expand it somewhat - and I know it will be days until I am comfortable again because my last concact with Java was 1 1/2 years ago.

@Makoto WATANABE: I think your question is better asked in the "getting started with Freebasic" section. There are a lot of people out there which are much better in explaining basic input and output operations which have nothing to do with this datatype. There are quite a lot of approaches to this problem, ranging from the input function over inkey up to an Windows GUI ...
integer
Posts: 408
Joined: Feb 01, 2007 16:54
Location: usa

Re: Arbitrarily Big Integer Routines

Post by integer »

Makoto WATANABE wrote:Dear stephanbrunker

Thanks for your quick reply.
Please excuse my inadequate expressions.
I'd like to enter numbers using "Input" command instead of the command line.
Please teach me a sample program.
Try this:

Code: Select all

#include "biginteger_v28.bas"         '' <-- or what you have named it

dim as string bunchodigits
dim as bigint abignummer

input "enter some decimal digits";bunchodigits
abignummer = cbig(bunchodigits)

print "number as entered from keyboard: ";bunchodigits
print "converted to a bigint                  :";abignummer
print "& squared = ";abignummer*abignummer
OUTPUT:
  • number as entered from keyboard: 123456789876543210123456
    converted to a bigint : +123456789876543210123456
    & squared= +15241578966620942051516341899101137082761383936
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Arbitrarily Big Integer Routines

Post by srvaldez »

there should be no need to explicitly call the conversion function, this should work

Code: Select all

dim as bigint abignumber
dim as string s

input "enter a BigInt number ",s

abignumber = s ''automatically casted to Bigint 
abignumber = abignumber + abignumber
s = abignumber ''automatically casted to String
stephanbrunker
Posts: 62
Joined: Nov 02, 2013 14:57

Re: Arbitrarily Big Integer Routines

Post by stephanbrunker »

I have created a github repository and moved the code there. Because the total of 2000 lines, i have split the code into multiple parts, depending on the tasks they do, like the constructors, conversion functions and so on. I have also created an extensive readme with all the neccessary information.

https://github.com/stephanbrunker/big_integer
Makoto WATANABE
Posts: 231
Joined: Apr 10, 2010 11:41
Location: Japan
Contact:

Re: Arbitrarily Big Integer Routines

Post by Makoto WATANABE »

Dear stephanbrunker
Dear integer
Dear srvaldez

Thank you very much for teaching me how to write programs.
I will be getting started with big_integer-master.
ur_naz
Posts: 49
Joined: Mar 02, 2016 12:44

Re: Arbitrarily Big Integer Routines

Post by ur_naz »

Maybe stack instead string would be faster
Post Reply