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
Add primitives for at least commonly used math constants, such as math.pi and math.e. For example, math.pi should be compiled into the float literal 3.141592653589793.
This PR inlines math literals such as `math.pi` and `math.e`. Previously
Using `math.pi` would emit a getattr, unbox, error check, then box op code,
but now it just boxes the value directly.
This PR is an improvement, but there are a few things that could be improved
further:
* `math` is still being imported even if you only imported literal values such
as `pi` (which is now inlined and doesn't need to be imported).
* We are essentially boxing a literal which should be a `CPyLit_Float` value
instead. I looked into this, but AFAICT there is no "float object" primitve,
meaning Mypyc will emit the same amount of code as before (minus the getattr)
which is not ideal. Is there any way to indicate in the IR that a
`CPyLit_Float` value is a boxed float as opposed to an unboxed float
(`double`)?
Also, I added a test to ensure that the math literals are inlined properly and
have the same value, but the test is failing saying that `pi` does not exist
on module `math`. There are no errors when running the same file through mypy,
so I don't know why it is failing. I checked, and the issue still seems to be
present on `master`.
Closesmypyc/mypyc#985
This PR inlines math literals such as `math.pi` and `math.e`. Previously
Using `math.pi` would emit a getattr, unbox, error check, then box op
code (if we need a boxed value), but now it just generates a literal directly
(that is sometimes boxed).
Closesmypyc/mypyc#985
Add primitives for at least commonly used
math
constants, such asmath.pi
andmath.e
. For example,math.pi
should be compiled into the float literal 3.141592653589793.See also #984.
Here's a list of constants we may want to cover:
The text was updated successfully, but these errors were encountered: