Small numbercial analysis question

  • Thread starter Thread starter DrKareem
  • Start date Start date
  • Tags Tags
    Analysis
Click For Summary

Discussion Overview

The discussion revolves around a numerical analysis problem involving the handling of large numbers in C++. Participants explore various data types and libraries that can accommodate calculations beyond standard integer limits.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant encountered issues with integer overflow in C++ when using standard integers for large calculations and switched to long integers, but still faced limitations.
  • Another participant suggests creating a larger integer class in C++ or using existing C++ numerics libraries for handling large integers.
  • There is a suggestion to consider using "long long" or "__int64" for 64-bit integers, or to switch to Java's BigInteger class for larger numbers.
  • Some participants propose using floating-point types like "double" or "long double" if integers are not strictly required.
  • One participant mentions the possibility of using 128-bit integer operations if the processor supports SSE2 instructions for numbers greater than 10^19.
  • Another participant recommends ubasic, a tool that can handle integers and rational numbers up to 2600 digits long.

Areas of Agreement / Disagreement

Participants express various approaches to handling large numbers, with no consensus on a single solution. Multiple competing views remain regarding the best method or library to use.

Contextual Notes

Limitations include the dependence on specific programming environments and the varying capabilities of different data types and libraries. Some suggestions may require additional testing or familiarity with the proposed tools.

Who May Find This Useful

Programmers and developers working with numerical analysis in C++ or those interested in handling large numerical data types in programming.

DrKareem
Messages
101
Reaction score
1
I was doing a small numbercal analysis problem that required the use of huge numbers. At first i was surprised that my code didn't work, even after double and triple checking, and after tracing the programme, i found out the mistake that i did. Firstly i used integers, and when the numbers started to increase they went bigger than the integer number range on C++ and started to give a negative number. Anyways, i used long and it worked ok for most of the numbers that needed calculations, but still some iteration couldn't be done since they also went out of range.

How could i solve this problem?
 
Computer science news on Phys.org
Wow, well in the case of integers it is a simpler problem. Extending floating point datatypes is more complicated.

It is not so hard to create a larger integer class as long as you follow the same bitwise rules than intrinsic integer types follow. And the basic arithmetic operators can be overriden in C++ to make it pretty transparent.

But to save you some trouble, there are many C++ numerics libraries out there that have already done this. Try starting with "c++ numerics library" in google.

I can't speak for any of them because I haven't used them before.
 
Thx, will do.

Still open to more suggestions though :)
 
Are 64 bits enough for you? If so then use long long (with g++) or __int64 (with VS); or their unsigned counterparts. Otherwise a quick solution might be to switch to Java and use the library class BigInteger.
 
Last edited by a moderator:
Last edited:
I'm thankful. It hasn't occurred to me to use Java, which i will be doing, and for educational purposed i'll also check out and test the links grady and robphy gave.
 
If you don't have to work in Unix, get ubasic (free download) from
http://www.simtel.net/category.php?id=299

It comes "ready to go" with built-in capability to handle integers and rational numbers up to 2600 DIGITS long, plus other impressive features.
 
Last edited by a moderator:

Similar threads

Replies
4
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
8
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K