Divide and Get Remainder at the same time?

后端 未结 9 1187
不知归路
不知归路 2020-12-15 02:37

Apparently, x86 (and probably a lot of other instruction sets) put both the quotient and the remainder of a divide operation in separate registers.

Now, we can proba

9条回答
  •  渐次进展
    2020-12-15 03:01

    In Java (since 1.5) the class BigDecimal has the operation divideAndRemainder returning an array of 2 elements with the result and de remainder of the division.

    BigDecimal bDecimal = ...
    BigDecimal[] result = bDecimal.divideAndRemainder(new BigDecimal(60));
    

    Javadoc: https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html#divideAndRemainder-java.math.BigDecimal-

提交回复
热议问题