GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
ada

Ada Big_Integer package correctly handles negative exponents

The Ada Big_Integer package in GCC now correctly handles negative base values with even exponents for the exponentiation operator and preserves the sign during…

This commit corrects two issues within GCC’s Ada Big_Integer package, preventing incorrect results in certain arithmetic operations. Specifically, the exponentiation operator (**) now accurately accounts for the parity of an exponent when the base is negative, resolving cases like -2 ** even_exponent. Additionally, a previous oversight where the sign of the result was dropped during multiplication has been fixed, ensuring arithmetic correctness in the Big_Integer library.

In Details

This commit addresses a bug in the libgnat/s-genbig.adb file, part of the Ada runtime library's Big_Integer package. The ** operator (exponentiation) was fixed to correctly handle the sign of the result when the base is negative and the exponent is even. This was a classic edge-case error where Big_Exp failed to consider the exponent's parity, leading to an incorrect positive result. A related bug in the "**" routine that caused the sign to be 'dropped on the floor' for certain operations was also rectified, confirming that Big_Integer arithmetic now aligns with expected behavior…

For Context

Computer programs often need to work with very large numbers that don't fit into standard integer types. For this, programming languages provide "big integer" libraries, which handle numbers of arbitrary size. In the Ada programming language, GCC includes a Big_Integer package for such calculations. This commit fixes a couple of subtle errors in how this Big_Integer package performs calculations. One fix ensures that when you raise a negative number to an even power (like -2 squared), the result is always positive, as it should be mathematically. Another correction ensures that the sign of a number (positive or negative) is properly maintained during multiplication operations. These fixes guarantee that complex calculations with very large numbers in Ada programs produce accurate results.

Filed Under: adabugfixarithmetic