Question on arithmetic calculations

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
bmarkus
Posts: 111
Joined: Tue Oct 21, 2014 5:58 am

Question on arithmetic calculations

Post by bmarkus » Wed Oct 19, 2016 2:31 pm

Just started to play with LoPy and have a problem explained below. It is not LoPy specific but related to MicroPython I guess, it is why asking here.

machine.freq()[0] / 1000 / 1000 returns 80.00003 which is OK

But

machine.freq()[0] / 1000000 returns 8.181962e-07

which doesn't look the right result

machine.freq()[0] / 1000000.0
machine.freq()[0] / 1e6

returns the same. What is wrong?

Regards... Béla
Tiny Core Linux (piCore) developer
HAM radio call: HA5DI (Béla)

User avatar
bmarkus
Posts: 111
Joined: Tue Oct 21, 2014 5:58 am

Re: Question on arithmetic calculations

Post by bmarkus » Wed Oct 19, 2016 2:48 pm

Now I remember, several month ago there was an issue opened at GitHub about a similar issue if I'm right. It looks the same here.
Tiny Core Linux (piCore) developer
HAM radio call: HA5DI (Béla)

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Question on arithmetic calculations

Post by pythoncoder » Thu Oct 20, 2016 1:35 pm

For what it's worth all of those tests on the Pyboard return the correct value (168.0).
Peter Hinch
Index to my micropython libraries.

jgmdavies
Posts: 57
Joined: Tue Aug 09, 2016 2:39 pm

Re: Question on arithmetic calculations

Post by jgmdavies » Thu Oct 20, 2016 7:37 pm

On the WiPy 2.0, machine.freq()[0] / 1000 / 1000 returns 80.00003,
and machine.freq()[0] / 1000000 returns 8.181962e-07 - same problem as reported for the LoPy.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Question on arithmetic calculations

Post by Damien » Fri Oct 21, 2016 9:36 am

Without knowing anything about the config settings in their build (eg what object representation they use) it's really hard to answer questions like this.

jgmdavies
Posts: 57
Joined: Tue Aug 09, 2016 2:39 pm

Re: Question on arithmetic calculations

Post by jgmdavies » Fri Oct 21, 2016 9:45 am

My experiment was using a WiPy 2.0 with build 0.9.0.b2, as updated recently using the 'Pycom Firmware Update' program.

Jim

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Question on arithmetic calculations

Post by Damien » Fri Oct 21, 2016 10:02 am

jgmdavies wrote:My experiment was using a WiPy 2.0 with build 0.9.0.b2, as updated recently using the 'Pycom Firmware Update' program.
Sorry, this doesn't help. What I meant was that, because the code for WiPy/LoPy/SiPy is not open source, only Pycom themselves know how their version of MicroPython is configured, and only they can answer and fix things like this.

User avatar
bmarkus
Posts: 111
Joined: Tue Oct 21, 2014 5:58 am

Re: Question on arithmetic calculations

Post by bmarkus » Fri Oct 21, 2016 10:05 am

Reported the issue at the Pycom forum, Daniel confirmed the bug.
Tiny Core Linux (piCore) developer
HAM radio call: HA5DI (Béla)

Post Reply