Skip to content

Commit

Permalink
Document 64-bit integer support in readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrv committed Jul 29, 2016
1 parent e8eb4e6 commit 169f4d8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ User guide
- [Callbacks](#callbacks)
- [Using objects](#using-objects)
- [Type conversion](#type-conversion)
- [64-bit integers](#64-bit-integers)
- [Error handling](#error-handling)
- [Publishing on npm](#publishing-on-npm)
- [Shipping an asm.js fallback](#shipping-an-asmjs-fallback)
Expand Down Expand Up @@ -922,6 +923,7 @@ are automatically converted between equivalent types:
| ---------- | --------------------------------- |
| number | (un)signed char, short, int, long |
| number | float, double |
| number or [bignum](#64-bit-integers) | (un)signed long, long long |
| boolean | bool |
| string | const (unsigned) char * |
| string | std::string |
Expand All @@ -930,6 +932,23 @@ are automatically converted between equivalent types:
| Function | nbind::cbFunction<br>(only as a parameter)<br>See [callbacks](#callbacks) |
| Instance of any prototype<br>(with a fromJS method) | Instance of any class<br>(with a toJS method)<br>See [using objects](#using-objects) |

64-bit integers
---------------

Normally C++ 64-bit integer types are first converted to `double` and then to JavaScript number
which can only hold 53 bits of precision, but it's possible to preserve all bits by using a bignum class.
It should have a constructor taking the following arguments:

- Integer containing 32 bits from the least important half.
- Integer containing 32 bits from the most important half.
- Boolean, true if the number is negative.

It should also have a `fromJS` function which takes a callback,
and calls it with those same arguments to pass the data back to C++ when needed.

An example implementation also capable of printing 64-bit numbers to strings
in bases 2, 4, 10 and 16 is [included](https://raw.githubusercontent.com/charto/nbind/master/src/int64.ts).

Error handling
--------------

Expand Down

0 comments on commit 169f4d8

Please sign in to comment.