So basically I am writing an android app and I notice that the add function is not working properly. When I tried testing it with
Complex dummy = Complex.ZERO;
dummy.add(Complex.I);
Log.i("DEBUG", "DUMMY = " + dummy);
I get
I/DEBUG: DUMMY = (0.0, 0.0)
from Logcat. I can't seem to find what went wrong with such a simple function call.
This is the description of the function from Apache's website
public Complex add(Complex addend) throws NullArgumentException
Returns a Complex whose value is (this + addend). Uses the definitional formula (a + bi) + (c + di) = (a+c) + (b+d)i
Complex.Zero = (0.0 + 0.0i)
Complex.I = (0.0 + 1.0i)
Why not?
The answer is in your question itself(on the docs),
Returns a Complex whose value is (this + addend)
Here dummy.add(Complex.I);
returns (0.0 + 1.0i) but is not used. So, assign the return value back to dummy
Correct code would be
dummy = dummy.add(Complex.I);
PS: Also, in my 5+ years of coding. I've blindly trusted Apache Commons everyday everytime. Never it failed ;)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.