Skip to content

Javascript array sort is broken #14649

Closed
@carver

Description

@carver

System information

Geth version: 1.6.5-stable
OS & Version: Linux

Expected behaviour

When this javascript is run in geth console:

floats = [0.82, 1.22, 0.54];
floats.sort(function (a,b) { console.log('comparing', a, b, a-b); return a-b; });

I expect to see these comparisons, and the sorted array:

comparing 0.82 1.22 -0.4
comparing 1.22 0.54 0.6799999999999999
comparing 0.82 0.54 0.2799999999999999
[0.54, 0.82, 1.22]

(this output is copied from the Chrome console, where it works as expected)

Actual behaviour

Instead, I see this modified array that is unsuccessfully sorted:

comparing 0.82 1.22 -0.4
comparing 0.54 1.22 -0.6799999999999999
[0.82, 0.54, 1.22]

Steps to reproduce the behaviour

geth &
geth attach
> floats = [0.82, 1.22, 0.54];
> floats.sort(function (a,b) { console.log('comparing', a, b, a-b); return a-b; });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions