Closed correalucas closed 10 years ago
Hi, sorry for late response. I can't reproduce your issue. There is some version difference, bigdecimal gem is 1.2.3 and jvm is OpenJDK 64-Bit 1.6.0_24. What do you see in BigDecimal description ? (omitted after #, for example I see #<BigDecimal:7f2002545550,'0.9999E2',18(18)> . the value part is 0.999E2 ?
Hi arton, Sorry about BigDecimal description, now i guess it showing... Well, i try to reproduce with your versions...
Thank you for response.
Hi,
I tried to reproduce with your versions and i got the same result.
The problem is that after i load the Rjb, every bigdecimal number when i convert to float returns zero.
Before i load the Rjb, the bigdecimal number '99.99' converted to float returns '99.99'.
After i load the Rjb , the bigdecimal number '99.99' converted to float returns '0.0'
Now i ask if that code is correct:
Rjb::load '.', ['-Xmx1024m']
It seems wrong...
Thanks again.
Hi It seems no problem. The first argument '.' means adding current directory to CLASSPATH and the second argument is valid JVM option for max heap is 1024m. Do you separate the issue from behavior of to_f or else. 'to_f' means only BigDecimal#to_f is affected or else. for example) 3.to_f produce 3.0 or 0 ? ... (means Object#to_f is affected or else) n.to_s produce '99.99' ? ... (means BidDecimal instance itself is affected or else)
Ohhh! My favorite bug:)
JDK 1.7.0.45 linux ruby 2.0.0, but i have the same problem with 1.9.3
require "rjb" require "bigdecimal"
class Testing puts BigDecimal.new("1.5").to_f.to_s Rjb::load( '', [] ) puts BigDecimal.new("1.5").to_f.to_s puts 3.to_f puts BigDecimal.new("1.5").to_s.to_f end
1.5 0.0 3.0 1.5
Hi,
Same problem on Mac. OS X 10.9.1 (Mavericks) Java 1.7.0_45-b18 Tested with ruby 2.0.0p247, 2.0.0-p353 and 2.1.0.
Same results as reported by AlexKovynev.
It's very curious because I also can't reproduce the issue. I wonder if you set $DBG=true; $VERBOSE=true then reproduce the lines you showed . Do you use autoload for some external libraries ?
Hi Arton.
I've just changed the java version from 1.7.0_45-b18 to 1.6.0_65-b14-462-11M4609 and it works fine. Have you tried running the sample code from AlexKovynev on Java 7?
Yes the sample runs fine with my Debian box both with OpenJDK 7u21-2.3.9-5 build( 23.7-b01) and OpenJDK 6b24-1.11.5-1 (build 20.0-b12), also run fine with Oracle's JDK -5, 6, 7 for x86 windows. Now I doubt your building environment, for example your jni.h is for x86 not for x64 or has bad configuration between x86 and x64.
Perhaps all of these configurations is just up and running, not running is on Linux Oracle JDK 7
Is there an opportunity to try?
What do you mean ? Whay don't you try OpenJDK ?
BTW I wonder if you try to set BigDecimal.mode before Rjb::import. ex)
require 'bigdecimal' BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, true) BigDecimal.mode(BigDecimal::EXCEPTION_UNDERFLOW, true) require 'rjb' ...(same as usual)
Regards
Hi all I've just tried on my OSX maverick and Oracle JVM and it runs fine. irb(main):001:0> require 'bigdecimal' => true irb(main):002:0> a = BigDecimal.new('99.99') => #<BigDecimal:7ffe8c03bc80,'0.9999E2',18(18)> irb(main):003:0> a.to_f => 99.99 irb(main):004:0> require 'rjb' => true irb(main):005:0> a.to_f => 99.99 irb(main):006:0> Rjb::load => nil irb(main):007:0> a.to_f => 99.99 irb(main):008:0> System = Rjb::import('java.lang.System') => #<Rjb::Java_lang_System:0x007ffe8c254800 @user_initialize=nil> irb(main):009:0> System.property('java.version') => "1.7.0_51" irb(main):010:0> System.property('java.vendor') => "Oracle Corporation" irb(main):011:0> RUBY_VERSION => "2.1.0" irb(main):012:0> Rjb::VERSION => "1.4.8"
So I believe it's your setting. For example current Ruby bundles BigDecimal (not gem). Do you use bundled BigDecimal correctly ? Or do you use pure - natural Ruby installed /usr/local. Or using rbenv or other switching system let ruby - rjb - big decimal version confiliction ? Because of both BigDecimal and Rjb are extended libraries means compiled and linked at install time. So they easily lead binary version mismatching.
I may close this useless issue after few days. Best regards
Hi arton.
I'm using rbenv and bundle with the --path=.bundle. What we did here to solve the problem was to specify "gem 'bigdecimal', '~> 1.2.5'" directly in the Gemfile and then "bundle install". That forced the bigdecimal gem to be installed in the .bundle folder. Now it works fine with Java 7!
Thanks a lot for your help.
Cheers! Marlus
I am use an rvm, ruby compiled from source, strange, will try separate gem as msaraiva suggested after weekend.
Hi masaravia Thanks for your trying fixing version. I'm glad to run fine on your environment.
Hi Alex Please report the result if it runs fine or not.
Regards
Hi arton, i am happy!:) Issue can be closed!
Hi Alex It's great ! I close this issue.
Thank you so much for the hint regarding including BigDecimal in the Gemfile. I've been fighting with this issue for the last two days. Everything works fine on the development machines, but not on the production system. It even set all numbers in my app to 0 until I would restart the application server.
+1, it solves the issue
Thank you for your report !
I'm glad I could help. Thanks for the great project, arton.
Cheers! Marlus
2014-09-05 17:58 GMT-03:00 arton notifications@github.com:
Thank you for your report !
— Reply to this email directly or view it on GitHub https://github.com/arton/rjb/issues/28#issuecomment-54680606.
Hi there guys.
I'm having this issue on a single server in a cluster of 3. Do you guys think it's OK to include a gem that handles what the stdlib already provides?
I'm taking a look at configs like locale/etc on all servers, because it's working correctly on 2 of the 3. I'll let you guys know if I discover something.
Oh, I'm using MRI 2.1.6 and rjb 1.4.8.
Hi gregoriokusowski Did you install extra gem on cluster #3? I wonder if you could check .gemspec and rbenv (or somthing of env controller) settings.
@arton,
nope, they all have the same gems, and we don't have bigdecimal
in our Gemfile.
We're using rvm.
Solved:
The third machine was displaying this warning perl: warning: Setting locale failed.
.
After fixing that, I've reinstalled the Ruby 2.1.6 and the Rjb gem, but the problem persisted (yesterday).
Today, in order to make a few more tests to isolate the test, I've logged into the machine and the problem isn't happening anymore. (My plan was to compare env dumps between those machines)
I think that all I needed to do is to open a new session on that server in order to make it work.
Our unicorn is up and running, and now displaying more than zeros for our users ;)
TL;DR: If you are facing this problem, check your locale settings, and spin up a new session after each change to validate.
Thank you guys.
Hi Gregório Thank you for your report for solving! It's great help for us.
Hi, When i try to convert BigDecimal into float number, i get zero in result Below, the versions of my enviroment and the test:
ruby --version => ruby 1.9.3p484 (2013-11-22 revision 43786) [i686-linux]
java -version => java version "1.7.0_45" - Java(TM) SE Runtime Environment (build 1.7.0_45-b18) - Java HotSpot(TM) Client VM (build 24.45-b08, mixed mode)
Gems => rjb (1.4.8), bigdecimal (1.1.0)
irb => 1.9.3-p484 :001 > require 'bigdecimal' => true 1.9.3-p484 :002 > require 'rjb' => true 1.9.3-p484 :003 > n = BigDecimal.new('99.99') => #< BigDecimal:8b9a304,'0.9999E2',18(18) > 1.9.3-p484 :004 > n.to_f => 99.99 1.9.3-p484 :005 > Rjb::load '.', ['-Xmx1024m'] => nil 1.9.3-p484 :006 > n = BigDecimal.new('99.99') => #< BigDecimal:8a26c5c,'0.9999E2',18(18) > 1.9.3-p484 :007 > n.to_f => 0.0
I await return, Thanks.