Skip to content

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

Description

@DavidRusso
  • 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

Activity

  1. apapirovski commented on Jan 17, 2018

    @apapirovski
    Contributor

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

  2. added
    bufferIssues and PRs related to the buffer subsystem.
    on Jan 17, 2018
  3. mrmacete commented on Jan 18, 2018

    @mrmacete

    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.

  4. mrmacete commented on Jan 19, 2018

    @mrmacete

    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

  5. added a commit that references this issue on Jan 24, 2018
  6. added a commit that references this issue on May 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.confirmed-bugIssues and PRs for confirmed bugs.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions