www.heteroclinic.net
Introduction: the Problem 20140528
For most engineering students even of computer science or physics,
the first year college study will involve designing an addition circuit using logical gates on a breadboard.
One point we should recall is that the results will not be a single bit while we try to sum up two single bits as the different operands.
The result would need a bit represent the sum, another bit called carry. In later year, I remember probably (I read the book, not formally take
about 8086 CPU) in an assembly language book, the sum results of two registers will be saved in a register (maybe one of the above), if there is
an overflow, a register or a bit of some register will indicate there is a carry and store the carry. However, this was a post-mortem approach.
You can only regret it, but no-way to reverse it. It is uncertain if most up-to-date software checks the carry (read the above-mentioned register)
and set a proper exception handle etc.
This is rather a motivation than a problem. I took a couple of days figure out a way to avoid the problem at the same time practice some
healthy software development methodology.
|
||
A Fundamental Mathematical Analysis 20140528
I.The mathematical condition for sum overflow:
II.The mathematical condition for multiplication overflow: |
||
A Java Implementation 20140528
System requirement:
Download and unpack the source, for Windows users, you can consider 7zip for the tar.gz file. In a Linux/UNIX shell, or Cygwin etc:
Build the jar binary and generate the coverage report ( target/site/jacoco-ut/index.html):
Use the following command to generate Javadoc ( target/site/apidocs/index.html): |
||
License or Agreement of Usage Terms 20140528
|
20140629
|
||
20140629
|
||
20140629
|
||
20140629
We also found how fatal the least significant digit(s) plays in deciding the prime or composite attribute of a very large number. |