HardwareJon
Posts: 18
Joined: Sat Nov 22, 2014 7:34 pm

Effective bit length of Python on RasPi

Sun Nov 19, 2017 3:36 am

Hi,

I am using my RasPi to read and transmit (to Google Sheets) data from a Bosch BME280 sensor.

Because of their compensation algorithms (performed in the RasPi) they recommend.....
For best possible calculation accuracy in pressure, 64 bit integer support is needed.
I've read several descriptions of how Python deals with number length (essentially limited by the platform).

My question is: Will Python (3.4) on a RasPi (Jessie lite) provide the calculation accuracy of the recommended 64 bits?

I know any error is probably "in the weeds" however the concept has bothered me for some time.

Thanks

Jon

User avatar
rpdom
Posts: 11860
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Effective bit length of Python on RasPi

Sun Nov 19, 2017 7:19 am

Python 2 will use 32 bit ints, but can handle numbers with much bigger precision.

Python 3 doesn't use the standard types and gives ints unlimited precision.

But basically you don't need to worry about bit length in Python, it will sort itself out for you.

jahboater
Posts: 1946
Joined: Wed Feb 04, 2015 6:38 pm

Re: Effective bit length of Python on RasPi

Sun Nov 19, 2017 8:07 am

Yes.

To convince yourself, try:-

1234 ** 1234

in any version of Python!

They are probably talking about some other language such as C or C++.
And 64-bit integers (int64_t) work fine with these too.

User avatar
jojopi
Posts: 3007
Joined: Tue Oct 11, 2011 8:38 pm

Re: Effective bit length of Python on RasPi

Sun Nov 19, 2017 10:23 am

HardwareJon wrote:
Sun Nov 19, 2017 3:36 am
For best possible calculation accuracy in pressure, 64 bit integer support is needed.
That sentence appears in the introduction for some C code that requires a 64bit type. The code will not just be less accurate if the type is not available, it will be wrong. There is a separate implementation using only 32bit types.

If you converted the C code to Python yourself, the question is whether you did so correctly. If you are using someone else's library, the question is what they did.

Adafruit_Python_BME280 uses the double precision floating point implementation from Appendix A of the datasheet. That is the right decision for the Pi, in any language. The datasheet only recommends integer first because of smaller platforms where floating point is very costly and/or limited to single precision.

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 16 guests