Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Question on arithmetic

    Scheduled Pinned Locked Moved LoPy
    10 Posts 4 Posters 2.3k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • bmarkusB Offline
      bmarkus
      last edited by bmarkus

      machine.freq()[0] returns 80000.03 which is OK.
      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?

      1 Reply Last reply Reply Quote 0
      • L Offline
        LoneTech
        last edited by

        Confirming this error. It happens for 5e5=500000 and up. Multiplication doesn't trigger it (freq*1e-6 is OK) and integer floor division is OK (freq//1000000). Looks like a floating point division bug in MicroPython.

        1 Reply Last reply Reply Quote 0
        • D Offline
          daniel
          last edited by daniel

          Thanks for the report.
          It's indeed a bug inside MicroPython. Doing the same calculations in pure C returns the correct value: 80.000000, so it's definitely in the way MicroPython handles floating point numbers. We'll add this one to the list...

          1 Reply Last reply Reply Quote 0
          • bmarkusB Offline
            bmarkus
            last edited by bmarkus

            @daniel

            Can you provide an ETA for fix? A buggy arithmetic in core is really a problem. According to reports it works correctly on original MicroPython boards.

            This issue was already discussed several month ago at the upstream MicroPython GitHub issue tracker and fixed there as far as I remember.

            1 Reply Last reply Reply Quote 0
            • D Offline
              daniel
              last edited by

              It's planned for the release of next week Friday. I agree that it's a big issue.

              1 Reply Last reply Reply Quote 0
              • R Offline
                rockybulwinkle
                last edited by

                I also just found what might be the same bug. I triggered it by doing 100000000.0/1, which it said returns 0.0. I'm running 0.9.2.b2.

                1 Reply Last reply Reply Quote 0
                • bmarkusB Offline
                  bmarkus
                  last edited by

                  After three and half weeks still waiting for a fix of this floating point bug. It has nothing to do with LoRa, WiFi, Bluetooth it is a core MicroPython issue. For me it is a main blocking factor, as I can't trust the MicroPython implementation at all if there are such bugs.

                  1 Reply Last reply Reply Quote 0
                  • R Offline
                    rockybulwinkle
                    last edited by rockybulwinkle

                    The bug doesn't appear on my pyboard, so it has something to do with how they're handling floats on this port.

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      daniel
                      last edited by

                      Hello,

                      Sorry for the delay. The problem is caused by a compiler bug that Espressif has identified and a fix is on the way. Please see details here:

                      https://github.com/espressif/esp-idf/issues/96

                      Cheers,
                      Daniel

                      bmarkusB 1 Reply Last reply Reply Quote 0
                      • bmarkusB Offline
                        bmarkus @daniel
                        last edited by

                        @daniel said in Question on arithmetic:

                        Hello,

                        Sorry for the delay. The problem is caused by a compiler bug that Espressif has identified and a fix is on the way. Please see details here:

                        https://github.com/espressif/esp-idf/issues/96

                        Cheers,
                        Daniel

                        Hi Daniel

                        thanks for the info. Looking forward the fixed firmware, hope they will fix it shortly.

                        Regards... Béla

                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • 1 / 1
                        • First post
                          Last post

                        Pycom on Twitter

                        Pycom