You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
py/parse: Add support for math module constants and float folding.
Add a new MICROPY_COMP_FLOAT_CONST feature, enabled by in mpy-cross
and when compiling with MICROPY_CONFIG_ROM_LEVEL_FULL_FEATURES.
The new feature leverages the code of MICROPY_COMP_CONST_FOLDING to
support folding of floating point constants.
If MICROPY_COMP_MODULE_CONST is defined as well, math module constants
are made available at compile time. For example:
_DEG_TO_GRADIANT = const(math.pi/180)
_INVALID_VALUE = const(math.nan)
A few corner cases had to be handled:
- The float const folding code should not fold expressions resulting
into complex results, as the mpy parser for complex immediates
has limitations.
- The constant generation code must distinguish between -0.0 and 0.0,
which are different even if C consider them as ==
To avoid loosing precision when parsing floats from .mpy file,
the repr() string version of floats has been improved to include
an extra digit, only when actually needed. This new version of
float repr() actually appears to better mimic CPython. The new
repr() code is however only enabled when MICROPY_COMP_MODULE_CONST
is set, to avoid increasing code footprint.
This change removes previous limitations on the use of const()
expressions that would result in floating point number, so the
test cases of micropython/const_error have to be updated.
Additional test cases have been added to cover the new repr() code.
Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
0 commit comments