Skip to content

Normalize negative zero to positive zero in mathParser #9274

@coderabbitai

Description

@coderabbitai

Description

The math expression parser in src/lib/litegraph/src/utils/mathParser.ts can produce -0 from expressions like -0, 0 * -1, or 0 / -1. While -0 === 0 is true in JavaScript, the expr-eval library explicitly normalizes negative zero to positive zero (nstack[0] === 0 ? 0 : result) because -0 has caused real issues downstream in some contexts.

Suggested Change

Add normalization at the end of evaluateMathExpression:

return result === 0 ? 0 : result

Context

References

┆Issue is synchronized with this Notion page by Unito

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions