Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Rounding integers with custom decimals throws NotImplementedError #613

Open
William04A opened this issue Mar 9, 2023 · 3 comments
Open

Comments

@William04A
Copy link

Hi! I've noticed a bug related to the rounding function.

Heads up: I'm quite confident that this is the same bug as described here: adafruit/circuitpython#1890.

Board/system information:

(sysname='GPy', nodename='GPy', release='1.20.2.r6', version='v1.11-c5a0a97 on 2021-10-28', machine='GPy with ESP32', pybytes='1.7.1')

Bug report

Rounding integer values with a custom number of decimals seems to throw a NotImplementedError:

>>> round(1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NotImplementedError:

If the values is converted to float, it works fine:

>>> round(float(1), 2)
1.0
@robert-hh
Copy link
Contributor

Micropython is not CPython, just a small subset. Thus there are many properties which are not implemented. And you seem to have found one.
I would not call it a bug. It's by intention not available.

@William04A
Copy link
Author

William04A commented Mar 9, 2023

@robert-hh Fair point. Adafruit's CircuitPython has a bug report about this which I linked in the OP which hints that the function is implemented in Micropython, it is just a flag that you enable. It does add some extra code size according to them, but ~100 bytes. Since it is implemented in Micropython, Adafruit considers it a bug and not having the feature presumes that everything you pass to round() with the n argument is a float makes me personally consider this something that should be present in the source code. However, I'm not a MicroPython source code expert of any kind and I know you're much more skilled in that department from our conversations on the PyCom forum :)

@robert-hh
Copy link
Contributor

Yes, the flag is called MICROPY_PY_BUILTINS_ROUND_INT, and it is disabled in py/mpconfig.h. If you need it, you have to build the firmware yourself. In MicroPython mainline, it is usually disabled for ports with small flash, and enabled for ports with larger flash. About Pycom: I do not know if there is activity, now that Pycom Inc got bancrupt and some of their business is continued by Pycom BV. Even if the stopped most of their actual products, they will most likely keep MicroPython for their new products. But even then: I could never tell if raising issues in their public repository was noticed. I hardly ever got feedback from Pycom when I did.
P.S.: round(int,int) is kind of a no-op. since it just returns the first int argument.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants