dcodeIO / long.js

A Long class for representing a 64-bit two's-complement integer value.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fails to format base 10 min 64bit signed value.

wibobm opened this issue · comments

let INT64_MIN = "-9223372036854775808";
console.info( "INT64_MIN " +  Long.fromString(INT64_MIN).toString(10));
// incorrectly prints "-9223372036854775801717986912"

let INT64_MIN_BASE2 = "1000000000000000000000000000000000000000000000000000000000000000";
console.info( "INT64_MIN " +  Long.fromString(INT64_MIN_BASE2,false,2).toString(10));
// Also incorrectly prints out same incorrect value "-9223372036854775801717986912"
commented

This is working for me:

> Long.fromString("-9223372036854775808", 10).toString(10)
'-9223372036854775808'

> Long.fromString("-9223372036854775808", true, 10).toString(10)
'9223372036854775808'

> Long.fromString("1000000000000000000000000000000000000000000000000000000000000000", 2).toString(10)
'-9223372036854775808'

> Long.fromString("1000000000000000000000000000000000000000000000000000000000000000", true, 2).toString(10)
'9223372036854775808'

What version are you using?

% node

let Long = require("long-mutable");
Long.fromString("-9223372036854775808", 10).toString(10)
'-9223372036854775801717986912'

Which does not match the value you get. I'm using the latest version published on NPM.
Thanks!

commented

let Long = require("long-mutable");

long-mutable isn't this package and I am not the author of long-mutable. Other than that your example is working fine for me, using long, which is the correct package:

> var Long = require("long");
> Long.fromString("-9223372036854775808", 10).toString(10)
'-9223372036854775808'