473,396 Members | 1,921 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,396 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


Jul 21 '05 #1
8 1655
Sam,

What is the type of the source of that number?

Cor
Jul 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

Jul 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


Jul 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]
Jul 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

Jul 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
|
|
|
|
Jul 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


Jul 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

Jul 21 '05 #9

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

Similar topics

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...
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...
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?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.