sageryd
asked on
Large variables?
Hi everybody.
I'm making a "perfect number finder", to find certain mathematical numbers. But the results are too big to fit into a variable. I have very large numbers. There must be someway to store these, look at the calculator that comes with windows, it handles 36 places, and after that it goes over to exponentials. I want my program to works just like that.
How can this be done?
--johan
I'm making a "perfect number finder", to find certain mathematical numbers. But the results are too big to fit into a variable. I have very large numbers. There must be someway to store these, look at the calculator that comes with windows, it handles 36 places, and after that it goes over to exponentials. I want my program to works just like that.
How can this be done?
--johan
The standart Delphi functions allow to 19 digits with double or Int64. If you want to more up digits you must write.
Sageryd,
The largest integer type you can get is an int64 which uses 8 bytes. A normal integer uses 4 bytes and has a range of –2147483648 to 214748364. An int64 should be able to handle most values.
An int64 has the range –2^63..2^63–1.
To specify an int64 instead of using
var
number : integer;
use
var
number : int64;
A real number is a decimal point number. An 'comp' real has the range -2^63+1 to 2^63 –1. Where as the usual real has the range much lower. For more help refer to the online help. Lookup int64, and floating-point numbers.
Hope that helps.
The largest integer type you can get is an int64 which uses 8 bytes. A normal integer uses 4 bytes and has a range of –2147483648 to 214748364. An int64 should be able to handle most values.
An int64 has the range –2^63..2^63–1.
To specify an int64 instead of using
var
number : integer;
use
var
number : int64;
A real number is a decimal point number. An 'comp' real has the range -2^63+1 to 2^63 –1. Where as the usual real has the range much lower. For more help refer to the online help. Lookup int64, and floating-point numbers.
Hope that helps.
sorry as i was typing the response you added that comment. I am pretty sure you are right, you need some code. I advise you look on http://www.delphipages.com under mathematical components, i am sure there will be one that does what you want.
Andrew
Andrew
Try to make one component from array of char, and then parse it to numeric.
Ex.
A : Array[1..100] Of Char;
B : Array[1..100] Of Char;
Result : Array[1..100] Of Char;
....
A = 123456789123456787
B = 972482384837283283
-------------------------- -- +
Result = .....parse char by char
The logic is like that, i ever made that but in C++.
Hope this can help !
Ex.
A : Array[1..100] Of Char;
B : Array[1..100] Of Char;
Result : Array[1..100] Of Char;
....
A = 123456789123456787
B = 972482384837283283
--------------------------
Result = .....parse char by char
The logic is like that, i ever made that but in C++.
Hope this can help !
Or If you think using array of char is to slow, than you can use array of Integer or longInt
Like :
A : Array[1..20] Of Integer;
So you can assume that first array is first 5 digits.
A[1] --> digit 1 - 5
A[2] --> digit 6 - 10
....
....
....
A[20] --> digit 96 - 100
Hope this can help you...
Like :
A : Array[1..20] Of Integer;
So you can assume that first array is first 5 digits.
A[1] --> digit 1 - 5
A[2] --> digit 6 - 10
....
....
....
A[20] --> digit 96 - 100
Hope this can help you...
ASKER
Ok, good solutions. But how can I easily assign my calculated number to the constructed variable(s)?
--johan
--johan
How you represent calculated numbers in memory ?
May be you only need procedure of displaying them as string ?
May be you only need procedure of displaying them as string ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well....thanks Alex, but I'm not sure on how it works...can you give an example?
ASKER
Sorry it took so long, I've been working on another project for some time, the numberfinder has low priority. Thanx for all your help!
--johan
--johan
Extended up to 1.1 x 10^4932
Comp up to 2^63 - 1
If you want to hold bigger numbers, I think there is no simple way to do that. You should to write your own procedures to work with numbers.