Bug 168226 - Use o3tl::convert() for unit conversion instead of custom formula
Summary: Use o3tl::convert() for unit conversion instead of custom formula
Status: UNCONFIRMED
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:
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Blocks:
 
Reported: 2025-09-01 09:50 UTC by Hossein
Modified: 2025-09-01 09: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