Comments (7)
floor
becomes round
if you add 0.5
to the value. For example: floor((-24 / 20) + 0.5) = floor(-1.2 + 0.5) = floor(-0.7) = 1
. The same thing happens with ceil
if you subtract 0.5
.
I also seem to recall Riley including a round
function on the dev server, but I can't find his post about that, so I'm not sure.
from roll20-character-sheets.
I thought about that, but it doesn't always work.
floor((30 / 20) + 0.5) = floor(1.5 + 0.5) = 2
fix((30 / 20)) = fix(1.5) = 1
To be clear, I'm looking for a function that always rounds towards 0. Not a function that rounds naturally.
ie. 1.9 should become 1, 1.5 should become 1, -2.1 should become -2.
from roll20-character-sheets.
Ah, yeah; if you want "towards 0," that wouldn't work. Adding half and flooring the number is round, not towards 0.
An option other than fix
(which I've honestly never heard of being a standard implementation) would be sign
. sign(x) = 1
if x >= 0
and sign(x) = -1
if x < 0
. Thus, x * sign(x) = abs(x)
, and func(x * sign(x)) * sign(x)
maintains the sign of x
for the final result.
from roll20-character-sheets.
Yeah, what you pointed out with sign() is essentially what I was suggesting could be done using abs().
func(x * sign(x)) * sign(x) vs func(abs(x)) * x/abs(x)
sign(x)
and x/abs(x)
would have the same result.
Unfortunately I don't think Roll20 offers the sign() function either.
I've also never heard of fix being regularly available, I just googled to see what such a function is usually called, and "fix" is what came up.
from roll20-character-sheets.
Math.sign(x)
is only in the candidate stages of the specification, and thus it is not available although some browsers do implement it. But as you know, it can easily be substituted for equivalent expressions.
I think the fix
function name comes from MATLAB.
Anyway, FWIW, I'd also like this this functionality to be available, to be able to calculate degrees of success in Deathwatch rolls
from roll20-character-sheets.
Another solution would be to add a tertiary operator (ie. x == 0 ? y : z
which translates to if x is 0 then y else z
). Then we could do x > 0 ? floor(x) : ceil(y)
Which would probably be somewhat more complicated to implement, though also more powerful for those developing character sheets.
from roll20-character-sheets.
Support for abs() was added today: https://app.roll20.net/forum/post/827711/#post-827711
from roll20-character-sheets.
Related Issues (20)
- 100DOS Mythic - incorrect Line Endings on #11941 HOT 1
- Crowdin translations HOT 1
- [Ars Magica 5th] Sheet broken after release on Roll20 HOT 6
- [Ars Magica 5e] Virtue and Flaw categories not saving HOT 5
- Mongoose Traveler: 2E Sheet & Dark Mode HOT 7
- [PortesMonstresTresors] Background image replaced by a huge icon HOT 2
- [Official_100DOS_Mythic_by_100DOS] Bad line feeds breaking my fork HOT 1
- [Cyberpunk 2020] [Transaltion] Fix some misstranslations in french on the character sheet
- [InNomine] Can we get an english version please? HOT 1
- [Earthdawn (FASA Official) V3.14] css incorrect line endings
- Character Sheet Code In Roll20 Different From That Submitted To GitHub (Mongoose Traveller 2E)
- [DCC] Saves, Weapon Attacks, and other buttons missing modifiers HOT 8
- Incorrect Line Endings - Earthdawn (FASA Official)/Earthdawn.css HOT 1
- #12149 merged but Prod code not updated yet. HOT 1
- [Das Schwarze Auge (TDE) 5 OFFICIAL by Ulisses] The french translation has been completely overwritten by the english translation HOT 3
- [GURPS] Death Checks using Unconscious Check modifier?
- [GURPS] 2.9.20 rollback and Roll20 issue with newly added field
- [Mongoose Traveller] Computers skill show/hide broken, Deception formula wrong HOT 1
- German Translation HOT 1
- Portuguese translation Mage V20 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from roll20-character-sheets.