Giter Club home page Giter Club logo

Comments (6)

emilyyyylime avatar emilyyyylime commented on June 2, 2024

Another option not mentioned above is working the same as (3), but returning +0.0 for +0.0 and -0.0 for -0.0.
Essentially, sign(x) = if x > 0.0 { type(x)(1) } else if x < -0.0 { type(x)(-1) } else { x }. I do believe this option has the most applicability in the widest range of use cases, as it aligns with the mathematical definition while keeping the flexibility of (2) — you get to differentiate between 0+ and 0- where that's required and elsewhere just use == 0 for a straightforward 0 check.

from typst.

PgBiel avatar PgBiel commented on June 2, 2024

Another option not mentioned above is working the same as (3), but returning +0.0 for +0.0 and -0.0 for -0.0. Essentially, sign(x) = if x > 0.0 { type(x)(1) } else if x < -0.0 { type(x)(-1) } else { x }. I do believe this option has the most applicability in the widest range of use cases, as it aligns with the mathematical definition while keeping the flexibility of (2) — you get to differentiate between 0+ and 0- where that's required and elsewhere just use == 0 for a straightforward 0 check.

I don't think that's particularly useful, since #(float("+0.0") == float("-0.0")) returns true, so it's easier to just return +0 for both cases.

from typst.

emilyyyylime avatar emilyyyylime commented on June 2, 2024

Since when do we prefer 'easier' approaches? /lh
My point is that for almost all use cases this is indistinguishable from (3), but if someone really needs to differentiate 0+ and 0- they still can.

from typst.

laurmaedje avatar laurmaedje commented on June 2, 2024

As said somewhere else, I'd prefer to have calc removed in favor of methods on int and float, so any potential discussion should take this possibility into account.

from typst.

PgBiel avatar PgBiel commented on June 2, 2024

As said somewhere else, I'd prefer to have calc removed in favor of methods on int and float, so any potential discussion should take this possibility into account.

I think that could definitely be suitable in this case, given that the behavior would differ between integers and floats. We could have int.signum() and float.signum().

from typst.

laurmaedje avatar laurmaedje commented on June 2, 2024

I'd say this favors a design where calc.signum returns a number of the type it was given.

from typst.

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.