Pack/unpack doesn't seem to work properly for doubles #1

Closed
mohawkjohn opened this Issue Oct 31, 2012 · 6 comments

Projects

None yet

2 participants

If I do 1.1.pack(:double), I get "?\x8C\xCC\xCD", which is the value I should get were I doing 1.1.pack(:float).

1.1.pack('E') gives the correct value, which is "\x9A\x99\x99\x99\x99\x99\xF1?".

I've tried with a whole bunch of variations, e.g., 1.1.pack(:precision => :double). Same result.

@marcandre marcandre added a commit that referenced this issue Nov 1, 2012
@marcandre v1.3.4: Fix double packing & unpacking [Issue #1]
Thanks John Woods
936a32f
Owner

Fixed two problems with float packing unpacking. One was with native endian, double precision (was using 'F', now uses 'D') and that packing in single precision made all subsequent packing single precision (even if double precision was requested).

If this hasn't fixed your issue, please let me know!

Thanks

@marcandre marcandre closed this Nov 1, 2012

Hmm. Still seems to not quite be working for me. I have to add :endian => :little to the options, though unpack('D') works fine for me.

@marcandre marcandre reopened this Nov 1, 2012
Owner

Mmmm, here's what I have on my end:

$ irb
1.9.3p194 :001 > require 'packable'
 => true 
1.9.3p194 :002 > 1.1.pack(:double)
 => "?\xF1\x99\x99\x99\x99\x99\x9A" 
1.9.3p194 :003 > Packable::VERSION
 => "1.3.5" 
1.9.3p194 :005 > `ruby -v`
 => "ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin10.8.0]\n" 

What's on your end?

I get the same thing, but 1.1.pack(:double) is not doing :endian => :native, as far as I can tell.

1.1.pack(:double)
  => "?\xF1\x99\x99\x99\x99\x99\x9A"
1.1.pack('E')
  => "\x9A\x99\x99\x99\x99\x99\xF1?"
1.1.pack('D')
  => "\x9A\x99\x99\x99\x99\x99\xF1?"
1.1.pack(:precision => :double, :endian => :native)
  => "\x9A\x99\x99\x99\x99\x99\xF1?"
Owner

Indeed, the default is :endian => :big, not sure why I chose that at the time. I'll close this issue, then, since you can adjust the settings or specify the endianness you want, things work.

Or let me know what you'd like to be done!

@marcandre marcandre closed this Nov 1, 2012

It just seems like it makes more sense to use whatever the native setting is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment