Dfp Dfp.multiply(int x) does not comply with the general contract FieldElement.multiply(int n)

Details

Description

In class org.apache.commons.math3.Dfp, the method multiply(int n) is limited to 0 <= n <= 9999. This is not consistent with the general contract of FieldElement.multiply(int n), where there should be no limitation on the values of n.

Thomas Neidhart
added a comment - 23/Sep/12 21:26 Hi,
I looked at this issue, and if I understand it correctly, the current multiply(int) method is using a performance shortcut for values of x between 0 and RADIX.
I did a very simple patch to implement the following logic:
if 0<=x<RADIX: call multiplyFast with x
otherwise create a new Dfp instance with x and call multiply(Dfp) with it

I looked at it as it is one of the few open issues for 3.1. As I am no expert for the Dfp implementation, I did not want to commit it without at least a comment from Sebastien or somebody else who is more proficient in this area than I am.

Thomas Neidhart
added a comment - 20/Oct/12 09:55 I looked at it as it is one of the few open issues for 3.1. As I am no expert for the Dfp implementation, I did not want to commit it without at least a comment from Sebastien or somebody else who is more proficient in this area than I am.

Seems good to me too. Using shift-right operations would result in faster implementations. I remember having tried that at the time I created this issue, but it seems to me I met with an issue, I can't remember what...
So for the time being, let's stick with this patch, and once we get some time, we can look into optimizations.

Sébastien Brisard
added a comment - 21/Oct/12 10:06 Seems good to me too. Using shift-right operations would result in faster implementations. I remember having tried that at the time I created this issue, but it seems to me I met with an issue, I can't remember what...
So for the time being, let's stick with this patch, and once we get some time, we can look into optimizations.