0

I have a i.MX6UL EVK board (696 MHz Cortex-A7 core armv7l). I am using same python code for some testing in normal ubuntu linux pc with kernel 4.4.0 and on EVK board which is also running customized linux(built using yocto) with kernel 4.1.15. Following is my python code

df = 0.540 + 2 * 43

This calculation gives 86.54 as result in pc while in EVK board same calculation gives 86.540000000000006. Also in EVK some of the floating point numbers are converted to higher precision for example just typing 16.825 in python interpreter gives 16.824999999999999 as result while on pc no such behaviour is observed. But typing 18.689 in interpreter gives same result 18.689 in both pc and EVK board. What is the reason for such behaviour in EVK and how can I resolve this problem since I don't want such automatic conversion to higher precision. In EVK I am using python version 2.7.9 while in pc I have 2.7.6 version.

prattom
  • 1,625
  • 11
  • 42
  • 67
  • I don't have an answer, but I would start by eliminating your variables. Upgrade your PC to Python 2.7.9 and see if you still get the same results. – alxwrd Jun 08 '17 at 07:53
  • is there any way to avoid such higher precision for example if I print 16.825 I want 16.825 and not 16.824999999999999 – prattom Jun 08 '17 at 07:55
  • While possibly not a duplicate, a good read still: https://stackoverflow.com/questions/588004/is-floating-point-math-broken – Ilja Everilä Jun 08 '17 at 07:56
  • 2
    @prattom That is just how floating point arithmetic works. – Ma0 Jun 08 '17 at 07:57
  • even using round(16.825, 3) gives 16.824999999999999 while round(16.825, 1) gives 16.800000000000001 – prattom Jun 08 '17 at 08:15
  • Possible duplicate of [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Ilja Everilä Jun 08 '17 at 08:55

0 Answers0