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

1486274226
Tetsuo
Forum Champion
What math functions are supported by default. I know + - * / ceil floor. Any others? I'm specifically looking for square roots.
The only math functions supported in dice rolls are: abs(), ceil(), floor(), and round().
Everything else is documented in Dice Reference . There's no square root function for the dice engine.
1486281205
Tetsuo
Forum Champion
Silvyre doesn't have any fancy math-fu to solve for square roots?
Franky H. said: Silvyre doesn't have any fancy math-fu to solve for square roots? Use Brian's instead. :)
1486326233
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.
Perhaps you're running into the 100 Roll Query limit?
1486327547
Tetsuo
Forum Champion
thats certainly possible. Its a very long macro. :| Ok. 
1486328922
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.
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 ]]
1486331449

Edited 1486331460
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.
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. :(
1486331587
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.
What did you enter specifically into the Text Chat?
1486334115

Edited 1486334193
Lithl
Pro
Sheet Author
API Scripter
[[100**0.5]] (plus a couple values other than 100)
1486334449
Tetsuo
Forum Champion
That returns 0 for me. 
1486349602
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I get a square root with that formula.
1486353977
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...
1486354421
Tetsuo
Forum Champion
It's still not working for me. Am I just being dumb?
1486354543

Edited 1486354856
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.
1486355411
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?
<a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Browser_compatibility" rel="nofollow">https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Browser_compatibility</a> 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).
1486356169
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]]
1486356516

Edited 1486357307
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!
1486357435
Tetsuo
Forum Champion
This even works with die rolls.&nbsp; Thats... pretty sweet.&nbsp;