Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use cases & motivation #5

Description

@MaxGraey

I think it's worth writing about motivation and possible use cases.
I think this sentence is very suitable for the case when you need to compare the signs of two numbers in proper way:

const sameSigns = Math.signbit(x) === Math.signbit(y);
const diffSigns = Math.signbit(x) !== Math.signbit(y);

Why Math.sign is not works in this case?

  1. if x == +0 and y == -0 Math.sign(x) === Math.sign(y) will return true. See why this important.
  2. if one of variables x or y is NaN Math.sign(x) === Math.sign(y) will always return false.

When we need compare signs? It's pretty often required in computational geometry:
https://github.com/search?q=SAME_SIGNS&type=Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions