Skip to content

JS: Handling Infinity values for Float fields #49

Open
@serchavalos

Description

@serchavalos

Hello!

I noticed that in encoder.js, the method does not allow writeFloat does not accept Infinity as its value

https://github.com/protocolbuffers/protobuf/blob/d9ccd0c0e6bbda9bf4476088eeb46b02d7dcd327/js/binary/encoder.js#L365-L375

/**
 * Writes a single-precision floating point value to the buffer. Numbers
 * requiring more than 32 bits of precision will be truncated.
 * @param {number} value The value to write.
 */
jspb.BinaryEncoder.prototype.writeFloat = function(value) {
  goog.asserts.assert((value >= -jspb.BinaryConstants.FLOAT32_MAX) &&
                      (value <= jspb.BinaryConstants.FLOAT32_MAX));
  jspb.utils.splitFloat32(value);
  this.writeUint32(jspb.utils.split64Low);
};

And its comment seems misleading because it says Numbers requiring more than 32 bits of precision will be truncated. but in reality, it throws an error.

Shouldn't writeFloat remove this restriction or at least this assert?

Thanks in advance,

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjavascripttriagedIssue has been triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions