问题
I'm trying to implement an RSA attack in Java and I need to compute math operations like floor and ceil to BigInteger variables. As we know math.ceil and math.floor only apply to double variables, do you know any other way I can compute floor and ceil for BigIntegers? Thank you.
回答1:
The question does not make sense: floor and ceil round a floating number to an integer. And guess what: BigInteger can only represent Integers. So no rounding required. (Esp. the RSA context emphasize the integer character).
回答2:
Since BigInteger values are integers, I assume that you want the the ceiling and floor of division operations. For that, I suggest that you use BigDecimal instead. It has a method divide
that takes another BigDecimal and a MathContext. In the MathContext, you can specify the rounding mode as ceiling or floor (among others).
If all you need is rounding toward zero, you can also use BigDecimal.divideToIntegralValue
.
来源:https://stackoverflow.com/questions/9987155/java-biginteger-floor-and-ceil-functions