JoshuaWise / integer

Native 64-bit integers with overflow protection.
MIT License
19 stars 9 forks source link

Problem with -0 #14

Open borisgontar opened 5 years ago

borisgontar commented 5 years ago

The method Integer.fromBits does not accept javascript's minus zero the same way other methods do:

Integer(-0) Integer { high: 0, low: 0 } Integer.fromNumber(-0) Integer { high: 0, low: 0 } Integer.fromString('-0') Integer { high: 0, low: 0 } Integer.fromBits(0, -0) TypeError: Expected second arguement to be a regular 32-bit signed integer

The problem might be caused by the word "arguement" :-)

And thanks a lot for the excellent module 'better-sqlite3'.

JoshuaWise commented 4 years ago

Interesting find.

JavaScript internally stores numbers as either 64-bit floats or 32-bit integers, depending on their value. Since -0 is only representable as a float, it fails the type-check that fromBits performs which only accepts integers. Providing support for -0 would require additional type checks, comparisons, and casting, which frankly don't seem worth it, given how rare this edge-case is.

borisgontar commented 4 years ago

Agreed.

On Mon, Apr 20, 2020, 2:29 PM Joshua Wise, notifications@github.com wrote:

Interesting find.

JavaScript internally stores numbers as either 64-bit floats or 32-bit integers, depending on their value. Since -0 is only representable as a float, it fails the type-check that fromBits performs which only accepts integers. Providing support for -0 would require additional type checks, comparisons, and casting, which frankly don't seem worth it, given how rare this edge-case is.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JoshuaWise/integer/issues/14#issuecomment-616732204, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLQS5XTQIV2DGFS2UHKIYLRNSH7BANCNFSM4G23EE6Q .