Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Math Functions

February 05 (8 years ago)
Tetsuo
Forum Champion
What math functions are supported by default. I know + - * / ceil floor. Any others? I'm specifically looking for square roots.
February 05 (8 years ago)
The only math functions supported in dice rolls are: abs(), ceil(), floor(), and round().
February 05 (8 years ago)
Everything else is documented in Dice Reference. There's no square root function for the dice engine.
February 05 (8 years ago)
Tetsuo
Forum Champion
Silvyre doesn't have any fancy math-fu to solve for square roots?
February 05 (8 years ago)

Franky H. said:

Silvyre doesn't have any fancy math-fu to solve for square roots?

Use Brian's instead. :)
February 05 (8 years ago)
Tetsuo
Forum Champion
Alright. Next question. I know you can only nest macros 99 layers deep. does that limit apply to inline rolls in general?

I have a macro that solves square roots based on Brians post. If I feed it the number 200, it solves correctly. If I replace 200 with 

[[ [[?{Vertical} * ?{Vertical}]] + [[?{Horizontal} * ?{Horizontal}]] ]]

It doesn't return anything. No error, no result, no anything.
February 05 (8 years ago)
Perhaps you're running into the 100 Roll Query limit?
February 05 (8 years ago)
Tetsuo
Forum Champion
thats certainly possible. Its a very long macro. :| Ok. 
February 05 (8 years ago)
Tetsuo
Forum Champion
Alright. I did it. I removed a step, and combined the two queries into one. This changed 200+ queries into ~60. Slightly less accurate, but it works. For anyone interested, this is primarily used to find distance in 3d combat. (IE: Fly spell in pathfinder.)

[[([[([[([[([[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]]]])/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[([[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]]]])/2]]]])/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[([[([[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]]]])/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[([[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]] + [[[[?{Type height * height + distance * distance}]] / [[([[[[?{Type height * height + distance * distance}]]/2]] + [[[[?{Type height * height + distance * distance}]] / [[[[?{Type height * height + distance * distance}]]/2]]]])/2]]]])/2]]]])/2]]]])/2]]]])/2]]

Just type in the numbers you want to solve, and hit enter. It will ask for height * height + distance * distance. So, if someone is 10ft over, and flying 30ft up, you would enter 10*10+30*30.
February 05 (8 years ago)
Cool!

For Pathfinder, I'd personally be okay with using an approximation like this via [[ abs(?{x|10} - ?{y|30}) + {?{x}, ?{y}}kl1 * 1.5 ]]
February 05 (8 years ago)

Edited February 05 (8 years ago)
Lithl
Pro
Sheet Author
API Scripter

Silvyre said:

Franky H. said:

Silvyre doesn't have any fancy math-fu to solve for square roots?

Use Brian's instead. :)
Actually, it turns out you can use ** as the exponent operator. So square root can be done accurately as x**0.5.
February 05 (8 years ago)

Brian said:

Silvyre said:

Franky H. said:

Silvyre doesn't have any fancy math-fu to solve for square roots?

Use Brian's instead. :)
Actually, it turns out you can use ** as the exponent operator. So square root can be done accurately as x**0.5.

While this works awesomely for Character Sheets, it unfortunately does not work at all with the dice engine. :(
February 05 (8 years ago)
Lithl
Pro
Sheet Author
API Scripter

Silvyre said:

Brian said:

Silvyre said:

Franky H. said:

Silvyre doesn't have any fancy math-fu to solve for square roots?

Use Brian's instead. :)
Actually, it turns out you can use ** as the exponent operator. So square root can be done accurately as x**0.5.

While this works awesomely for Character Sheets, it unfortunately does not work at all with the dice engine. :(
Yes it does, I just tried it.
February 05 (8 years ago)
What did you enter specifically into the Text Chat?
February 05 (8 years ago)

Edited February 05 (8 years ago)
Lithl
Pro
Sheet Author
API Scripter
[[100**0.5]] (plus a couple values other than 100)
February 05 (8 years ago)
Tetsuo
Forum Champion
That returns 0 for me. 
February 06 (8 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I get a square root with that formula.
February 06 (8 years ago)
Andrew C
Marketplace Creator
[[9**0.5]]=3
[[16**0.5]]=4
[[15**0.5]]=3.872983346207417

So there we go. Exponents included. So just use decimal approximations or bracketed division to get other roots.

Cube root = **(1/3)
Fourth Root = **(1/4)
And so on...
February 06 (8 years ago)
Tetsuo
Forum Champion
It's still not working for me. Am I just being dumb?
February 06 (8 years ago)

Edited February 06 (8 years ago)
I'm in Franky's boat. Perhaps it's only functioning on certain shards? :S

It seems ** functions as an exponent operator in Chrome but not Firefox... Very strange.
February 06 (8 years ago)
Tetsuo
Forum Champion
Alright. Confirmed this is working on desktop chrome. Just not on IOS or Firefox. Weird. Mayhaps Silvyre could poke a Dev about it?
February 06 (8 years ago)
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Browser_compatibility

It seems that the current version of Firefox does not support ** as an exponent operator until the next version (while Chrome has since a few versions ago).
February 06 (8 years ago)
Tetsuo
Forum Champion
I wasn't aware browser features changed what could or couldn't be done in roll20s dice engine. That makes my macro obsolete. Now it's simply:

[[[[?{height}*?{height} + ?{distance}*?{distance}]]**0.5]]
February 06 (8 years ago)

Edited February 06 (8 years ago)
I believe all math within a roll is resolved client-side (by the user's browser) right after the QuantumRoll dice engine returns the values of any dice expressions and adds the QuantumRoll symbol to the roll. (Which is why 'pure math rolls' (e.g. /r 1+1 or [[1+1]]) do not get marked by the QuantumRoll symbol.)

I suppose I underestimated how long ** has been a browser standard!
February 06 (8 years ago)
Tetsuo
Forum Champion
This even works with die rolls. 

Thats... pretty sweet.