It is currently April 28th, 2024, 10:30 am

Formula not returning expected result.

Get help with creating, editing & fixing problems with skins
User avatar
Brian
Developer
Posts: 2688
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Formula not returning expected result.

Post by Brian »

MrJackFrost wrote:I'm sorry but I think that this is also incorrect. You need to find the closest multiple of three that is less than -23 (this goes for when you are modding both a positive or negative number). -21 > -23 so -21 would not be the number to use. The closest multiple of 3 that is less than -23 is -24 because -24 < -23. Then -23 - (-24) = -23 + 24 which = 1.
I am not suggesting that you are incorrect, I am just trying to find an explanation as to "why" this is happening.

Rainmeter is written in C++, and C++ does modulus division this way (which may go against common mathematical practices). There really is no problem here as we are not going to add a bunch of code just to "fix" something that really isn't broken.

-Brian
MrJackFrost
Posts: 18
Joined: May 25th, 2012, 8:41 pm

Re: Formula not returning expected result.

Post by MrJackFrost »

OH, I misread your post, my mistake. I thought you were saying in general modulus division does not work on negative numbers. Okay, so then I have another question, is there a way to make a measure launch a script other then a lua script. For example could I do something along the lines of:

[Measure]
Measure=Script
ScriptFile=pythonscript.py?

Or does this only work for lua scripts? Thanks for all the help you have given.
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Formula not returning expected result.

Post by poiru »

Brian wrote:Rainmeter is written in C++, and C++ does modulus division this way (which may go against common mathematical practices). There really is no problem here as we are not going to add a bunch of code just to "fix" something that really isn't broken.
I'd argue that this is a bug and we should fix it so that the mathematically correct result is returned (especially since it's probably only a few lines of code).
MrJackFrost wrote:Or does this only work for lua scripts?
Yep.
User avatar
Brian
Developer
Posts: 2688
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Formula not returning expected result.

Post by Brian »

The Script measure if specifically for Lua scripts.

If you want to launch another type of script, you can just do like this:
LeftMouseUpAction=["path\to\your\script\pythonscript.py"] (or you might try LeftMouseUpAction=["pythonscript.py"])

This is assuming you are on the latest beta, and your system is set up to run python scripts through the command line. If your system is not set up that way, you can try launching the program that runs the script like this:
LeftMouseUpAction=["path\to\your\pythonscript\python.exe" "pythonscript.py"]

(Since I do not use python, I can not confirm this will work)

-Brian
User avatar
Brian
Developer
Posts: 2688
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Formula not returning expected result.

Post by Brian »

poiru wrote:I'd argue that this is a bug and we should fix it so that the mathematically correct result is returned (especially since it's probably only a few lines of code).
Sounds like we have a volunteer....

-Brian
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Formula not returning expected result.

Post by poiru »

Brian wrote:Sounds like we have a volunteer....
Hah! I'll take a look later :)
MrJackFrost
Posts: 18
Joined: May 25th, 2012, 8:41 pm

Re: Formula not returning expected result.

Post by MrJackFrost »

Haha, thanks for all your responses! Ill just handle all the calculations in Python for the mean time and I'll keep checking back to this thread to see if there are updates :). Again, thanks for your replies!
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Formula not returning expected result.

Post by jsmorley »

MrJackFrost wrote:Haha, thanks for all your responses! Ill just handle all the calculations in Python for the mean time and I'll keep checking back to this thread to see if there are updates :). Again, thanks for your replies!
Just to be clear, only Lua is supported in Rainmeter in a Measure=Script.
MrJackFrost
Posts: 18
Joined: May 25th, 2012, 8:41 pm

Re: Formula not returning expected result.

Post by MrJackFrost »

jsmorley wrote: Just to be clear, only Lua is supported in Rainmeter in a Measure=Script.
Yup, thanks!
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Formula not returning expected result.

Post by MerlinTheRed »

The modulus works differently in some programming languages than it works in its mathematical definition. Sometimes you want the one solution, sometimes you want the other one, depending on your application. You just have to work around if a system only provides one and not the other.

I believe the mathematical definition is designed so you get the same result when adding or subtracting a multiple of the number you are taking the modulo with. For example 23 mod 3 = 2, and (23-14*3) mod 3 = 2. This definition must not care about your number being positive or negative.

I think this is implemented differently in some programming languages because of the way (integer) numbers are represented in a computer. The "incorrect" version you find in C++ and the like is faster and easier to compute on a cpu while still giving a meaningful result. If you need the correct mathematical one you have to convert the result yourself.

EDIT: Sorry if this post contains redundant information. I didn't notice there were two pages.
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!