You are using the new UI (Beta).Return to the original UI

This page has been automatically translated by machine translation. Please note that translations may not be entirely accurate.

keisanHigh-precision calculations for everyday life and work

Implementation of addition with carry-over beyond the significant digits

Author: ameyaExecutions: 135

※ This library was created by a member. This site is not responsible for its content.

Manage Bookmarks
This is a programming-related topic.
When the result of an addition operation exceeds the number of significant digits, it is displayed in exponential notation, and the least significant digit is rounded off.
However, by performing a special operation during the addition, we can avoid rounding and achieve a carry.
I’ve set this to 10 digits, but you can apply the same approach even with 50 digits.
A
Positive integers up to 10 digits
B
Positive integers up to 10 digits
a = A;
b = B;
h = 5E+9;
k = 1E+10;
c = (a - h) + (b - h);
if (c <= 0) {
  println(0, c + k);
} else {
  println(1, c);
}

No customer feedback for this calculation yet.