Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point value decoded incorrectly by buf.readDoubleBE() #18208

Closed
DavidRusso opened this issue Jan 17, 2018 · 3 comments
Closed

Floating point value decoded incorrectly by buf.readDoubleBE() #18208

DavidRusso opened this issue Jan 17, 2018 · 3 comments
Labels
buffer Issues and PRs related to the buffer subsystem. confirmed-bug Issues with confirmed bugs.

Comments

@DavidRusso
Copy link

  • Version: v9.4.0
  • Platform: Windows 10 Pro x64 Version 1709 (OS Build 16299.192)
  • Subsystem: Buffer

example_js.txt

The attached example produces the output:

246800 encodes to 410e208000000000
410e208000000000 decodes to 246800.03176522627

The expected result is:

246800 encodes to 410e208000000000
410e208000000000 decodes to 246800

@apapirovski
Copy link
Member

/cc @bnoordhuis this is likely related to the recent switch to calculating this in JS.

@apapirovski apapirovski added the buffer Issues and PRs related to the buffer subsystem. label Jan 17, 2018
BridgeAR added a commit to BridgeAR/node that referenced this issue Jan 17, 2018
The offset was formerly coerced to a integer and this reimplements
that.

Fixes nodejs#18208
@BridgeAR BridgeAR added the confirmed-bug Issues with confirmed bugs. label Jan 17, 2018
@mrmacete
Copy link

mrmacete commented Jan 18, 2018

Here's another example:

v9.4.0 (wrong):

> const x = Buffer.alloc(8,0)
undefined
> x.writeDoubleLE(41.0)
8
> x.toString('hex')
'0000000000804440'
> Buffer.from('0000000000804440','hex').readDoubleLE()
0

v8.9.4 (correct):

> const x = Buffer.alloc(8,0)
undefined
> x.writeDoubleLE(41.0)
8
> x.toString('hex')
'0000000000804440'
> Buffer.from('0000000000804440','hex').readDoubleLE()
41

edit: ok this seems to happen just because the offset argument here is undefined and in previous versions it was coerced to 0, so passing in an explicit 0 will do.

@mrmacete
Copy link

also, probably the confusion comes from the fact that the examples in the docs actually pass undefined there (even if offset isn't stated as optional): https://nodejs.org/api/buffer.html#buffer_buf_readdoublele_offset_noassert

MylesBorins pushed a commit that referenced this issue Mar 6, 2018
The offset was formerly coerced to a integer and this reimplements
that.

PR-URL: #18215
Fixes: #18208
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
MylesBorins pushed a commit that referenced this issue Mar 6, 2018
The offset was formerly coerced to a integer and this reimplements
that.

PR-URL: #18215
Fixes: #18208
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
The offset was formerly coerced to a integer and this reimplements
that.

PR-URL: nodejs#18215
Fixes: nodejs#18208
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. confirmed-bug Issues with confirmed bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants