Bug 168226 - Use o3tl::convert() for unit conversion instead of custom formula
Summary: Use o3tl::convert() for unit conversion instead of custom formula
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:26.2.0
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Blocks:
 
Reported: 2025-09-01 09:50 UTC by Hossein
Modified: 2025-10-22 13:51 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hossein 2025-09-01 09:50:37 UTC
Description:
Unit conversion is done in various places in LibreOffice core. It is recommended to use the built-in function: o3tl::convert instead of writing a custom formula. The goal is to the increase accuracy and avoid errors, and also to be able to handle possible overflows.

This is an example commit:

Use o3tl::convert instead of manual conversion 6cbadf8bf1295a9c3d1d9a389e8cf076314facf4

This task is described in more details in this blog post:
https://dev.blog.documentfoundation.org/2025/08/28/unit-conversion-in-libreoffice-code/

Code Pointers:
To to find instances to change, one can try finding some magic numbers listed in the blog post. For example, consider measuring a line based on twips:

line – Line unit (312 twip)

If you search for 312 as a whole word, you may find some examples:

$ git grep -w 312 *.cxx
Comment 1 Commit Notification 2025-10-22 06:26:10 UTC
Okhuomon Ajayi committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/6c688ee8625f3f5e7be50912e02cdf59f6ae7e5f

tdf#168226 Use o3tl::convert() for unit conversion instead of custom

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 2 Commit Notification 2025-10-22 13:51:21 UTC
Okhuomon Ajayi committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/b261377735231e0556ad682feae0046e1029c1e7

tdf#168226 Fix rounding behavior in PtTo10Mu and TenMuToPt functions

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.