Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latest from CODA-OSS and NITRO #667

Merged
merged 10 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions externals/coda-oss/UnitTest/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <std/bit>
#include <std/filesystem>
#include <std/bit> // std::endian
#include <std/numbers>

#include "CppUnitTest.h"

Expand Down
2 changes: 2 additions & 0 deletions externals/coda-oss/modules/c++/coda-oss-lite.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ClInclude Include="coda_oss\include\coda_oss\CPlusPlus.h" />
<ClInclude Include="coda_oss\include\coda_oss\cstddef.h" />
<ClInclude Include="coda_oss\include\coda_oss\namespace_.h" />
<ClInclude Include="coda_oss\include\coda_oss\numbers.h" />
<ClInclude Include="coda_oss\include\coda_oss\optional.h" />
<ClInclude Include="coda_oss\include\coda_oss\optional_.h" />
<ClInclude Include="coda_oss\include\coda_oss\span.h" />
Expand Down Expand Up @@ -407,6 +408,7 @@
<None Include="std\include\std\cstddef" />
<None Include="std\include\std\filesystem" />
<None Include="std\include\std\memory" />
<None Include="std\include\std\numbers" />
<None Include="std\include\std\optional" />
<None Include="std\include\std\span" />
<None Include="std\include\std\string" />
Expand Down
6 changes: 6 additions & 0 deletions externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,9 @@
<ClInclude Include="types\include\types\Complex.h">
<Filter>types</Filter>
</ClInclude>
<ClInclude Include="coda_oss\include\coda_oss\numbers.h">
<Filter>coda_oss</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
Expand Down Expand Up @@ -1225,5 +1228,8 @@
<None Include="sys\include\sys\sys_config.h.cmake.in">
<Filter>sys</Filter>
</None>
<None Include="std\include\std\numbers">
<Filter>std</Filter>
</None>
</ItemGroup>
</Project>
83 changes: 83 additions & 0 deletions externals/coda-oss/modules/c++/coda_oss/include/coda_oss/numbers.h
Original file line number Diff line number Diff line change
@@ -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 <math.h>
/*
#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 <typename T> constexpr T e_v = static_cast<T>(M_E);
template <typename T> constexpr T log2e_v = static_cast<T>(M_LOG2E);
template <typename T> constexpr T log10e_v = static_cast<T>(M_LOG10E);
template <typename T> constexpr T pi_v = static_cast<T>(M_PI);
template <typename T> constexpr T inv_pi_v = static_cast<T>(M_1_PI);
//template <typename T> constexpr T inv_sqrtpi_v = static_cast<T>();
template <typename T> constexpr T ln2_v = static_cast<T>(M_LN2);
template <typename T> constexpr T ln10_v = static_cast<T>(M_LN10);
template <typename T> constexpr T sqrt2_v = static_cast<T>(M_SQRT2);
//template <typename T> constexpr T sqrt3_v = static_cast<T>();
//template <typename T> constexpr T inv_sqrt3_v = static_cast<T>();
//template <typename T> constexpr T egamma_v = static_cast<T>();
//template <typename T> constexpr T phi_v = static_cast<T>();

constexpr double e = e_v<double>;
constexpr double log2e = log2e_v<double>;
constexpr double log10e = log10e_v<double>;
constexpr double pi = pi_v<double>;
constexpr double inv_pi = inv_pi_v<double>;
//constexpr double inv_sqrtpi = inv_sqrtpi_v<double>;
constexpr double ln2 = ln2_v<double>;
constexpr double ln10 = ln10_v<double>;
constexpr double sqrt2 = sqrt2_v<double>;
//constexpr double sqrt3 = sqrt3_v<double>;
//constexpr double inv_sqrt3 = inv_sqrt3_v<double>;
//constexpr double egamma = egamma_v<double>;
//constexpr double phi = phi_v<double>;
}

}

#endif // CODA_OSS_coda_oss_numbers_h_INCLUDED_
3 changes: 2 additions & 1 deletion externals/coda-oss/modules/c++/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ 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}
DIRECTORY "tests")
coda_add_tests(
MODULE_NAME ${MODULE_NAME}
DIRECTORY "unittests"
DEPS std-c++
UNITTEST)
16 changes: 9 additions & 7 deletions externals/coda-oss/modules/c++/math/include/math/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <math.h>
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 <typename T>
static constexpr T radians_to_degrees() noexcept
{
return static_cast<T>(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<typename T>
static constexpr T degrees_to_radians() noexcept
{
Expand All @@ -55,4 +57,4 @@ struct Constants
SPEED_OF_LIGHT_METERS_PER_SEC * METERS_TO_FEET;
};
}
#endif
#endif // CODA_OSS_math_Constants_h_INCLUDED_
11 changes: 11 additions & 0 deletions externals/coda-oss/modules/c++/math/unittests/test_sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <TestCase.h>
#include <math/Utilities.h>
#include <limits>
#include <std/numbers>

TEST_CASE(testZero)
{
Expand All @@ -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);
)

4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/math/wscript
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from build import writeConfig
NAME = 'math'
MAINTAINER = '[email protected]'
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

Expand Down
49 changes: 49 additions & 0 deletions externals/coda-oss/modules/c++/std/include/std/numbers
Original file line number Diff line number Diff line change
@@ -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 <numbers>
#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_
8 changes: 4 additions & 4 deletions externals/coda-oss/modules/c++/str/include/str/Convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ namespace str
{
template <typename T> int getPrecision(const T& type);
template <typename T> int getPrecision(const std::complex<T>&);
#if CODA_OSS_types_unique_zinteger
template <typename T> int getPrecision(const types::zinteger<T>&);
#if CODA_OSS_types_unique_ComplexInteger
template <typename T> int getPrecision(const types::ComplexInteger<T>&);
#endif

namespace details
Expand Down Expand Up @@ -335,9 +335,9 @@ int getPrecision(const std::complex<T>& type)
{
return getPrecision(type.real());
}
#if CODA_OSS_types_unique_zinteger
#if CODA_OSS_types_unique_ComplexInteger
template <typename T>
int getPrecision(const types::zinteger<T>& type)
int getPrecision(const types::ComplexInteger<T>& type)
{
return getPrecision(type.real());
}
Expand Down