Power of number (pow) calculation in rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Power of number (pow) calculation in rules

#1 Post by chromo23 » 01 Dec 2022, 13:04

I was wondering if it is possible to calculate the power of a number in rules.
E.g. 2^x

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Power of number (pow) calculation in rules

#2 Post by TD-er » 01 Dec 2022, 13:13

I was like, OK, quickly show the link in the docs and be done with it...
Like this link: https://espeasy.readthedocs.io/en/lates ... -functions
But on closer inspection, it doesn't mention the pow function.

However it does exist and is exactly what you'd expect :)

Code: Select all

double RulesCalculate_t::apply_operator(char op, double first, double second)
{
  switch (op)
  {
    case '+':
      return first + second;
    case '-':
      return first - second;
    case '*':
      return first * second;
    case '/':
      return first / second;
    case '%':
      return static_cast<int>(round(first)) % static_cast<int>(round(second));
    case '^':
      return pow(first, second);
    default:
      return 0.0;
  }
}
(see case '^')

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Power of number (pow) calculation in rules

#3 Post by chromo23 » 01 Dec 2022, 13:15

I knew i read about this somewhere... and was actually surprised that nothing came up in the documentation.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Power of number (pow) calculation in rules

#4 Post by TD-er » 01 Dec 2022, 13:20

I think these basic functions should be mentioned in that "Basic Math Functions" section too.


TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Power of number (pow) calculation in rules

#6 Post by TD-er » 01 Dec 2022, 13:30

Looking forward to the pull request then :)

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Power of number (pow) calculation in rules

#7 Post by chromo23 » 01 Dec 2022, 13:41

of course... i am especially good at that...🤥

I have never really dared to do it, because I find the editing a bit hard to get used to. Do you use an extra editor for that or do you edit it directly in the code editor?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Power of number (pow) calculation in rules

#8 Post by TD-er » 01 Dec 2022, 13:45

I just edit it in VS code.
Just open the CLI in VS code, so you're in the same Python virtual env as used to run PlatformIO.

Then go to docs folder and run ./make.bat html (or the make html variant when not on Windows)
If you're missing Python packages, run (from the docs folder)

Code: Select all

pip3 install -r requirements.txt

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Power of number (pow) calculation in rules

#9 Post by chromo23 » 01 Dec 2022, 15:15

I knew that this wouldn´t be as easy as it looked..
after reading a lot, adding paths and packages, reading a bit more, installing sphinx manually i finally got something when typing "make html"....
...error messages
:?

so...a few times installing, reading, reinstalling later i finally got to the point where it "makes" something...
:)

so it only took me almost 2 hours to actually start with the content.... :D

...but now i´ll make myself a coffee and relax...

...maybe I will also treat myself to a cookie...

...or two...


ps: i guess i can ignore these error messages?

Code: Select all

reading sources... [100%] index                                                                                                                                         
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index                                                                                                                                          
source/Plugin/AdaGFX_commands.repl:45: WARNING: undefined label: p123_page
source/Plugin/AdaGFX_values.repl:6: WARNING: undefined label: p096_page
source/Plugin/AdaGFX_commands.repl:45: WARNING: undefined label: p123_page
source/Plugin/AdaGFX_commands.repl:45: WARNING: undefined label: p123_page
source/Plugin/AdaGFX_commands.repl:45: WARNING: undefined label: p123_page
source/Plugin/AdaGFX_values.repl:6: WARNING: undefined label: p096_page
source/Plugin/AdaGFX_commands.repl:45: WARNING: undefined label: p123_page
generating indices... genindex done
writing additional pages... search done
copying images... [100%] Tools/images/SettingsArchive_provisioning.png                                                                                                  
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 7 warnings.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Power of number (pow) calculation in rules

#10 Post by Ath » 01 Dec 2022, 15:22

Most of those warnings will be fixed once P123 is merged into mega, but that's not yet completed. Can be ignored for now.
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests