In both the protobuf native PHP library and PHP C-extension, I am seeing a loss of precision with floats:
message TestMessage {
float foo = 1;
}
$initialMessage = new TestMessage();
$initialMessage->setFoo(-8.6107481E7);
echo "Initial message: ";
var_dump($initialMessage->getFoo());
echo "Serialized message: ";
$serializedMessage = new TestMessage();
$serializedMessage->mergeFromString($initialMessage->serializeToString());
var_dump($serializedMessage->getFoo());
When the C-Extension is enabled, the loss of precision happens immediately. When the C-extension is not enabled, the loss of precision happens when the message is serialized and deserialized:
// Without protobuf C-Extension
Initial message: float(-86107481)
Serialized message: float(-86107480)
// With protobuf C-Extension
Initial message: float(-86107480)
Serialized message: float(-86107480)
In both the protobuf native PHP library and PHP C-extension, I am seeing a loss of precision with floats:
When the C-Extension is enabled, the loss of precision happens immediately. When the C-extension is not enabled, the loss of precision happens when the message is serialized and deserialized: