Closed Bug 2083404 Opened 27 days ago Closed 16 days ago

Subtracting the result of hypot in calc in CSS causes addition instead

Categories

(Core :: CSS Parsing and Computation, defect)

defect

Tracking

()

RESOLVED FIXED
161 Branch
Tracking Status
firefox161 --- fixed

People

(Reporter: auberonlopez, Assigned: dholbert)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 1 external file)

Steps to reproduce

When hypot is subtracted from a value inside of calc in CSS, addition is performed instead of subtraction. For example, calc(100px - hypot(30px, 40px)) should evaluate to 50px, but it actually evaluates to 150px. The attached demo file visualizes this issue.

Steps to reproduce:

  1. Start Firefox by clicking on the desktop icon.
  2. Open the attached file.

Tested on
Ubuntu 26.0.4.1, with Firefox 154.0 AND Nightly 160.0a1 (2026-10-17)
MacOS 26.6.2 Firefox 157.0.1

AI Disclaimer
The example code was generated using AI but checked by hand. The bug report was written by hand.

Actual results

Multiple calc values were incorrectly evaluated, causing the test page to show red bars representing the delta. In each case except for the control case the value of hypot was added instead of subtracted.

Expected results

calc should have been correctly evaluated, with hypot being subtracted. This would have resulted in all green bars with no red.

The Bugbug bot thinks this bug should belong to the 'Core::CSS Parsing and Computation' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → CSS Parsing and Computation
Product: Firefox → Core

The severity field is not set for this bug.
:tlouw, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(tlouw)

Thanks for the bug report!

It looks like this dates back to when we added support for hypot(), in bug 1814469 -- I can reproduce this bug all the way back to Nightly 2023-03-05, the first build with that bug's patch.

One clue -- Bug 1814469 comment 2 mentioned what-sounds-like this exact issue (an inability to negate hypot() as well as abs() at the time).

And then later on, it looks like we fixed the analogous bug for abs() in bug 1863779. But we never fixed it for hypot(). So: likely we need toapply the same approach as in bug 1863779, but now for hypot().

Leaving ni=tlouw open since I suspect he's among the best-prepped to work on this, having worked on bug 1863779. :)

Blocks: css-values-4
Severity: -- → S3
Status: UNCONFIRMED → NEW
Depends on: 1814469
Ever confirmed: true
See Also: → 1863779

Actually this looks easy enough; I'll just take it.

Assignee: nobody → dholbert
Status: NEW → ASSIGNED
Flags: needinfo?(tlouw)

Before this patch, we mishandled negation of 'hypot()' in a special-case that
propagated the negation to the children. This was ineffective and wrong; it
still produced a positive result, due to the squaring arithmetic that happens
in a hypot() operation.

This patch makes hypot() share the same codpath that we use for many other math
functions, implementing negation using wrap_self_in_negate().

Pushed by dholbert@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/a362b3e9a326 https://hg.mozilla.org/integration/autoland/rev/e7324d6ddff6 Remove invalid special-case for negating hypot() expressions in calc(). r=firefox-style-system-reviewers,emilio
Status: ASSIGNED → RESOLVED
Closed: 16 days ago
Resolution: --- → FIXED
Target Milestone: --- → 161 Branch
Duplicate of this bug: 2086975

Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/64703 for changes under testing/web-platform/tests

Upstream PR merged by moz-wptsync-bot

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: