Skip to content

"Sign" option in (math operator of value) block #1912

@towerofnix

Description

@towerofnix

Feature request - There should be a "sign" option in the (math operator of value) block. This would return 1, 0, or -1 depending on whether the given value is positive, zero, or negative. There is a fairly straightforward workaround - "(value) / (abs of (value))" (*) - but it is rather verbose, requiring that the block representing the value be used twice, which can cause relatively large blocks:

if (abs of (Camera → Hero Tracker → Speed X)) > 8: set (Camera → Hero Tracker → Speed X) to (8 * ((Camera → Hero Tracker → Speed X) / (abs of (Camera → Hero Tracker → Speed X))))

(Now imagine if the variable were a reporter containing blocks itself, e.g. a list item getter!)

The only confusion I can see arising would be in vocal discussion - the phrase "the sign of block" sounds no different from "the sine of block" - but since these blocks would usually be discussed within context where which choice is meant is obvious, I don't think this is a significant blocker.

(* PS! This workaround actually doesn't work for zero - 0 / abs of 0 is just 0/0, which reports as NaN. Accounting for zero requires many more blocks and likely stack/non-reporter blocks as well.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions