-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRComplexNumber.java
More file actions
48 lines (42 loc) · 1.19 KB
/
Copy pathRComplexNumber.java
File metadata and controls
48 lines (42 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.rosuda.JRI;
/** class that represents a complex number. A complex number is a remainder and
* multiplier. In R, it is represented as remainder + multiplier i.
*/
public class RComplexNumber
{
private double multiplier;
private double remainder;
/** default constructor.
* @param multiplier the multiplier of the number (the multiplier * i).
* @param remainder the remainder of the number (remainder + xi).
*/
public RComplexNumber(double multiplier, double remainder)
{
this.multiplier = multiplier;
this.remainder = remainder;
}
/** get the number's multiplier. */
public double getMultiplier()
{
return multiplier;
}
/** get the number's remainder. */
public double getReminder()
{
return remainder;
}
/** get the string representation of the complex number. You cannot adjust
* the precision via this method. Use a DecimalFormatter or String.format
* if you would like more control of the number's format.
* @return a string with the following format: r+mi
*/
public String toString()
{
String tail = "";
if(multiplier > 0)
tail = "+" + multiplier + "i";
else if(multiplier < 0)
tail = multiplier + "i";
return remainder + tail;
}
}