In JRuby, don't add sqrt, exp, log, power implemented in ruby#417
In JRuby, don't add sqrt, exp, log, power implemented in ruby#417tompng merged 1 commit intoruby:masterfrom
Conversation
Ruby-implemented sqrt, exp, log, power depends on new feature only implemented in bigdecimal.c: `BigDecimal(float_without_prec)` and `BigDecimal#_decimal_shift`
|
@tompng Thanks for looking into this. I believe we could implement https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html#movePointLeft-int- https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html#movePointRight-int- It could be implemented in Ruby right now via the following code: class BigDecimal
def _decimal_shift(i)
java_bigdecimal = to_java
if i < 0
java_bigdecimal.move_point_right(-i).to_d
else
java_bigdecimal.move_point_left(i).to_d
end
end
end
BigDecimal("123.456")._decimal_shift(2) # => 0.123456e1
BigDecimal("123.456")._decimal_shift(-2) # => 0.123456e5
Over time, we want to reduce the amount of custom code we have to maintain in our BigDecimal, but making two completely different implementations line up is not easy. 😭 |
|
Thank you 👍 |
|
@tompng CI on JRuby will be a big job but I agree that needs to happen. I think the JRuby BigDecimal implementation should move out of JRuby's repository (into this repo or a separate jruby/bigdecimal repo) so that we can fix issues more quickly and start reusing all of the .rb code. |
Stub out ruby-implemented methods (
sqrtexplogpower) in JRuby for now.These methods already exist in JRuby.
It depends on new feature only implemented in bigdecimal.c:
BigDecimal(float_without_prec)andBigDecimal#_decimal_shiftThere are some utility functions in
lib/bigdecimal/bigdecimal.rb:BigDecimal::Internal.coerce_to_bigdecimal,BigDecimal::Internal.validate_prec, etc.I want to use them in BigMath in the future. At that time, I think we need to remove this
returnand fix the ruby code.