diff --git a/externals/coda-oss/UnitTest/pch.h b/externals/coda-oss/UnitTest/pch.h index 69edb0037c..3ee1dd19ec 100644 --- a/externals/coda-oss/UnitTest/pch.h +++ b/externals/coda-oss/UnitTest/pch.h @@ -32,6 +32,7 @@ #include #include #include // std::endian +#include #include "CppUnitTest.h" diff --git a/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj index fe33e7cb1c..ca8e29c77b 100644 --- a/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj +++ b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj @@ -20,6 +20,7 @@ + @@ -407,6 +408,7 @@ + diff --git a/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters index 6110baa006..05fb54dc30 100644 --- a/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters +++ b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters @@ -750,6 +750,9 @@ types + + coda_oss + @@ -1225,5 +1228,8 @@ sys + + std + \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/numbers.h b/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/numbers.h new file mode 100644 index 0000000000..698bb042d0 --- /dev/null +++ b/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/numbers.h @@ -0,0 +1,83 @@ +/* ========================================================================= + * This file is part of coda_oss-c++ + * ========================================================================= + * + * (C) Copyright 2020-2022, Maxar Technologies, Inc. + * + * coda_oss-c++ is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; If not, http://www.gnu.org/licenses/. + * + */ +#pragma once +#ifndef CODA_OSS_coda_oss_numbers_h_INCLUDED_ +#define CODA_OSS_coda_oss_numbers_h_INCLUDED_ + +#ifndef _USE_MATH_DEFINES +#define _USE_MATH_DEFINES // get M_PI, etc. +#endif +#include +/* +#define M_E 2.71828182845904523536 // e +#define M_LOG2E 1.44269504088896340736 // log2(e) +#define M_LOG10E 0.434294481903251827651 // log10(e) +#define M_LN2 0.693147180559945309417 // ln(2) +#define M_LN10 2.30258509299404568402 // ln(10) +#define M_PI 3.14159265358979323846 // pi +#define M_PI_2 1.57079632679489661923 // pi/2 +#define M_PI_4 0.785398163397448309616 // pi/4 +#define M_1_PI 0.318309886183790671538 // 1/pi +#define M_2_PI 0.636619772367581343076 // 2/pi +#define M_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi) +#define M_SQRT2 1.41421356237309504880 // sqrt(2) +#define M_SQRT1_2 0.707106781186547524401 // 1/sqrt(2) +*/ + +namespace coda_oss +{ + +namespace numbers +{ +// https://en.cppreference.com/w/cpp/header/numbers + +template constexpr T e_v = static_cast(M_E); +template constexpr T log2e_v = static_cast(M_LOG2E); +template constexpr T log10e_v = static_cast(M_LOG10E); +template constexpr T pi_v = static_cast(M_PI); +template constexpr T inv_pi_v = static_cast(M_1_PI); +//template constexpr T inv_sqrtpi_v = static_cast(); +template constexpr T ln2_v = static_cast(M_LN2); +template constexpr T ln10_v = static_cast(M_LN10); +template constexpr T sqrt2_v = static_cast(M_SQRT2); +//template constexpr T sqrt3_v = static_cast(); +//template constexpr T inv_sqrt3_v = static_cast(); +//template constexpr T egamma_v = static_cast(); +//template constexpr T phi_v = static_cast(); + +constexpr double e = e_v; +constexpr double log2e = log2e_v; +constexpr double log10e = log10e_v; +constexpr double pi = pi_v; +constexpr double inv_pi = inv_pi_v; +//constexpr double inv_sqrtpi = inv_sqrtpi_v; +constexpr double ln2 = ln2_v; +constexpr double ln10 = ln10_v; +constexpr double sqrt2 = sqrt2_v; +//constexpr double sqrt3 = sqrt3_v; +//constexpr double inv_sqrt3 = inv_sqrt3_v; +//constexpr double egamma = egamma_v; +//constexpr double phi = phi_v; +} + +} + +#endif // CODA_OSS_coda_oss_numbers_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/math/CMakeLists.txt b/externals/coda-oss/modules/c++/math/CMakeLists.txt index 7af371b07a..387b3e955c 100644 --- a/externals/coda-oss/modules/c++/math/CMakeLists.txt +++ b/externals/coda-oss/modules/c++/math/CMakeLists.txt @@ -3,7 +3,7 @@ set(MODULE_NAME math) coda_add_module( ${MODULE_NAME} VERSION 0.1 - DEPS except-c++ str-c++ sys-c++ types-c++) + DEPS except-c++ str-c++ sys-c++ types-c++ coda_oss-c++) coda_add_tests( MODULE_NAME ${MODULE_NAME} @@ -11,4 +11,5 @@ coda_add_tests( coda_add_tests( MODULE_NAME ${MODULE_NAME} DIRECTORY "unittests" + DEPS std-c++ UNITTEST) diff --git a/externals/coda-oss/modules/c++/math/include/math/Constants.h b/externals/coda-oss/modules/c++/math/include/math/Constants.h index 59064839f9..64803a19e7 100644 --- a/externals/coda-oss/modules/c++/math/include/math/Constants.h +++ b/externals/coda-oss/modules/c++/math/include/math/Constants.h @@ -20,24 +20,26 @@ * */ -#ifndef __MATH_CONSTANTS_H__ -#define __MATH_CONSTANTS_H__ +#pragma once +#ifndef CODA_OSS_math_Constants_h_INCLUDED_ +#define CODA_OSS_math_Constants_h_INCLUDED_ + +#include "coda_oss/numbers.h" -#include namespace math { -struct Constants +struct Constants final { static constexpr double FEET_TO_METERS = 0.3048; static constexpr double METERS_TO_FEET = 1.0 / FEET_TO_METERS; - static constexpr double RADIANS_TO_DEGREES = 180.0 / M_PI; + static constexpr double RADIANS_TO_DEGREES = 180.0 / coda_oss::numbers::pi; template static constexpr T radians_to_degrees() noexcept { return static_cast(RADIANS_TO_DEGREES); } - static constexpr double DEGREES_TO_RADIANS = M_PI / 180.0; + static constexpr double DEGREES_TO_RADIANS = coda_oss::numbers::pi / 180.0; template static constexpr T degrees_to_radians() noexcept { @@ -55,4 +57,4 @@ struct Constants SPEED_OF_LIGHT_METERS_PER_SEC * METERS_TO_FEET; }; } -#endif +#endif // CODA_OSS_math_Constants_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/math/unittests/test_sign.cpp b/externals/coda-oss/modules/c++/math/unittests/test_sign.cpp index 51d7f510ed..89e1b855e1 100644 --- a/externals/coda-oss/modules/c++/math/unittests/test_sign.cpp +++ b/externals/coda-oss/modules/c++/math/unittests/test_sign.cpp @@ -23,6 +23,7 @@ #include #include #include +#include TEST_CASE(testZero) { @@ -43,9 +44,19 @@ TEST_CASE(testNegative) TEST_ASSERT_EQ(math::sign(-0.1), -1); } +TEST_CASE(testConstants) +{ + static auto pi = std::numbers::pi; // "Conditional expression is constant" + TEST_ASSERT_EQ(pi, M_PI); + + static auto e = std::numbers::e; // "Conditional expression is constant" + TEST_ASSERT_EQ(e, M_E); +} + TEST_MAIN( TEST_CHECK(testZero); TEST_CHECK(testPositive); TEST_CHECK(testNegative); + TEST_CHECK(testConstants); ) diff --git a/externals/coda-oss/modules/c++/math/wscript b/externals/coda-oss/modules/c++/math/wscript index 1c048f0c45..c8de78ecc6 100644 --- a/externals/coda-oss/modules/c++/math/wscript +++ b/externals/coda-oss/modules/c++/math/wscript @@ -1,9 +1,9 @@ from build import writeConfig NAME = 'math' -MAINTAINER = 'asylvest@users.sourceforge.net' VERSION = '0.1' USELIB = 'MATH' -MODULE_DEPS = 'except str sys types' +MODULE_DEPS = 'except str sys types coda_oss' +TEST_DEPS = 'std' options = distclean = lambda p: None diff --git a/externals/coda-oss/modules/c++/std/include/std/numbers b/externals/coda-oss/modules/c++/std/include/std/numbers new file mode 100644 index 0000000000..e089df22b2 --- /dev/null +++ b/externals/coda-oss/modules/c++/std/include/std/numbers @@ -0,0 +1,49 @@ +/* ========================================================================= + * This file is part of std-c++ + * ========================================================================= + * + * (C) Copyright 2023, Maxar Technologies, Inc. + * + * std-c++ is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; If not, http://www.gnu.org/licenses/. + * + */ +#pragma once +#ifndef CODA_OSS_std_numbers_INCLUDED_ +#define CODA_OSS_std_numbers_INCLUDED_ + +#include "coda_oss/numbers.h" +#include "coda_oss/CPlusPlus.h" + + // Make it (too?) easy for clients to get our various std:: implementations +#ifndef CODA_OSS_NO_std_numbers + #if CODA_OSS_cpp20 + #include + #define CODA_OSS_NO_std_numbers 1 // provided by implementation, probably C++20 + #endif + #ifndef CODA_OSS_NO_std_numbers + #define CODA_OSS_NO_std_numbers 0 // <= C++20, use our own + #endif +#endif + +#if !CODA_OSS_NO_std_numbers +namespace std // This is slightly uncouth: we're not supposed to augment "std". +{ +namespace numbers +{ + using namespace coda_oss::numbers; +} +} +#endif // CODA_OSS_NO_std_numbers + +#endif // CODA_OSS_std_numbers_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/str/include/str/Convert.h b/externals/coda-oss/modules/c++/str/include/str/Convert.h index 8c915b77cd..0b3698e49f 100644 --- a/externals/coda-oss/modules/c++/str/include/str/Convert.h +++ b/externals/coda-oss/modules/c++/str/include/str/Convert.h @@ -46,8 +46,8 @@ namespace str { template int getPrecision(const T& type); template int getPrecision(const std::complex&); -#if CODA_OSS_types_unique_zinteger -template int getPrecision(const types::zinteger&); +#if CODA_OSS_types_unique_ComplexInteger +template int getPrecision(const types::ComplexInteger&); #endif namespace details @@ -335,9 +335,9 @@ int getPrecision(const std::complex& type) { return getPrecision(type.real()); } -#if CODA_OSS_types_unique_zinteger +#if CODA_OSS_types_unique_ComplexInteger template -int getPrecision(const types::zinteger& type) +int getPrecision(const types::ComplexInteger& type) { return getPrecision(type.real()); }