diff --git a/CHANGELOG.md b/CHANGELOG.md index 936a0f470..ad503b2e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ - Added `diagSolve`, `max`, and `abs` vector operations. +- Improved coding guidelines for developers on floating point conventions. + ## 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..4f728abd7 100644 --- a/tests/unit/vector/VectorHandlerTests.hpp +++ b/tests/unit/vector/VectorHandlerTests.hpp @@ -8,6 +8,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__); }