Giter VIP home page Giter VIP logo

Comments (7)

Lithl avatar Lithl commented on August 10, 2024

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.

Ardnived avatar Ardnived commented on August 10, 2024

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.

Lithl avatar Lithl commented on August 10, 2024

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.

Ardnived avatar Ardnived commented on August 10, 2024

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.

victor avatar victor commented on August 10, 2024

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.

Ardnived avatar Ardnived commented on August 10, 2024

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.

rileydutton avatar rileydutton commented on August 10, 2024

Support for abs() was added today: https://app.roll20.net/forum/post/827711/#post-827711

from roll20-character-sheets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.