Arithmetic/Rational/Java: Difference between revisions
Content added Content deleted
(Looks for common denominator when adding/subtracting) |
No edit summary |
||
Line 1: | Line 1: | ||
Modeled after BigInteger/BigDecimal. Instances of this class are immutable, and simplified upon construction. The returned numerator() and denominator() are never negative; the sign can be retrieved via signum(). The denominator for zero is always 1 (e.g. 0/5 is simplified to 0/1), and signed zeros are not supported (e.g. 0/-1 is simplified to 0/1). |
Modeled after BigInteger/BigDecimal. Instances of this class are immutable, and simplified upon construction. The returned numerator() and denominator() are never negative; the sign can be retrieved via signum(). The denominator for zero is always 1 (e.g. 0/5 is simplified to 0/1), and signed zeros are not supported (e.g. 0/-1 is simplified to 0/1). |
||
< |
<syntaxhighlight lang=java>import java.math.BigDecimal; |
||
import java.math.BigInteger; |
import java.math.BigInteger; |
||
import java.math.RoundingMode; |
import java.math.RoundingMode; |
||
Line 480: | Line 480: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |