473,804 Members | 2,296 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1679
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******** ******@tk2msftn gp13.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(bigN umberString);
bigNumber.ToStr ing();

or even

ulong bigNumber = ulong.Parse(big NumberString);
bigNumber.ToStr ing();

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******** ******@tk2msftn gp13.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*****@micros oft.com> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l...
| 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*****@micros oft.com> wrote in message
news:e$******** *****@TK2MSFTNG P12.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******** ******@tk2msftn gp13.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..jwaon line..com
-----------------------------------------------------------------------
"Sam Fisher" <so*****@micros oft.com> wrote in message news:%2******** **********@TK2M SFTNGP10.phx.gb l...
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
1622
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 integers or decimals of any length. I am currently developing maths programs in PHP, and PHP has a 'large number' type facility, but have been considering a switch to C++ as its faster.
3
23761
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 by C# or they are hardware (processor) dependent. Basic addition operation errors, for ex: 3.6 - 2.4 = 1.19999999999 or 1.20000000003 There are the erroneous values I'm getting. I'm using C#.Net v1.1 Please reply me how these operations are...
8
1787
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 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...
0
955
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 has the 'BC arithmetic' function that allows arithmetic involving very large numbers. Its just that I am considering switching languages from PHP to maybe C++ or VB.net
6
2417
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
2862
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 real numbers. This is the floating-point representation. However as we may all know, floating-point numbers are quite inaccurate. This means that ½ might actually be represented as 0.49998, which may not be good enough for some applications. In this...
3
1998
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does simple decimal arithmetic give strange results? ----------------------------------------------------------------------- For example, 5*1.015 does not give exactly 5.075 and 0.06+0.01 does not give exactly 0.07 in javascript. Javascript numbers are represented in binary as IEEE-754 (IEC 559) Doubles, with a resolution of 53 bits, giving an...
2
1583
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does simple decimal arithmetic give strange results? ----------------------------------------------------------------------- For example, 5*1.015 does not give exactly 5.075 and 0.06+0.01 does not give exactly 0.07 in javascript. Javascript numbers are represented in binary as IEEE-754 (IEC 559) Doubles, with a resolution of 53 bits, giving an...
2
1901
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does simple decimal arithmetic give strange results? ----------------------------------------------------------------------- For example, ` 5 * 1.015 ` does not give exactly ` 5.075 ` and ` 0.06+0.01 ` does not give exactly ` 0.07 ` in javascript. ECMAScript numbers are represented in binary as IEEE-754 (IEC 559)
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10599
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10346
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10090
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9173
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.