ENH: label version of neg0(). Add noexcept to sign/pos/neg etc.

This commit is contained in:
Mark Olesen
2023-01-11 11:46:09 +01:00
parent d74572cae8
commit f08392010f
2 changed files with 31 additions and 13 deletions

View File

@ -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;
}

View File

@ -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;
}