[PR #15098] [MERGED] Fix accuracy bugs around float/double/int conversions #30410

Open
opened 2026-01-31 09:40:41 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/15098
Author: @lhecker
Created: 4/4/2023
Status: Merged
Merged: 4/4/2023
Merged by: @DHowett

Base: mainHead: dev/lhecker/float-double-inaccuracy-bugs


📝 Commits (2)

  • c8865d4 Fix accuracy bugs around float/double conversions
  • e2edab0 Fix compilation

📊 Changes

7 files changed (+55 additions, -59 deletions)

View changed files

📝 src/cascadia/TerminalControl/ControlCore.cpp (+17 -20)
📝 src/cascadia/TerminalControl/ControlCore.h (+9 -9)
📝 src/cascadia/TerminalControl/ControlCore.idl (+6 -6)
📝 src/cascadia/TerminalControl/TermControl.cpp (+15 -15)
📝 src/cascadia/UnitTests_Control/ControlInteractivityTests.cpp (+3 -2)
📝 src/cascadia/WindowsTerminal/AppHost.cpp (+4 -6)
📝 src/inc/til/math.h (+1 -1)

📄 Description

I noticed this bug while resizing my window on my 150% scale display.
Every 3 "snaps" of the window size, it would fail to resize the text
buffer. I found that this occurs, because we convert the swap chain
size from a float into a double, which converts my 597.333313 height
into 597.33331298828125, which then multiplied by 1.5 results in
895.999969482421875. If you just cast this to an integer, it'll
result in a height of 895px instead of the expected 896px.

This PR addresses the issue in two ways:

  • Replace casts to integers with lrint or floor, etc.
  • Remove many of the redundant double <> float conversions.

PR Checklist

  • Resizing my window always resizes the text buffer

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/15098 **Author:** [@lhecker](https://github.com/lhecker) **Created:** 4/4/2023 **Status:** ✅ Merged **Merged:** 4/4/2023 **Merged by:** [@DHowett](https://github.com/DHowett) **Base:** `main` ← **Head:** `dev/lhecker/float-double-inaccuracy-bugs` --- ### 📝 Commits (2) - [`c8865d4`](https://github.com/microsoft/terminal/commit/c8865d4d5f3a0432de530e66a55e6c608c6e980c) Fix accuracy bugs around float/double conversions - [`e2edab0`](https://github.com/microsoft/terminal/commit/e2edab097655acc45145abf36a40e3f68fd29bf5) Fix compilation ### 📊 Changes **7 files changed** (+55 additions, -59 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalControl/ControlCore.cpp` (+17 -20) 📝 `src/cascadia/TerminalControl/ControlCore.h` (+9 -9) 📝 `src/cascadia/TerminalControl/ControlCore.idl` (+6 -6) 📝 `src/cascadia/TerminalControl/TermControl.cpp` (+15 -15) 📝 `src/cascadia/UnitTests_Control/ControlInteractivityTests.cpp` (+3 -2) 📝 `src/cascadia/WindowsTerminal/AppHost.cpp` (+4 -6) 📝 `src/inc/til/math.h` (+1 -1) </details> ### 📄 Description I noticed this bug while resizing my window on my 150% scale display. Every 3 "snaps" of the window size, it would fail to resize the text buffer. I found that this occurs, because we convert the swap chain size from a float into a double, which converts my 597.333313 height into 597.33331298828125, which then multiplied by 1.5 results in 895.999969482421875. If you just cast this to an integer, it'll result in a height of 895px instead of the expected 896px. This PR addresses the issue in two ways: * Replace casts to integers with `lrint` or `floor`, etc. * Remove many of the redundant double <> float conversions. ## PR Checklist * Resizing my window always resizes the text buffer ✅ --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:40:41 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30410