Skip to content

[FEEDBACK] The :math function should be better-specified #959

@sffc

Description

@sffc

As far as I can tell, in registry.md, the :math function allows for arbitrary addition and subtraction.

I think this is a problem: it can run into the floating-point math problems well known to most programmers, such as 0.1 + 0.2 != 0.3. For example, a message of the following form does not have well-defined behavior:

.input {$num :number}
.local $num_adjusted = {$num :math subtract=0.1}
.match $num_adjusted
0.1 {{...}}
0.2 {{...}}
0.3 {{...}}
*   {{...}}

Are there any use cases for this function other than adding or subtracting integers?

I suggest changing the function to restrict the domain to integers and defining that the math operates as if on decimal values. So, for example, {1.234 :math subtract=1} should be guaranteed to return 0.234.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Preview-FeedbackFeedback gathered during the technical previewfunctionsIssue pertains to the default function set

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions