basic/qa/vba_tests/cint.vb | 12 +++++------- basic/qa/vba_tests/clng.vb | 9 +++++---- basic/qa/vba_tests/mid.vb | 4 ++++ basic/source/sbx/sbxconv.hxx | 6 +++++- 4 files changed, 19 insertions(+), 12 deletions(-)
New commits: commit 76aafa18b7a81363a642c5b0ea381ea71c5e5185 Author: Andreas Heinisch <[email protected]> AuthorDate: Thu Nov 20 16:48:08 2025 +0100 Commit: Andreas Heinisch <[email protected]> CommitDate: Mon Nov 24 20:42:41 2025 +0100 tdf#162711 - VBASupport requires banker’s rounding for integer conversions Change-Id: Ife3f7aae3ba094fe83a5eda6b3d50d9358cc1184 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194286 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <[email protected]> diff --git a/basic/qa/vba_tests/cint.vb b/basic/qa/vba_tests/cint.vb index 42e41e53568f..4df0a0ba647c 100644 --- a/basic/qa/vba_tests/cint.vb +++ b/basic/qa/vba_tests/cint.vb @@ -23,13 +23,11 @@ Sub verify_testCInt() TestUtil.AssertEqual(CInt(-1.9), -2, "CInt(-1.9)") TestUtil.AssertEqual(CInt(0.2), 0, "CInt(0.2)") -REM In excel: -REM If the fraction is less than or equal to .5, the result will round down. -REM If the fraction is greater than .5, the result will round up. - -REM TestUtil.AssertEqual(CInt(0.5), 0, "CInt(0.5)") -REM TestUtil.AssertEqual(CInt(1.5), 2, "CInt(1.5)") -REM TestUtil.AssertEqual(CInt(2.5), 2, "CInt(2.5)") + ' tdf#162711 - VBASupport requires banker’s rounding for integer conversions + TestUtil.AssertEqual(CInt(0.5), 0, "CInt(0.5)") + TestUtil.AssertEqual(CInt(1.5), 2, "CInt(1.5)") + TestUtil.AssertEqual(CInt(2.5), 2, "CInt(2.5)") + TestUtil.AssertEqual(CInt(3.5), 4, "CInt(3.5)") TestUtil.AssertEqual(CInt(10.51), 11, "CInt(10.51)") TestUtil.AssertEqual(CInt("&H75FF"), 30207, "CInt(""&H75FF"")") diff --git a/basic/qa/vba_tests/clng.vb b/basic/qa/vba_tests/clng.vb index ae9421686d34..40cc4864980d 100644 --- a/basic/qa/vba_tests/clng.vb +++ b/basic/qa/vba_tests/clng.vb @@ -22,10 +22,11 @@ Sub verify_testCLng() TestUtil.AssertEqual(CLng(-1.9), -2, "CLng(-1.9)") TestUtil.AssertEqual(CLng(0.2), 0, "CLng(0.2)") -REM TestUtil.AssertEqual(CLng(0.5), 0, "CLng(0.5)") - -REM If the fraction is less than or equal to .5, the result will round down. -REM If the fraction is greater than .5, the result will round up. + ' tdf#162711 - VBASupport requires banker’s rounding for integer conversions + TestUtil.AssertEqual(CLng(0.5), 0, "CLng(0.5)") + TestUtil.AssertEqual(CLng(1.5), 2, "CLng(1.5)") + TestUtil.AssertEqual(CLng(2.5), 2, "CLng(2.5)") + TestUtil.AssertEqual(CLng(3.5), 4, "CLng(3.5)") TestUtil.AssertEqual(CLng(10.51), 11, "CLng(10.51)") TestUtil.AssertEqual(CLng("&H75FF"), 30207, "CLng(""&H75FF"")") diff --git a/basic/qa/vba_tests/mid.vb b/basic/qa/vba_tests/mid.vb index ebd326109f5d..6eabe787d5a6 100644 --- a/basic/qa/vba_tests/mid.vb +++ b/basic/qa/vba_tests/mid.vb @@ -26,6 +26,10 @@ Sub verify_testMid() TestUtil.AssertEqual(Mid(start:=6, string:="LibreOffice" ), "Office", "Mid() with 2 keyword names" ) TestUtil.AssertEqual(Mid(length:=5, start:=1, string:="LibreOffice" ), "Libre", "Mid() with 3 keyword names" ) + ' tdf#162711 - VBASupport requires banker’s rounding for integer conversions + TestUtil.AssertEqual(Mid("abc", 2.5, 1), "b", "Mid(""abc"", 2.5, 1)") + TestUtil.AssertEqual(Mid("abcd", 3.5, 1), "d", "Mid(""abcd"", 3.5, 1)") + Exit Sub errorHandler: TestUtil.ReportErrorHandler("verify_testMid", Err, Error$, Erl) diff --git a/basic/source/sbx/sbxconv.hxx b/basic/source/sbx/sbxconv.hxx index b04d534f42a2..61a4a4788fd4 100644 --- a/basic/source/sbx/sbxconv.hxx +++ b/basic/source/sbx/sbxconv.hxx @@ -24,6 +24,7 @@ #include <basic/sbx.hxx> #include <basic/sbxcore.hxx> #include <basic/sbxdef.hxx> +#include <runtime.hxx> #include <o3tl/float_int_conversion.hxx> #include <o3tl/safeint.hxx> @@ -34,7 +35,10 @@ class SbxArray; template <std::integral I> I ConvertWithOverflowTo(double f) { - f = rtl::math::round(f); + // tdf#162711 - VBASupport mode requires banker’s rounding for integer conversions + f = rtl_math_round(f, 0, + SbiRuntime::isVBAEnabled() ? rtl_math_RoundingMode_HalfEven + : rtl_math_RoundingMode_Corrected); if (!o3tl::convertsToAtMost(f, std::numeric_limits<I>::max())) { SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
