protobuf float precision "defaults" to double precision in python on mac os

Created on 13 Sep 2017  路  4Comments  路  Source: protocolbuffers/protobuf

I have an example that fails on linux boxes while it works on Mac OS X's python and protobuf implementation.

The used protobuf version (both python lib and protoc compiler) is 3.3. The python version doesn't really seem to make any difference (tried 2.7.10, 2.7.12 & 2.7.13 on mac os & linux).

Minimal example i could come up with:

message FloatPrecisionTest {
    float im_a_single_precision_float = 1;
}

py.test

def test_minimal():
    python_float_which_means_c_double = 0.2
    float_precision_test_proto = FloatPrecisionTest(im_a_single_precision_float=python_float_which_means_c_double)
    # this assert should fail, but it doesn't on MacOS X
    assert float_precision_test_proto.im_a_single_precision_float == python_float_which_means_c_double

so the presented test_minimal should fail in my opinion and it does so on linux - not so on Mac OS :/

Whats going on here?

Most helpful comment

All 4 comments

Pure python is using double precision for float. However python cpp implementation calls our c++ code thus float is float precision. This is a known behavior difference that we are currently hard to change.

I guess your linux is using cpp implementation and Mac OS is using pure python?

Hi! Thanks for the answer - yeah ok that makes sense - but why is one using a pure python implementation and the other one uses the cpp implementation.

Can i force it somehow to use the cpp implementation?

This is a known behavior difference that we are currently hard to change.

i guess you don't want to pay for the performance penalty of doing the conversion in python (inside the creating program)?

i'm just wondering what protobuf with the python implementation does when you are sending that message over the wire - i hope the float conversion does happen in this case? :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tang3w picture tang3w  路  39Comments

xfxyjwf picture xfxyjwf  路  35Comments

little-dude picture little-dude  路  88Comments

blowmage picture blowmage  路  26Comments

kolea2 picture kolea2  路  40Comments