8000 Sync from Piper @401883098 · graup/protobuf-javascript@c8284ae · GitHub
[go: up one dir, main page]

Skip to content

Commit c8284ae

Browse files
committed
Sync from Piper @401883098
PROTOBUF_SYNC_PIPER
2 parents d24ce49 + edc3c9f commit c8284ae

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

binary/utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ jspb.utils.splitFloat32 = function(value) {
202202

203203
exp = Math.floor(Math.log(value) / Math.LN2);
204204
mant = value * Math.pow(2, -exp);
205-
mant = Math.round(mant * jspb.BinaryConstants.TWO_TO_23) & 0x7FFFFF;
205+
mant = Math.round(mant * jspb.BinaryConstants.TWO_TO_23);
206+
if (mant >= 0x1000000) {
207+
++exp;
208+
}
209+
mant = mant & 0x7FFFFF;
206210

207211
jspb.utils.split64High = 0;
208212
jspb.utils.split64Low = ((sign << 31) | ((exp + 127) << 23) | mant) >>> 0;

binary/utils_test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ describe('binaryUtilsTest', function() {
391391
// Pi.
392392
test(f32_pi, 0x40490fdb);
393393

394+
// corner cases
395+
test(0.9999999762949594, 0x3f800000);
396+
test(7.99999999999999, 0x41000000);
397+
test(Math.sin(30 * Math.PI / 180), 0x3f000000); // sin(30 degrees)
398+
394399
// Various positive values.
395400
var cursor = f32_eps * 10;
396401
while (cursor != Infinity) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "google-protobuf",
3-
"version": "3.17.3",
3+
"version": "3.18.1",
44
"description": "Protocol Buffers for JavaScript",
55
"main": "google-protobuf.js",
66
"files": [

0 commit comments

Comments
 (0)
0