From e3d2ce135ddd625c0ab91ebccbab0920c8a07f43 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 17 Mar 2026 17:50:42 +0000 Subject: [PATCH 1/3] fixed floating point and constant usage --- CHANGELOG.md | 2 ++ docs/doxygen/doxygen-awesome.css | 18 +++++++++--------- .../developer_guide/coding_guidelines.rst | 6 ++++++ tests/unit/vector/VectorHandlerTests.hpp | 13 +++++++------ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 936a0f470..f846df36c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ - Added `diagSolve`, `max`, and `abs` vector operations. +- Improved coding guidelines for developers. + ## Changes to Re::Solve in release 0.99.2 ### Major Features diff --git a/docs/doxygen/doxygen-awesome.css b/docs/doxygen/doxygen-awesome.css index 08238977a..9656dc076 100644 --- a/docs/doxygen/doxygen-awesome.css +++ b/docs/doxygen/doxygen-awesome.css @@ -316,7 +316,7 @@ body, table, div, p, dl, #nav-tree .label, .title, } h1, h2, h3, h4, h5 { - margin-top: .9em; + margin-top: 0.9em; font-weight: 600; line-height: initial; } @@ -901,7 +901,7 @@ div.contents, div.header .title, div.header .summary { div.contents, div.header .title { line-height: initial; - margin: calc(var(--spacing-medium) + .2em) auto var(--spacing-medium) auto; + margin: calc(var(--spacing-medium) + 0.2em) auto var(--spacing-medium) auto; } div.header .summary { @@ -1019,7 +1019,7 @@ blockquote::before, blockquote::after { font-weight: bold; font-family: serif; font-size: 360%; - opacity: .15; + opacity: 0.15; position: absolute; } @@ -1945,7 +1945,7 @@ div.dynheader img[src="closed.png"] { display: block !important; visibility: visible; width: calc(100vw - 2 * var(--spacing-large)); - animation: fade .5s; + animation: fade 0.5s; } @keyframes fade { @@ -2344,7 +2344,7 @@ doxygen-awesome-dark-mode-toggle { } doxygen-awesome-dark-mode-toggle > svg { - transition: transform .1s ease-in-out; + transition: transform 0.1s ease-in-out; } doxygen-awesome-dark-mode-toggle:active > svg { @@ -2383,7 +2383,7 @@ doxygen-awesome-fragment-copy-button { } .doxygen-awesome-fragment-wrapper:hover doxygen-awesome-fragment-copy-button, doxygen-awesome-fragment-copy-button.success { - opacity: .28; + opacity: 0.28; } doxygen-awesome-fragment-copy-button:hover, doxygen-awesome-fragment-copy-button.success { @@ -2427,9 +2427,9 @@ a.anchorlink { margin-left: var(--spacing-small); color: var(--page-foreground-color) !important; text-decoration: none; - opacity: .15; + opacity: 0.15; display: none; - transition: opacity .1s ease-in-out, color .1s ease-in-out; + transition: opacity 0.1s ease-in-out, color 0.1s ease-in-out; } a.anchorlink svg { @@ -2442,7 +2442,7 @@ h3 a.anchorlink svg, h4 a.anchorlink svg { } a.anchorlink:hover { - opacity: .45; + opacity: 0.45; } h2:hover a.anchorlink, h1:hover a.anchorlink, h3:hover a.anchorlink, h4:hover a.anchorlink { diff --git a/docs/sphinx/developer_guide/coding_guidelines.rst b/docs/sphinx/developer_guide/coding_guidelines.rst index 54b118101..4ddffc339 100644 --- a/docs/sphinx/developer_guide/coding_guidelines.rst +++ b/docs/sphinx/developer_guide/coding_guidelines.rst @@ -81,6 +81,12 @@ Constants names should be capitalized and words separated by underscores. constexpr double SQRTTWO_ = 1.4142 // No, there is a trailing underscore but not between words constexpr double EXP = 2.7183 // Yes +Floating point variables +------------------------------ + +Use ``real_type`` for floating point variables. This is a typedef defined in ``Common.h`` and can be set to either ``float`` or ``double`` depending on the precision needed. +Always use a leading 0 for floating point numbers less than 1 and use a trailing 0 for whole numbers used as floating point numbers. + Exceptions to naming conventions -------------------------------- diff --git a/tests/unit/vector/VectorHandlerTests.hpp b/tests/unit/vector/VectorHandlerTests.hpp index 4f0ef8a8d..a1dfca8b3 100644 --- a/tests/unit/vector/VectorHandlerTests.hpp +++ b/tests/unit/vector/VectorHandlerTests.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -90,7 +91,7 @@ namespace ReSolve x.setToConst(3.0, memspace_); y.setToConst(1.0, memspace_); - real_type alpha = 0.5; + real_type alpha = ReSolve::constants::HALF; // the result is a vector with y[i] = 2.5 forall i; handler_.axpy(alpha, &x, &y, memspace_); @@ -172,7 +173,7 @@ namespace ReSolve } else { - c = 0.5; + c = ReSolve::constants::HALF; } x.setToConst(ii, c, memspace_); } @@ -224,16 +225,16 @@ namespace ReSolve V.setToConst(1.0, memspace_); yN.setToConst(-1.0, memspace_); - xN.setToConst(.5, memspace_); + xN.setToConst(ReSolve::constants::HALF, memspace_); yT.setToConst(-1.0, memspace_); - xT.setToConst(.5, memspace_); + xT.setToConst(ReSolve::constants::HALF, memspace_); real_type alpha = -1.0; real_type beta = 1.0; handler_.gemv('N', K, alpha, beta, &V, &yN, &xN, memspace_); - status *= verifyAnswer(xN, static_cast(K) + 0.5); + status *= verifyAnswer(xN, static_cast(K) + ReSolve::constants::HALF); handler_.gemv('T', K, alpha, beta, &V, &yT, &xT, memspace_); - status *= verifyAnswer(xT, static_cast(N) + 0.5); + status *= verifyAnswer(xT, static_cast(N) + ReSolve::constants::HALF); return status.report(__func__); } From fa9400e9c5c6b1f31438695216e45bae02e16294 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 17 Mar 2026 17:54:06 +0000 Subject: [PATCH 2/3] Apply pre-commmit fixes --- tests/unit/vector/VectorHandlerTests.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/vector/VectorHandlerTests.hpp b/tests/unit/vector/VectorHandlerTests.hpp index a1dfca8b3..4f728abd7 100644 --- a/tests/unit/vector/VectorHandlerTests.hpp +++ b/tests/unit/vector/VectorHandlerTests.hpp @@ -7,8 +7,8 @@ #include #include #include -#include +#include #include #include #include From 6e1e8147da9eb52f60c110d589ec2b2cce369704 Mon Sep 17 00:00:00 2001 From: Shaked Regev <35384901+shakedregev@users.noreply.github.com> Date: Tue, 17 Mar 2026 13:56:07 -0400 Subject: [PATCH 3/3] Enhance coding guidelines for floating point conventions Clarified coding guidelines regarding floating point conventions. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f846df36c..ad503b2e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ - Added `diagSolve`, `max`, and `abs` vector operations. -- Improved coding guidelines for developers. +- Improved coding guidelines for developers on floating point conventions. ## Changes to Re::Solve in release 0.99.2