Devomatik
DevCodeF1Com
Published in
2 min readAug 15, 2023

--

When it comes to the Ada programming language, there are two commonly used numeric types: integer and long_integer. While both of them are used to represent whole numbers, there are some key differences between the two that developers should be aware of.

The Basics

Let’s start with the basics. The integer type in Ada is a signed integer that can hold values between -231 and 231-1. On the other hand, the long_integer type is also a signed integer but with a much larger range, allowing values between -263 and 263-1.

Size Matters

As you can already tell, the main difference between integer and long_integer is their size. While integer is 32 bits long, long_integer is a whopping 64 bits long. So, if you need to work with larger numbers, long_integer is your go-to choice. However, keep in mind that the larger size also means more memory consumption.

Performance Considerations

When it comes to performance, integer has the upper hand. Since it is smaller in size, it requires less memory and can be processed more quickly by the CPU. So, if you are working with smaller numbers and performance is a critical factor, integer is the way to go.

Overflow and Underflow

Another important consideration is how the two types handle overflow and underflow. In Ada, when an integer value exceeds its range, it wraps around to the other end of the range. For example, if you add 1 to the maximum value of integer, it will become the minimum value. On the other hand, long_integer can handle much larger numbers without overflowing or underflowing.

Choosing the Right Type

So, how do you decide which type to use? It all depends on your specific requirements. If you are working with smaller numbers and performance is a concern, integer is a good choice. On the other hand, if you need to work with larger numbers and precision is important, long_integer is the way to go.

Conclusion

Both integer and long_integer are important numeric types in Ada, each with its own strengths and use cases. Understanding the differences between the two can help you make informed decisions when writing Ada code.

References

--

--