Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templating: negative numbers to the power of a variable are calculated incorrectly. #97387

Closed
Troon opened this issue Jul 28, 2023 · 2 comments
Closed
Labels

Comments

@Troon
Copy link
Contributor

Troon commented Jul 28, 2023

The problem

Writing IEEE 754 macro, reference equation uses -1**(sign_bit). I kept getting incorrect results. On investigation, I found:

{% set z = 0 %}
{{ -1**0 }}  # returns 1, correctly
{{ -1**z }}  # returns -1, incorrectly

Further checks show this appears to affect all negative numbers:

{% set z = 4 %}
{{ (-2)**4 }}  # 16
{{ (-2)**z }}  # -16

Worked around my original problem with [1,-1][sign_bit].

What version of Home Assistant Core has the issue?

2023.7.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Template

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@krepysh
Copy link

krepysh commented Jul 28, 2023

Also this issue has an opened PR which fixes order. pallets/jinja#1723

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@issue-triage-workflows issue-triage-workflows bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants