From f08392010f2c58ceb6684d6fdcd2c7197b795800 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 11 Jan 2023 11:46:09 +0100 Subject: [PATCH] ENH: label version of neg0(). Add noexcept to sign/pos/neg etc. --- src/OpenFOAM/primitives/Scalar/Scalar.H | 16 +++++------ .../primitives/ints/label/labelSpecific.H | 28 +++++++++++++++---- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.H b/src/OpenFOAM/primitives/Scalar/Scalar.H index dc5361f9bb..7e0d0784b9 100644 --- a/src/OpenFOAM/primitives/Scalar/Scalar.H +++ b/src/OpenFOAM/primitives/Scalar/Scalar.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -233,42 +233,42 @@ inline constexpr Scalar component(const Scalar val, const direction) noexcept //- Return 1 if s is greater_equal zero, or otherwise -1 -inline Scalar sign(const Scalar s) +inline Scalar sign(const Scalar s) noexcept { return (s >= 0)? 1: -1; } //- Return 1 if s is greater than zero, otherwise 1 -inline Scalar pos(const Scalar s) +inline Scalar pos(const Scalar s) noexcept { return (s > 0)? 1: 0; } //- Return 1 if s is greater_equal zero, or otherwise 0 -inline Scalar pos0(const Scalar s) +inline Scalar pos0(const Scalar s) noexcept { return (s >= 0)? 1: 0; } //- Return 1 if s is less than zero, or otherwise 0 -inline Scalar neg(const Scalar s) +inline Scalar neg(const Scalar s) noexcept { return (s < 0)? 1: 0; } //- Return 1 if s is less_equal zero, or otherwise 0 -inline Scalar neg0(const Scalar s) +inline Scalar neg0(const Scalar s) noexcept { return (s <= 0)? 1: 0; } //- Return the positive part of s, otherwise zero. Same as max(0, s). -inline Scalar posPart(const Scalar s) +inline Scalar posPart(const Scalar s) noexcept { return (s > 0)? s: 0; } @@ -276,7 +276,7 @@ inline Scalar posPart(const Scalar s) //- Return the negative part of s, otherwise zero. Same as min(0, s). // Does not change the sign -inline Scalar negPart(const Scalar s) +inline Scalar negPart(const Scalar s) noexcept { return (s < 0)? s: 0; } diff --git a/src/OpenFOAM/primitives/ints/label/labelSpecific.H b/src/OpenFOAM/primitives/ints/label/labelSpecific.H index 4f63951f6b..dc24d4c21e 100644 --- a/src/OpenFOAM/primitives/ints/label/labelSpecific.H +++ b/src/OpenFOAM/primitives/ints/label/labelSpecific.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014-2017 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -38,27 +39,44 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -inline label sign(const label s) +//- Return 1 if s is greater_equal zero, or otherwise -1 +inline label sign(const label s) noexcept { return (s >= 0)? 1: -1; } -inline label pos0(const label s) + +//- Return 1 if s is greater_equal zero, or otherwise 0 +inline label pos0(const label s) noexcept { return (s >= 0)? 1: 0; } -inline label neg(const label s) + +//- Return 1 if s is less than zero, or otherwise 0 +inline label neg(const label s) noexcept { return (s < 0)? 1: 0; } -inline label posPart(const label s) + +//- Return 1 if s is less_equal zero, or otherwise 0 +inline label neg0(const label s) noexcept +{ + return (s <= 0)? 1: 0; +} + + +//- Return the positive part of s, otherwise zero. Same as max(0, s). +inline label posPart(const label s) noexcept { return (s > 0)? s: 0; } -inline label negPart(const label s) + +//- Return the negative part of s, otherwise zero. Same as min(0, s). +// Does not change the sign +inline label negPart(const label s) noexcept { return (s < 0)? s: 0; }