File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
src/main/java/nom/bdezonia/zorbage/type/data/rational Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -104,17 +104,21 @@ public void setV(BigInteger n) {
104
104
}
105
105
106
106
public void setV (BigInteger n , BigInteger d ) {
107
- if (d .equals (BigInteger .ZERO ))
107
+ int comparison = d .compareTo (BigInteger .ZERO );
108
+ if (comparison == 0 )
108
109
throw new IllegalArgumentException ("divide by zero" );
109
- if (d . compareTo ( BigInteger . ZERO ) < 0 ) {
110
+ if (comparison < 0 ) {
110
111
n = n .negate ();
111
112
d = d .negate ();
112
113
}
113
- if (n .equals (BigInteger .ZERO ))
114
+ if (n .equals (BigInteger .ZERO )) {
114
115
d = BigInteger .ONE ;
115
- BigInteger gcd = n .gcd (d );
116
- this .n = n .divide (gcd );
117
- this .d = d .divide (gcd );
116
+ }
117
+ else {
118
+ BigInteger gcd = n .gcd (d );
119
+ this .n = n .divide (gcd );
120
+ this .d = d .divide (gcd );
121
+ }
118
122
}
119
123
120
124
@ Override
You can’t perform that action at this time.
0 commit comments