Subtracting the result of hypot in calc in CSS causes addition instead
Categories
(Core :: CSS Parsing and Computation, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox161 | --- | fixed |
People
(Reporter: auberonlopez, Assigned: dholbert)
References
(Blocks 1 open bug)
Details
Attachments
(1 file, 1 external file)
|
2.10 KB,
text/html
|
Details |
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:
- Start Firefox by clicking on the desktop icon.
- 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.
Comment 1•27 days ago
|
||
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.
Comment 2•19 days ago
|
||
The severity field is not set for this bug.
:tlouw, could you have a look please?
For more information, please visit BugBot documentation.
| Assignee | ||
Comment 3•18 days ago
|
||
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. :)
| Assignee | ||
Comment 4•17 days ago
|
||
Actually this looks easy enough; I'll just take it.
| Assignee | ||
Comment 5•17 days ago
|
||
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().
| Assignee | ||
Comment 6•17 days ago
|
||
Comment 8•16 days ago
|
||
| bugherder | ||
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
Description
•