ADA - Ada.Numerics.Big_Numbers.Big_Integer has upper limit?

  • Thread starter MFerguson
  • Start date
  • Tags
    Limit
In summary, the Big_Integer library has a default limit of 300 digits for numbers that it calculates. This limit can be modified, but it is not clear how to do so.
  • #1
MFerguson
1
0
I just started using the Big_Integer library that is a part of the 202X version of ADA.

It is repeatedly described as an "arbitrary precision library" that has user defined implementation.

I was under the impression that this library would be able to infinitely calculate numbers of any length, but there is clearly a default limit of 300 digits.

Is there any way to get rid of this problem?

Here is some example code:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Numerics.Big_Numbers.Big_Integers;
use Ada.Numerics.Big_Numbers.Big_Integers;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Test is
package Time_IO is new Fixed_IO(Duration);
start_time, end_time : Ada.Real_Time.Time;
elapsed_seconds : Ada.Real_Time.Time_Span;
solution : Unbounded_String;

rop : Big_Integer;
sum : Big_Integer := 0;

begin
start_time := Ada.Real_Time.Clock;

for i in 1..700 loop
rop := To_Big_Integer(i) ** Natural(i);
sum := sum + rop;
end loop;
solution := To_Unbounded_String(sum'Image); end_time := Ada.Real_Time.Clock;
elapsed_seconds := end_time - start_time;
Put("Solution: " & solution'Image); New_Line; New_Line;
Put("Program completed in ");
Time_IO.Put(To_Duration(elapsed_seconds), Fore => 0, Aft => 3);
Put(" seconds");
end BigTest;
 
Technology news on Phys.org
  • #2
Do you want Big Integers or arbitrary precision reals? If the latter then there must be a (modifiable) limit otherwise the calculation of e.g. 1/10 would not terminate.
 
Last edited:
  • Like
Likes sysprog
  • #3
MFerguson said:
I just started using the Big_Integer library that is a part of the 202X version of ADA.

It is repeatedly described as an "arbitrary precision library" that has user defined implementation.

I was under the impression that this library would be able to infinitely calculate numbers of any length, but there is clearly a default limit of 300 digits.

Is there any way to get rid of this problem?

Here is some example code:
 
  • #4
ADA is not the Ada programming language. The former is an acronym, a three letter one at that. The latter, Ada, is the name of the programming language, named after Ada Lovelace, credited by many as being one of, or the first programmer. She worked with Charles Babbage in the mid Nineteenth Century in designing an analytic machine, later evolved into modern digital computers.
 

Related to ADA - Ada.Numerics.Big_Numbers.Big_Integer has upper limit?

1. What is the purpose of Ada.Numerics.Big_Numbers.Big_Integer?

Ada.Numerics.Big_Numbers.Big_Integer is a data type in Ada that allows for the representation of integers with a much larger range than the standard integer data types. It is designed to handle numbers that are too large to be stored in a regular integer type, allowing for more precise and accurate calculations.

2. What is the upper limit of Ada.Numerics.Big_Numbers.Big_Integer?

The upper limit of Ada.Numerics.Big_Numbers.Big_Integer is dependent on the implementation of the compiler and the amount of memory available in the system. However, it is typically much larger than the upper limit of regular integer types, often in the range of hundreds of digits.

3. How does Ada.Numerics.Big_Numbers.Big_Integer store and handle large numbers?

Ada.Numerics.Big_Numbers.Big_Integer uses a dynamic memory allocation approach to store large numbers. This means that the amount of memory allocated for the data type will vary depending on the size of the number being stored. This allows for efficient storage and handling of large numbers without taking up unnecessary memory space.

4. Is there a performance trade-off when using Ada.Numerics.Big_Numbers.Big_Integer?

Yes, there is a performance trade-off when using Ada.Numerics.Big_Numbers.Big_Integer compared to regular integer types. Since it uses dynamic memory allocation, there is extra processing time needed to allocate and deallocate memory. However, the precision and accuracy provided by this data type may be worth the performance trade-off in certain applications.

5. Can Ada.Numerics.Big_Numbers.Big_Integer be used for all types of calculations?

While Ada.Numerics.Big_Numbers.Big_Integer can handle a wide range of numbers, it is not suitable for all types of calculations. It is designed for use in mathematical operations and not meant for use with string or character data. Additionally, it may not be suitable for real-time applications due to the performance trade-off mentioned earlier.

Similar threads

  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
3
Replies
75
Views
4K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
29
Views
3K
  • Calculus and Beyond Homework Help
Replies
3
Views
1K
  • Calculus and Beyond Homework Help
Replies
15
Views
4K
  • Programming and Computer Science
Replies
5
Views
2K
  • Calculus and Beyond Homework Help
Replies
5
Views
1K
Back
Top