473,382 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Arithmetic operations with large numbers

Hi,
I have a situation where I have to support a large number(not decimals),
something of the order of 20 to 30 digits in the database(sql server 2000)
I am not able to use LONG data type as it exceeds the limit, so I am
thinking of using the string value now. But do not know how to do the
arithmetic operations on this large number, I need the simple operations
like incrementing the number by one etc.

Any help will be greatly appreciated.

Sam


Nov 21 '05 #1
8 1769
Sam,

What is the type of the source of that number?

Cor
Nov 21 '05 #2

They are basically the certified mail article numbers
They are going to be numeric, but they are right now fixed length 20 chars
I can very well store them as String(Varchar) in the application, but I do
not know how to increment these numbers. I think I need help on conversion
of these stings to number with some numeric format and then increment it,
then get the string representation to save it back to the database.
Thanks
"Cor Ligthert" <no************@planet.nl> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
Sam,

What is the type of the source of that number?

Cor

Nov 21 '05 #3
Sam,
Could you not use something like:

long bigNumber = long.Parse(bigNumberString);
bigNumber.ToString();

or even

ulong bigNumber = ulong.Parse(bigNumberString);
bigNumber.ToString();

Jason Newell, MCAD
Software Engineer
Sam Fisher wrote:
They are basically the certified mail article numbers
They are going to be numeric, but they are right now fixed length 20 chars
I can very well store them as String(Varchar) in the application, but I do
not know how to increment these numbers. I think I need help on conversion
of these stings to number with some numeric format and then increment it,
then get the string representation to save it back to the database.
Thanks
"Cor Ligthert" <no************@planet.nl> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
Sam,

What is the type of the source of that number?

Cor


Nov 21 '05 #4
In article <e$*************@TK2MSFTNGP12.phx.gbl>, Sam Fisher wrote:

They are basically the certified mail article numbers
They are going to be numeric, but they are right now fixed length 20 chars
I can very well store them as String(Varchar) in the application, but I do
not know how to increment these numbers. I think I need help on conversion
of these stings to number with some numeric format and then increment it,
then get the string representation to save it back to the database.
Thanks


According to the documentation the largest possible decimal value with a
scale of 0 (no decimal places is)
+/-79,228,162,514,264,337,593,543,950,335. Is it likely you will ever
exceed this limit?

If you think they will, then you would probably be better off storing
them as a byte array and then writting functions to handle the
mathimatical operations... Of course, it may be easier to find a
pre-existing arbitrary precision integer library.

--
Tom Shelton [MVP]
Nov 21 '05 #5
Sam,

I don't think that you have much possibilities.

You can use the classic method for accumulators of course

You can splits them in two string from 10
assuming you add 20 the last value is 9.999.999.999 and the first is
1,000,000,000

convert them to two int64 and than when you add 20 and the the last becomes
9.999.999.999 than add 1 to the first value and set the second to the

difference.

Than it will be
1.000.000.001 and the second 0.000.000.019

Just my thought,

Cor

Nov 21 '05 #6
Sam,
| I am not able to use LONG data type as it exceeds the limit,
I would consider doing something similar to what Cor suggests, Define a
LongLong data type (an Int128 if you will) . I would consider making this
data type an immutable Structure that has two Long fields, a low order long
& a hi order long. Possible four Integers...

Then define the "operators" that I needed on it.

I would consider using C# or VB 2005 as defining the low order long as a
unsigned long would be easier...

The "trick" is going to be defining your operators, as you need to go back
to Math 101 & remember how to carry & borrow digits when you add & subtract
the numbers. Hint each of the fields (2 longs or 4 integers) represent a
"digit"...

Doing a quick google search, I found the following that may give you an idea
of how to do this.

http://blogs.msdn.com/ajenner/default.aspx

HINT: You need unchecked math, alternatively you could handle the exception
when the low digits have an overflow exception... Again unsigned for the low
digits would be easier...

Hope this helps
Jay


"Sam Fisher" <so*****@microsoft.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
| Hi,
| I have a situation where I have to support a large number(not decimals),
| something of the order of 20 to 30 digits in the database(sql server 2000)
| I am not able to use LONG data type as it exceeds the limit, so I am
| thinking of using the string value now. But do not know how to do the
| arithmetic operations on this large number, I need the simple operations
| like incrementing the number by one etc.
|
| Any help will be greatly appreciated.
|
| Sam
|
|
|
|
Nov 21 '05 #7
there are a number of large integer libraries out there -- one of which can
be found here http://www.codeproject.com/cpp/Large_Integer.asp

"Sam Fisher" <so*****@microsoft.com> wrote in message
news:e$*************@TK2MSFTNGP12.phx.gbl...

They are basically the certified mail article numbers
They are going to be numeric, but they are right now fixed length 20 chars
I can very well store them as String(Varchar) in the application, but I do
not know how to increment these numbers. I think I need help on conversion
of these stings to number with some numeric format and then increment it,
then get the string representation to save it back to the database.
Thanks
"Cor Ligthert" <no************@planet.nl> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
Sam,

What is the type of the source of that number?

Cor


Nov 21 '05 #8
Use System.Decimal

From MSDN:

The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative
79,228,162,514,264,337,593,543,950,335.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Sam Fisher" <so*****@microsoft.com> wrote in message news:%2******************@TK2MSFTNGP10.phx.gbl...
Hi,
I have a situation where I have to support a large number(not decimals), something of the order of 20 to 30 digits in the
database(sql server 2000)
I am not able to use LONG data type as it exceeds the limit, so I am thinking of using the string value now. But do not know how
to do the arithmetic operations on this large number, I need the simple operations like incrementing the number by one etc.

Any help will be greatly appreciated.

Sam

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sam Fisher | last post by:
Hi, I have a situation where I have to support a large number(not decimals), something of the order of 20 to 30 digits in the database(sql server 2000) I am not able to use LONG data type as it...
5
by: Jeremy Watts | last post by:
Hi, I'm a C++ newbie and wondered whether C or C++ have an 'arbitrary length' arithmetic facility, similar to say JAVA's 'BigInteger', that will carry out arithmetic operations symbolically on...
3
by: Madan | last post by:
Hi all, I had problem regarding float/double arithmetic only with + and - operations, which gives inaccurate precisions. I would like to know how the arithmetic operations are internally handled...
0
by: Jeremy Watts | last post by:
Hi, Does VB.net have an 'arbitrary length' arithmetic feature? Meaning can it handle very large real/integer number arithmetic symbolically like some other languages can? PHP for instance...
6
by: Devrim GUNDUZ | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, We were performing some tests on PostgreSQL and found that it fails on the following query: SELECT 512*18014398509481984 AS result;
1
by: ben kipkorir | last post by:
In this assignment we shall look at a possible representation of rational numbers in java using objects. The java language represents rational numbers using the same representation used for other...
3
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does simple decimal arithmetic give strange results?...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does simple decimal arithmetic give strange results?...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does simple decimal arithmetic give strange results?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.