Skip to main content
added 367 characters in body
Source Link

First of all, I'll assume that this is an exercise, as java.math.BigInteger already provides most of the functionality that is specified. It is also backed by specialized native code in most Java VM's.

The class is not designed with performance in mind. Using decimals in a linked list instead of an array of 32-bit integers or 64-bit longs is alsoeasy to debug, but it is far less performant than using e. The only advantage couldg. longs within an array. There are also many mathematical schemes that can be studied to avoid memory copiesspeed up the calculations such as Java BigInteger classesKaratsuba addition & (but then you'd have to perform calculations on the same instancemultiplication, rather than returning a new one Newton-Raphson division etc. BigInteger even mixes approaches depending on integer size as is done now)more involved tricks may have a relatively large initial overhead. UsingIn reality the decimal calculation style is also fully unnecessary, computer use bytes and words of various sizes. Thiscode is doubly true because this just seems to be an implementation detail - the inner calculations arelikely not exposed to the usereven used as most Java VM's will replace it with CPU-specific instructions.

Of course,Instead of implementing a list yourself LinkedList and other methods do already exist as well, and for specialized instructions itcould have been used. It however makes more much more sense to use arrays as they offer faster random access, which may be needed to implement the mathematical schemes mentioned earlier. I'm therefore assuming that creating the linked list yourself was part of an assignment.

The implementation itself seems fine if it is just to show that you can implement high school math using a computer application.

 

First of all, I'll assume that this is an exercise, as java.math.BigInteger already provides most of the functionality that is specified. It is also backed by specialized native code in most Java VM's.

Using a linked list instead of an array of 32-bit integers or 64-bit longs is also far less performant. The only advantage could be to avoid memory copies as Java BigInteger classes (but then you'd have to perform calculations on the same instance, rather than returning a new one as is done now). Using the decimal calculation style is also fully unnecessary, computer use bytes and words of various sizes. This is doubly true because this just seems to be an implementation detail - the inner calculations are not exposed to the user.

Of course, LinkedList and other methods do already exist as well, and for specialized instructions it makes more much more sense to use arrays as they offer faster random access.

First of all, I'll assume that this is an exercise, as java.math.BigInteger already provides most of the functionality that is specified.

The class is not designed with performance in mind. Using decimals in a linked list is easy to debug, but it is far less performant than using e.g. longs within an array. There are also many mathematical schemes that can be studied to speed up the calculations such as Karatsuba addition & multiplication, Newton-Raphson division etc. BigInteger even mixes approaches depending on integer size as more involved tricks may have a relatively large initial overhead. In reality the code is likely not even used as most Java VM's will replace it with CPU-specific instructions.

Instead of implementing a list yourself LinkedList could have been used. It however makes more more sense to use arrays as they offer faster random access, which may be needed to implement the mathematical schemes mentioned earlier. I'm therefore assuming that creating the linked list yourself was part of an assignment.

The implementation itself seems fine if it is just to show that you can implement high school math using a computer application.

 
added Comparable<T> interface as I forgot to mention that.
Source Link

Addition: in Java you'd implement the interface Comparable which provides the method compareTo so that all e.g. SortedList instances can rely on such functionality to be present.

Addition: in Java you'd implement the interface Comparable which provides the method compareTo so that all e.g. SortedList instances can rely on such functionality to be present.

added 103 characters in body
Source Link

It isn't clear which part of the number is the most and least significant digit. Devs will have to figure this out from the code, which is less than ideal. This could also be accomplished by renaming the class and fields of Node to e.g. DigitNode, and the fields to e.g. lowerDigitNode or higherDigitNode. The start of the list would then be e.g. leastSigDigNode or just least with a comment instead of ref_tail_node.

It isn't clear which part of the number is the most and least significant digit. Devs will have to figure this out from the code, which is less than ideal. This could also be accomplished by renaming the class and fields of Node to e.g. DigitNode to e.g. lowerDigitNode or higherDigitNode.

It isn't clear which part of the number is the most and least significant digit. Devs will have to figure this out from the code, which is less than ideal. This could also be accomplished by renaming the class and fields of Node to e.g. DigitNode, and the fields to e.g. lowerDigitNode or higherDigitNode. The start of the list would then be e.g. leastSigDigNode or just least with a comment instead of ref_tail_node.

added 115 characters in body
Source Link
Loading
added 5 characters in body
Source Link
Loading
added 399 characters in body
Source Link
Loading
Source Link
Loading