Re: [nodejs] why not add read or write 64bit from Node.JS Buffer class?

296 views
Skip to first unread message

Ben Noordhuis

unread,
Jan 16, 2013, 9:47:32 AM1/16/13
to nod...@googlegroups.com
On Wed, Jan 16, 2013 at 11:25 AM, Cheng Shao <dgkan...@gmail.com> wrote:
> I'm trying out nodejs as a TCP server. i want to read unsigned 64bit integer
> from Buffer. find not similar function. why not to be added?

JS numbers are 64 bits doubles. That means you can't represent 64 bit
integers with them because they're only exact for integers up to 2^53.

To illustrate:

$ node
> Math.pow(2, 53) === Math.pow(2, 53) - 1
false
> Math.pow(2, 53) === Math.pow(2, 53)
true
> Math.pow(2, 53) === Math.pow(2, 53) + 1
true

Nathan Rajlich

unread,
Jan 16, 2013, 12:44:14 PM1/16/13
to nod...@googlegroups.com
If you don't mind a compiled solution, my "ref" module adds the (read|write)Int64[BL]E functions to the Buffer object: https://github.com/TooTallNate/ref. You can pass in String representations of the int64 values and they will be dealt with in C-land.


--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply all
Reply to author
Forward
0 new messages