Conversation
|
What is that? |
55c41f8 to
34cc394
Compare
|
Hello, anybody here? |
| } | ||
|
|
||
| function number(encoder, value) { | ||
| var ivalue = value | 0; |
There was a problem hiding this comment.
This should be leaved as is: it has the same semantics, but there are performance consideration to take into account. See https://jsperf.com/math-floor-alternatives
| // uint 16 -- 0xcd | ||
| // uint 32 -- 0xce | ||
| type = (ivalue <= 0xFF) ? 0xcc : (ivalue <= 0xFFFF) ? 0xcd : 0xce; | ||
| type = (value <= 0xFF) ? 0xcc : (value <= 0xFFFF) ? 0xcd : (value <= 0xFFFFFFFF) ? 0xce : 0xcf; |
There was a problem hiding this comment.
I think this, together with line 74 are the most important. All the others should be reversed.
|
I reviewed your code and it seems exactly what I need. @kawanet colud you please consider relasing a new version with this bugfix? |
|
Oh, you are so kind, I can reverse that and keep bug fixed. |
|
Thank you guys for sending the PR and reviewing it! I have loved it("cc-cf: uint 8/16/32/64", function() {
assert.deepEqual(toArray(msgpack.encode(0xFF, options)), [0xcc, 0xFF]);
assert.deepEqual(toArray(msgpack.encode(0xFFFF, options)), [0xcd, 0xFF, 0xFF]);
assert.deepEqual(toArray(msgpack.encode(0x7FFFFFFF, options)), [0xce, 0x7F, 0xFF, 0xFF, 0xFF]);
});The author seems to have decided for 0x80000000 to fallback to float64 encoding instead of uint32 encoding. If it support value over assert.deepEqual(toArray(msgpack.encode(0x80000000, options)), [0xce, 0x80, 0x00, 0x00, 0x00]);
assert.deepEqual(toArray(msgpack.encode(0xFFFFFFFF, options)), [0xce, 0xFF, 0xFF, 0xFF, 0xFF]);I'm not sure that the performance difference still remains between |
|
It's interesting that now function number(encoder, value) {
var ivalue = Math.floor(value);
var type;
if (value !== ivalue || value < -0x80000000 || 0xffffffff < value) {By the way, @racketprogram's code supports Let me check it would not have a rounding error on round trip encoding/decoding as JavaScript's number (double) only has 53bit precision. |
Chrome is too genius as above. |
|
We still can not use a positive integer to be an int type in javascript, because javascript not have type hint. |
Right. ECMA-262 does not have a type hint in the spec. I have loved such hacks of int32 value which may help V8 run fast. |
|
I have a little confusing about the direction of that PR, Could you give me some comments or I can just wait a moment. |
We can not support uint64 and int64 because the limit of javascript.
|
@kawanet Hello ? |
That float verification operation is wrong when the value larger than int32max