Compare commits
No commits in common. "f550594b85be0e40d6368c78b4812d04597fb53e" and "352bf756bdb5852f7d06d5e50acc2f4823264108" have entirely different histories.
f550594b85
...
352bf756bd
@ -44,7 +44,7 @@ add_subdirectory(src/myx/base)
|
|||||||
add_subdirectory(src/myx/filesystem)
|
add_subdirectory(src/myx/filesystem)
|
||||||
add_subdirectory(src/myx/qt)
|
add_subdirectory(src/myx/qt)
|
||||||
add_subdirectory(src/myx/math)
|
add_subdirectory(src/myx/math)
|
||||||
# add_subdirectory(src/myx/redis)
|
add_subdirectory(src/myx/redis)
|
||||||
|
|
||||||
# Примеры
|
# Примеры
|
||||||
if(MYXLIB_BUILD_EXAMPLES OR MYXLIB_BUILD_EXAMPLES_HO)
|
if(MYXLIB_BUILD_EXAMPLES OR MYXLIB_BUILD_EXAMPLES_HO)
|
||||||
|
@ -1,5 +1 @@
|
|||||||
#ifndef MYXLIB_BUILD_LIBRARIES
|
|
||||||
#error Define MYXLIB_BUILD_LIBRARIES to compile this file.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
@ -5,10 +5,8 @@
|
|||||||
|
|
||||||
#ifdef MYXLIB_BUILD_LIBRARIES
|
#ifdef MYXLIB_BUILD_LIBRARIES
|
||||||
#undef MYXLIB_HEADER_ONLY
|
#undef MYXLIB_HEADER_ONLY
|
||||||
#define MYXLIB_INLINE inline
|
|
||||||
#else
|
#else
|
||||||
#define MYXLIB_HEADER_ONLY
|
#define MYXLIB_HEADER_ONLY
|
||||||
#define MYXLIB_INLINE inline
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MYXLIB_HEADER_ONLY
|
#ifdef MYXLIB_HEADER_ONLY
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_
|
#ifndef MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_
|
||||||
#define MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_
|
#define MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
@ -3,10 +3,12 @@ set(TRGT filesystem)
|
|||||||
|
|
||||||
# cmake-format: off
|
# cmake-format: off
|
||||||
# Список файлов исходных текстов
|
# Список файлов исходных текстов
|
||||||
|
if(NOT MYXLIB_HEADER_ONLY)
|
||||||
set(TRGT_cpp
|
set(TRGT_cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/current_executable.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/current_executable.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/paths_mt.cpp)
|
${CMAKE_CURRENT_SOURCE_DIR}/paths_mt.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Список заголовочных файлов
|
# Список заголовочных файлов
|
||||||
set(TRGT_hpp
|
set(TRGT_hpp
|
||||||
|
@ -22,14 +22,14 @@ namespace filesystem {
|
|||||||
error "Class CurrentExecutable is supported only in Linux"
|
error "Class CurrentExecutable is supported only in Linux"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MYXLIB_INLINE CurrentExecutable::CurrentExecutable() :
|
CurrentExecutable::CurrentExecutable() :
|
||||||
m_procFilePath( QStringLiteral( "/proc/self/exe" ) )
|
m_procFilePath( QStringLiteral( "/proc/self/exe" ) )
|
||||||
{
|
{
|
||||||
m_canonicalFilePath = m_procFilePath.canonicalFilePath();
|
m_canonicalFilePath = m_procFilePath.canonicalFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QFileInfo& CurrentExecutable::canonicalFilePath() const
|
const QFileInfo& CurrentExecutable::canonicalFilePath() const
|
||||||
{
|
{
|
||||||
return( m_canonicalFilePath );
|
return( m_canonicalFilePath );
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,2 @@
|
|||||||
#ifndef MYXLIB_BUILD_LIBRARIES
|
#include <myx/filesystem/current_executable.hpp>
|
||||||
#error Define MYXLIB_BUILD_LIBRARIES to compile this file.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/filesystem/current_executable-inl.hpp>
|
#include <myx/filesystem/current_executable-inl.hpp>
|
||||||
|
@ -19,9 +19,9 @@ namespace myx {
|
|||||||
|
|
||||||
namespace filesystem {
|
namespace filesystem {
|
||||||
|
|
||||||
MYXLIB_INLINE Paths::Paths() = default;
|
Paths::Paths() = default;
|
||||||
|
|
||||||
MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType()
|
Paths::HierarchyType Paths::getHierarchyType()
|
||||||
{
|
{
|
||||||
QRegExp binUnityRegexp( "/s*bin/unity$" );
|
QRegExp binUnityRegexp( "/s*bin/unity$" );
|
||||||
QRegExp binRegexp( "/s*bin$" );
|
QRegExp binRegexp( "/s*bin$" );
|
||||||
@ -170,7 +170,7 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType()
|
|||||||
} // Paths::getHierarchyType
|
} // Paths::getHierarchyType
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& configFileExtension )
|
bool Paths::init( const QString& projectDir, const QString& configFileExtension )
|
||||||
{
|
{
|
||||||
m_projectName = projectDir.isEmpty() ? m_currentExecutable.m_canonicalFilePath.fileName()
|
m_projectName = projectDir.isEmpty() ? m_currentExecutable.m_canonicalFilePath.fileName()
|
||||||
: projectDir;
|
: projectDir;
|
||||||
@ -214,7 +214,7 @@ MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& config
|
|||||||
} // Paths::updatePaths
|
} // Paths::updatePaths
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool Paths::makeDefaultDirectories()
|
bool Paths::makeDefaultDirectories()
|
||||||
{
|
{
|
||||||
bool status = true;
|
bool status = true;
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ MYXLIB_INLINE bool Paths::makeDefaultDirectories()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE QString Paths::findConfigFile( const QString& defaultConfigFile )
|
QString Paths::findConfigFile( const QString& defaultConfigFile )
|
||||||
{
|
{
|
||||||
if ( !defaultConfigFile.isEmpty() && QFileInfo( defaultConfigFile ).isReadable() )
|
if ( !defaultConfigFile.isEmpty() && QFileInfo( defaultConfigFile ).isReadable() )
|
||||||
{
|
{
|
||||||
@ -251,103 +251,103 @@ MYXLIB_INLINE QString Paths::findConfigFile( const QString& defaultConfigFile )
|
|||||||
} // Paths::findConfigFile
|
} // Paths::findConfigFile
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE QDir Paths::executableFileDirectory() const
|
QDir Paths::executableFileDirectory() const
|
||||||
{
|
{
|
||||||
return( m_currentExecutable.m_canonicalFilePath.dir() );
|
return( m_currentExecutable.m_canonicalFilePath.dir() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QDir& Paths::userConfigDirectory() const
|
const QDir& Paths::userConfigDirectory() const
|
||||||
{
|
{
|
||||||
return( m_userConfigDirectory );
|
return( m_userConfigDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QDir& Paths::systemConfigDirectory() const
|
const QDir& Paths::systemConfigDirectory() const
|
||||||
{
|
{
|
||||||
return( m_systemConfigDirectory );
|
return( m_systemConfigDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QFileInfo& Paths::configFilePath() const
|
const QFileInfo& Paths::configFilePath() const
|
||||||
{
|
{
|
||||||
return( m_configFilePath );
|
return( m_configFilePath );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QString& Paths::configFileName() const
|
const QString& Paths::configFileName() const
|
||||||
{
|
{
|
||||||
return( m_configFileName );
|
return( m_configFileName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QString& Paths::configFileExtension() const
|
const QString& Paths::configFileExtension() const
|
||||||
{
|
{
|
||||||
return( m_configFileExtension );
|
return( m_configFileExtension );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QDir& Paths::userVarDataDirectory() const
|
const QDir& Paths::userVarDataDirectory() const
|
||||||
{
|
{
|
||||||
return( m_userVarDataDirectory );
|
return( m_userVarDataDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QDir& Paths::systemVarDataDirectory() const
|
const QDir& Paths::systemVarDataDirectory() const
|
||||||
{
|
{
|
||||||
return( m_systemVarDataDirectory );
|
return( m_systemVarDataDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QDir& Paths::userConstDataDirectory() const
|
const QDir& Paths::userConstDataDirectory() const
|
||||||
{
|
{
|
||||||
return( m_userConstDataDirectory );
|
return( m_userConstDataDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QDir& Paths::systemConstDataDirectory() const
|
const QDir& Paths::systemConstDataDirectory() const
|
||||||
{
|
{
|
||||||
return( m_systemConstDataDirectory );
|
return( m_systemConstDataDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QDir& Paths::userLogDirectory() const
|
const QDir& Paths::userLogDirectory() const
|
||||||
{
|
{
|
||||||
return( m_userLogDirectory );
|
return( m_userLogDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QDir& Paths::systemLogDirectory() const
|
const QDir& Paths::systemLogDirectory() const
|
||||||
{
|
{
|
||||||
return( m_systemLogDirectory );
|
return( m_systemLogDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QDir& Paths::tempDirectory() const
|
const QDir& Paths::tempDirectory() const
|
||||||
{
|
{
|
||||||
return( m_tempDirectory );
|
return( m_tempDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QDir& Paths::homeDirectory() const
|
const QDir& Paths::homeDirectory() const
|
||||||
{
|
{
|
||||||
return( m_homeDirectory );
|
return( m_homeDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QString& Paths::projectName() const
|
const QString& Paths::projectName() const
|
||||||
{
|
{
|
||||||
return( m_projectName );
|
return( m_projectName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE QString Paths::executableFileName() const
|
QString Paths::executableFileName() const
|
||||||
{
|
{
|
||||||
return( m_currentExecutable.m_canonicalFilePath.fileName() );
|
return( m_currentExecutable.m_canonicalFilePath.fileName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QFileInfo& Paths::executableFilePath() const
|
const QFileInfo& Paths::executableFilePath() const
|
||||||
{
|
{
|
||||||
return( m_currentExecutable.m_canonicalFilePath );
|
return( m_currentExecutable.m_canonicalFilePath );
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,2 @@
|
|||||||
#ifndef MYXLIB_BUILD_LIBRARIES
|
#include <myx/filesystem/paths.hpp>
|
||||||
#error Define MYXLIB_BUILD_LIBRARIES to compile this file.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/filesystem/paths-inl.hpp>
|
#include <myx/filesystem/paths-inl.hpp>
|
||||||
|
@ -19,9 +19,9 @@ namespace myx {
|
|||||||
|
|
||||||
namespace filesystem {
|
namespace filesystem {
|
||||||
|
|
||||||
MYXLIB_INLINE PathsMT::PathsMT() = default;
|
PathsMT::PathsMT() = default;
|
||||||
|
|
||||||
MYXLIB_INLINE PathsMT& PathsMT::instance()
|
PathsMT& PathsMT::instance()
|
||||||
{
|
{
|
||||||
volatile PathsMT* localInstance = mInstance.load( std::memory_order_acquire );
|
volatile PathsMT* localInstance = mInstance.load( std::memory_order_acquire );
|
||||||
if ( localInstance == nullptr )
|
if ( localInstance == nullptr )
|
||||||
|
@ -1,5 +1,2 @@
|
|||||||
#ifndef MYXLIB_BUILD_LIBRARIES
|
#include <myx/filesystem/paths_mt.hpp>
|
||||||
#error Define MYXLIB_BUILD_LIBRARIES to compile this file.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/filesystem/paths_mt-inl.hpp>
|
#include <myx/filesystem/paths_mt-inl.hpp>
|
||||||
|
@ -3,7 +3,7 @@ set(TRGT math)
|
|||||||
|
|
||||||
# cmake-format: off
|
# cmake-format: off
|
||||||
# Список файлов исходных текстов
|
# Список файлов исходных текстов
|
||||||
set(TRGT_cpp
|
set(TRGT_sources
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative_and_abs.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative_and_abs.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps.cpp
|
||||||
@ -14,15 +14,10 @@ set(TRGT_cpp
|
|||||||
set(TRGT_hpp
|
set(TRGT_hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/all.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/all.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative-inl.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative_and_abs.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative_and_abs.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative_and_abs-inl.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps-inl.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps_and_abs.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps_and_abs.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps_and_abs-inl.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/constants.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/constants.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/constants-inl.hpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/float_cmp_types.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/float_cmp_types.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/functions.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/functions.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/radar.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/radar.hpp
|
||||||
@ -32,14 +27,13 @@ set(TRGT_headers ${TRGT_hpp})
|
|||||||
# cmake-format: on
|
# cmake-format: on
|
||||||
|
|
||||||
add_library(${TRGT}-header-only INTERFACE)
|
add_library(${TRGT}-header-only INTERFACE)
|
||||||
target_sources(${TRGT}-header-only INTERFACE ${TRGT_headers})
|
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
${TRGT}-header-only SYSTEM INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
${TRGT}-header-only SYSTEM INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
||||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||||
|
|
||||||
if(MYXLIB_BUILD_LIBRARIES)
|
if(MYXLIB_BUILD_LIBRARIES)
|
||||||
|
|
||||||
add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers})
|
add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_sources} ${TRGT_headers})
|
||||||
common_target_properties(${TRGT})
|
common_target_properties(${TRGT})
|
||||||
|
|
||||||
# Создание цели для проверки утилитой clang-tidy
|
# Создание цели для проверки утилитой clang-tidy
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
#ifndef MYX_MATH_ALL_HPP_
|
|
||||||
#define MYX_MATH_ALL_HPP_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <myx/math/almost_equal_relative.hpp>
|
#include <myx/math/almost_equal_relative.hpp>
|
||||||
#include <myx/math/almost_equal_relative_and_abs.hpp>
|
#include <myx/math/almost_equal_relative_and_abs.hpp>
|
||||||
#include <myx/math/almost_equal_ulps.hpp>
|
#include <myx/math/almost_equal_ulps.hpp>
|
||||||
@ -11,5 +6,3 @@
|
|||||||
#include <myx/math/functions.hpp>
|
#include <myx/math/functions.hpp>
|
||||||
#include <myx/math/radar.hpp>
|
#include <myx/math/radar.hpp>
|
||||||
#include <myx/math/units.hpp>
|
#include <myx/math/units.hpp>
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
#ifndef MYX_MATH_ALMOST_EQUAL_RELATIVE_INL_HPP_
|
|
||||||
#define MYX_MATH_ALMOST_EQUAL_RELATIVE_INL_HPP_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef MYXLIB_HEADER_ONLY
|
|
||||||
#include <myx/math/almost_equal_relative.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace myx {
|
|
||||||
|
|
||||||
namespace math {
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool almost_equal_relative( const float a, const float b,
|
|
||||||
const float maxRelDiff )
|
|
||||||
{
|
|
||||||
float diff = fabsf( a - b );
|
|
||||||
float aN = fabsf( a );
|
|
||||||
float bN = fabsf( b );
|
|
||||||
float largest = ( bN > aN ) ? bN : aN;
|
|
||||||
|
|
||||||
if ( diff <= largest * maxRelDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
return( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool almost_equal_relative( const double a, const double b,
|
|
||||||
const double maxRelDiff )
|
|
||||||
{
|
|
||||||
double diff = fabs( a - b );
|
|
||||||
double aN = fabs( a );
|
|
||||||
double bN = fabs( b );
|
|
||||||
double largest = ( bN > aN ) ? bN : aN;
|
|
||||||
|
|
||||||
if ( diff <= largest * maxRelDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
return( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace math
|
|
||||||
|
|
||||||
} // namespace myx
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,42 @@
|
|||||||
#ifndef MYXLIB_BUILD_LIBRARIES
|
#include <myx/math/almost_equal_relative.hpp>
|
||||||
#error Define MYXLIB_BUILD_LIBRARIES to compile this file.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/math/almost_equal_relative-inl.hpp>
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
bool almost_equal_relative( const float a, const float b,
|
||||||
|
const float maxRelDiff )
|
||||||
|
{
|
||||||
|
float diff = fabsf( a - b );
|
||||||
|
float aN = fabsf( a );
|
||||||
|
float bN = fabsf( b );
|
||||||
|
float largest = ( bN > aN ) ? bN : aN;
|
||||||
|
|
||||||
|
if ( diff <= largest * maxRelDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
return( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool almost_equal_relative( const double a, const double b,
|
||||||
|
const double maxRelDiff )
|
||||||
|
{
|
||||||
|
double diff = fabs( a - b );
|
||||||
|
double aN = fabs( a );
|
||||||
|
double bN = fabs( b );
|
||||||
|
double largest = ( bN > aN ) ? bN : aN;
|
||||||
|
|
||||||
|
if ( diff <= largest * maxRelDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
return( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
#ifndef MYX_MATH_ALMOST_EQUAL_RELATIVE_HPP_
|
#ifndef MYX_MATH_ALMOST_EQUAL_RELATIVE_HPP_
|
||||||
#define MYX_MATH_ALMOST_EQUAL_RELATIVE_HPP_
|
#define MYX_MATH_ALMOST_EQUAL_RELATIVE_HPP_
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <myx/base/config.hpp>
|
|
||||||
|
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
|
||||||
// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
||||||
@ -32,8 +28,4 @@ bool almost_equal_relative( double a, double b,
|
|||||||
|
|
||||||
} // namespace myx
|
} // namespace myx
|
||||||
|
|
||||||
#ifdef MYXLIB_HEADER_ONLY
|
|
||||||
#include "almost_equal_relative-inl.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // MYX_MATH_ALMOST_EQUAL_RELATIVE_HPP_
|
#endif // MYX_MATH_ALMOST_EQUAL_RELATIVE_HPP_
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
#ifndef MYX_MATH_ALMOST_EQUAL_RELATIVE_AND_ABS_INL_HPP_
|
|
||||||
#define MYX_MATH_ALMOST_EQUAL_RELATIVE_AND_ABS_INL_HPP_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef MYXLIB_HEADER_ONLY
|
|
||||||
#include <myx/math/almost_equal_relative_and_abs.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace myx {
|
|
||||||
|
|
||||||
namespace math {
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool almost_equal_relative_and_abs( const float a, const float b,
|
|
||||||
const float maxAbsDiff, const float maxRelDiff )
|
|
||||||
{
|
|
||||||
// Check if the numbers are really close -- needed
|
|
||||||
// when comparing numbers near zero.
|
|
||||||
float diff = fabsf( a - b );
|
|
||||||
if ( diff <= maxAbsDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
float aN = fabsf( a );
|
|
||||||
float bN = fabsf( b );
|
|
||||||
float largest = ( bN > aN ) ? bN : aN;
|
|
||||||
|
|
||||||
if ( diff <= largest * maxRelDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
return( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool almost_equal_relative_and_abs( const double a, const double b,
|
|
||||||
const double maxAbsDiff, const double maxRelDiff )
|
|
||||||
{
|
|
||||||
// Check if the numbers are really close -- needed
|
|
||||||
// when comparing numbers near zero.
|
|
||||||
double diff = fabs( a - b );
|
|
||||||
if ( diff <= maxAbsDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
double aN = fabs( a );
|
|
||||||
double bN = fabs( b );
|
|
||||||
double largest = ( bN > aN ) ? bN : aN;
|
|
||||||
|
|
||||||
if ( diff <= largest * maxRelDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
return( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace math
|
|
||||||
|
|
||||||
} // namespace myx
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,56 @@
|
|||||||
#ifndef MYXLIB_BUILD_LIBRARIES
|
#include <myx/math/almost_equal_relative_and_abs.hpp>
|
||||||
#error Define MYXLIB_BUILD_LIBRARIES to compile this file.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/math/almost_equal_relative_and_abs-inl.hpp>
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
bool almost_equal_relative_and_abs( const float a, const float b,
|
||||||
|
const float maxAbsDiff, const float maxRelDiff )
|
||||||
|
{
|
||||||
|
// Check if the numbers are really close -- needed
|
||||||
|
// when comparing numbers near zero.
|
||||||
|
float diff = fabsf( a - b );
|
||||||
|
if ( diff <= maxAbsDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
float aN = fabsf( a );
|
||||||
|
float bN = fabsf( b );
|
||||||
|
float largest = ( bN > aN ) ? bN : aN;
|
||||||
|
|
||||||
|
if ( diff <= largest * maxRelDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
return( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool almost_equal_relative_and_abs( const double a, const double b,
|
||||||
|
const double maxAbsDiff, const double maxRelDiff )
|
||||||
|
{
|
||||||
|
// Check if the numbers are really close -- needed
|
||||||
|
// when comparing numbers near zero.
|
||||||
|
double diff = fabs( a - b );
|
||||||
|
if ( diff <= maxAbsDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
double aN = fabs( a );
|
||||||
|
double bN = fabs( b );
|
||||||
|
double largest = ( bN > aN ) ? bN : aN;
|
||||||
|
|
||||||
|
if ( diff <= largest * maxRelDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
return( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
#ifndef MYX_MATH_ALMOST_EQUAL_RELATIVE_AND_ABS_HPP_
|
#ifndef MYX_MATH_ALMOST_EQUAL_RELATIVE_AND_ABS_HPP_
|
||||||
#define MYX_MATH_ALMOST_EQUAL_RELATIVE_AND_ABS_HPP_
|
#define MYX_MATH_ALMOST_EQUAL_RELATIVE_AND_ABS_HPP_
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <myx/base/config.hpp>
|
|
||||||
|
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
|
||||||
namespace myx {
|
namespace myx {
|
||||||
@ -32,8 +28,4 @@ bool almost_equal_relative_and_abs( double a, double b,
|
|||||||
|
|
||||||
} // namespace myx
|
} // namespace myx
|
||||||
|
|
||||||
#ifdef MYXLIB_HEADER_ONLY
|
|
||||||
#include "almost_equal_relative_and_abs-inl.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // MYX_MATH_ALMOST_EQUAL_RELATIVE_AND_ABS_HPP_
|
#endif // MYX_MATH_ALMOST_EQUAL_RELATIVE_AND_ABS_HPP_
|
||||||
|
@ -1,93 +0,0 @@
|
|||||||
#ifndef MYX_MATH_ALMOST_EQUAL_ULPS_INL_HPP_
|
|
||||||
#define MYX_MATH_ALMOST_EQUAL_ULPS_INL_HPP_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef MYXLIB_HEADER_ONLY
|
|
||||||
#include <myx/math/almost_equal_ulps.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/math/float_cmp_types.hpp>
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace myx {
|
|
||||||
|
|
||||||
namespace math {
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool almost_equal_ulps( const float a, const float b,
|
|
||||||
const int maxUlpsDiff )
|
|
||||||
{
|
|
||||||
FloatCmp uA( a );
|
|
||||||
FloatCmp uB( b );
|
|
||||||
|
|
||||||
// Если знаки разные, то числа не равны.
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
|
||||||
if ( uA.negative() != uB.negative() )
|
|
||||||
{
|
|
||||||
// Кроме случая, когда +0==-0
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
|
||||||
#endif
|
|
||||||
if ( a == b ) // -V550
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
return( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Разница в младших битах.
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
|
||||||
auto ulpsDiff = std::abs( uA.i - uB.i );
|
|
||||||
if ( ulpsDiff <= maxUlpsDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
return( false );
|
|
||||||
} // almost_equal_ulps
|
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool almost_equal_ulps( const double a, const double b,
|
|
||||||
const int maxUlpsDiff )
|
|
||||||
{
|
|
||||||
DoubleCmp uA( a );
|
|
||||||
DoubleCmp uB( b );
|
|
||||||
|
|
||||||
// Если знаки разные, то числа не равны.
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
|
||||||
if ( uA.negative() != uB.negative() )
|
|
||||||
{
|
|
||||||
// Кроме случая, когда +0==-0
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
|
||||||
#endif
|
|
||||||
if ( a == b ) // -V550
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
return( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Разница в младших битах.
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
|
||||||
auto ulpsDiff = std::abs( uA.i - uB.i );
|
|
||||||
if ( ulpsDiff <= maxUlpsDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
return( false );
|
|
||||||
} // almost_equal_ulps
|
|
||||||
|
|
||||||
} // namespace math
|
|
||||||
|
|
||||||
} // namespace myx
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,83 @@
|
|||||||
#ifndef MYXLIB_BUILD_LIBRARIES
|
#include <myx/math/almost_equal_ulps.hpp>
|
||||||
#error Define MYXLIB_BUILD_LIBRARIES to compile this file.
|
#include <myx/math/float_cmp_types.hpp>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/math/almost_equal_ulps-inl.hpp>
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
bool almost_equal_ulps( const float a, const float b,
|
||||||
|
const int maxUlpsDiff )
|
||||||
|
{
|
||||||
|
FloatCmp uA( a );
|
||||||
|
FloatCmp uB( b );
|
||||||
|
|
||||||
|
// Если знаки разные, то числа не равны.
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||||
|
if ( uA.negative() != uB.negative() )
|
||||||
|
{
|
||||||
|
// Кроме случая, когда +0==-0
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
||||||
|
#endif
|
||||||
|
if ( a == b ) // -V550
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
return( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Разница в младших битах.
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||||
|
auto ulpsDiff = std::abs( uA.i - uB.i );
|
||||||
|
if ( ulpsDiff <= maxUlpsDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
return( false );
|
||||||
|
} // almost_equal_ulps
|
||||||
|
|
||||||
|
|
||||||
|
bool almost_equal_ulps( const double a, const double b,
|
||||||
|
const int maxUlpsDiff )
|
||||||
|
{
|
||||||
|
DoubleCmp uA( a );
|
||||||
|
DoubleCmp uB( b );
|
||||||
|
|
||||||
|
// Если знаки разные, то числа не равны.
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||||
|
if ( uA.negative() != uB.negative() )
|
||||||
|
{
|
||||||
|
// Кроме случая, когда +0==-0
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
||||||
|
#endif
|
||||||
|
if ( a == b ) // -V550
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
return( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Разница в младших битах.
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||||
|
auto ulpsDiff = std::abs( uA.i - uB.i );
|
||||||
|
if ( ulpsDiff <= maxUlpsDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
return( false );
|
||||||
|
} // almost_equal_ulps
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
#ifndef MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
#ifndef MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
||||||
#define MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
#define MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <myx/base/config.hpp>
|
|
||||||
#include <myx/math/float_cmp_types.hpp>
|
#include <myx/math/float_cmp_types.hpp>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@ -31,8 +28,4 @@ bool almost_equal_ulps( double a, double b,
|
|||||||
|
|
||||||
} // namespace myx
|
} // namespace myx
|
||||||
|
|
||||||
#ifdef MYXLIB_HEADER_ONLY
|
|
||||||
#include "almost_equal_ulps-inl.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
#endif // MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
||||||
|
@ -1,87 +0,0 @@
|
|||||||
#ifndef MYX_MATH_ALMOST_EQUAL_ULPS_INL_HPP_
|
|
||||||
#define MYX_MATH_ALMOST_EQUAL_ULPS_INL_HPP_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef MYXLIB_HEADER_ONLY
|
|
||||||
#include <myx/math/almost_equal_ulps_and_abs.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/math/float_cmp_types.hpp>
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace myx {
|
|
||||||
|
|
||||||
namespace math {
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool almost_equal_ulps_and_abs( const float a, const float b,
|
|
||||||
const float maxAbsDiff, const int maxUlpsDiff )
|
|
||||||
{
|
|
||||||
// Check if the numbers are really close -- needed
|
|
||||||
// when comparing numbers near zero.
|
|
||||||
float absDiff = fabsf( a - b );
|
|
||||||
if ( absDiff <= maxAbsDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
FloatCmp uA( a );
|
|
||||||
FloatCmp uB( b );
|
|
||||||
|
|
||||||
// Different signs means they do not match.
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
|
||||||
if ( uA.negative() != uB.negative() )
|
|
||||||
{
|
|
||||||
return( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the difference in ULPs.
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
|
||||||
int ulpsDiff = std::abs( uA.i - uB.i );
|
|
||||||
if ( ulpsDiff <= maxUlpsDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
return( false );
|
|
||||||
} // almost_equal_ulps_and_abs
|
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool almost_equal_ulps_and_abs( const double a, const double b,
|
|
||||||
const double maxAbsDiff, const int maxUlpsDiff )
|
|
||||||
{
|
|
||||||
// Check if the numbers are really close -- needed
|
|
||||||
// when comparing numbers near zero.
|
|
||||||
double absDiff = fabs( a - b );
|
|
||||||
if ( absDiff <= maxAbsDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
DoubleCmp uA( a );
|
|
||||||
DoubleCmp uB( b );
|
|
||||||
|
|
||||||
// Different signs means they do not match.
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
|
||||||
if ( uA.negative() != uB.negative() )
|
|
||||||
{
|
|
||||||
return( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the difference in ULPs.
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
|
||||||
auto ulpsDiff = std::abs( uA.i - uB.i );
|
|
||||||
if ( ulpsDiff <= maxUlpsDiff )
|
|
||||||
{
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
return( false );
|
|
||||||
} // almost_equal_ulps_and_abs
|
|
||||||
|
|
||||||
} // namespace math
|
|
||||||
|
|
||||||
} // namespace myx
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,77 @@
|
|||||||
#ifndef MYXLIB_BUILD_LIBRARIES
|
#include <myx/math/almost_equal_ulps_and_abs.hpp>
|
||||||
#error Define MYXLIB_BUILD_LIBRARIES to compile this file.
|
#include <myx/math/float_cmp_types.hpp>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/math/almost_equal_ulps_and_abs-inl.hpp>
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
bool almost_equal_ulps_and_abs( const float a, const float b,
|
||||||
|
const float maxAbsDiff, const int maxUlpsDiff )
|
||||||
|
{
|
||||||
|
// Check if the numbers are really close -- needed
|
||||||
|
// when comparing numbers near zero.
|
||||||
|
float absDiff = fabsf( a - b );
|
||||||
|
if ( absDiff <= maxAbsDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
FloatCmp uA( a );
|
||||||
|
FloatCmp uB( b );
|
||||||
|
|
||||||
|
// Different signs means they do not match.
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||||
|
if ( uA.negative() != uB.negative() )
|
||||||
|
{
|
||||||
|
return( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the difference in ULPs.
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||||
|
int ulpsDiff = std::abs( uA.i - uB.i );
|
||||||
|
if ( ulpsDiff <= maxUlpsDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
return( false );
|
||||||
|
} // almost_equal_ulps_and_abs
|
||||||
|
|
||||||
|
|
||||||
|
bool almost_equal_ulps_and_abs( const double a, const double b,
|
||||||
|
const double maxAbsDiff, const int maxUlpsDiff )
|
||||||
|
{
|
||||||
|
// Check if the numbers are really close -- needed
|
||||||
|
// when comparing numbers near zero.
|
||||||
|
double absDiff = fabs( a - b );
|
||||||
|
if ( absDiff <= maxAbsDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
DoubleCmp uA( a );
|
||||||
|
DoubleCmp uB( b );
|
||||||
|
|
||||||
|
// Different signs means they do not match.
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||||
|
if ( uA.negative() != uB.negative() )
|
||||||
|
{
|
||||||
|
return( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the difference in ULPs.
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||||
|
auto ulpsDiff = std::abs( uA.i - uB.i );
|
||||||
|
if ( ulpsDiff <= maxUlpsDiff )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
return( false );
|
||||||
|
} // almost_equal_ulps_and_abs
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
#ifndef MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
#ifndef MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
||||||
#define MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
#define MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <myx/base/config.hpp>
|
|
||||||
|
|
||||||
namespace myx {
|
namespace myx {
|
||||||
|
|
||||||
namespace math {
|
namespace math {
|
||||||
@ -30,8 +26,4 @@ bool almost_equal_ulps_and_abs( double a, double b,
|
|||||||
|
|
||||||
} // namespace myx
|
} // namespace myx
|
||||||
|
|
||||||
#ifdef MYXLIB_HEADER_ONLY
|
|
||||||
#include "almost_equal_ulps_and_abs-inl.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
#endif // MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
#ifndef MYX_MATH_CONSTANTS_INL_HPP_
|
|
||||||
#define MYX_MATH_CONSTANTS_INL_HPP_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef MYXLIB_HEADER_ONLY
|
|
||||||
#include <myx/math/constants.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace myx {
|
|
||||||
|
|
||||||
namespace math {
|
|
||||||
|
|
||||||
} // namespace math
|
|
||||||
|
|
||||||
} // namespace myx
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,9 @@
|
|||||||
#ifndef MYXLIB_BUILD_LIBRARIES
|
#include <myx/math/constants.hpp>
|
||||||
#error Define MYXLIB_BUILD_LIBRARIES to compile this file.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/math/constants-inl.hpp>
|
namespace myx {
|
||||||
|
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
#ifndef MYX_MATH_CONSTANTS_HPP_
|
#ifndef MYX_MATH_CONSTANTS_HPP_
|
||||||
#define MYX_MATH_CONSTANTS_HPP_
|
#define MYX_MATH_CONSTANTS_HPP_
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <myx/base/config.hpp>
|
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
@ -12,14 +8,11 @@ namespace myx {
|
|||||||
|
|
||||||
namespace math {
|
namespace math {
|
||||||
|
|
||||||
const auto ImpedanceOfFreeSpace = (M_PI * 119.9169832);
|
const auto ImpedanceOfFreeSpace = 376.7303136675757;
|
||||||
|
|
||||||
} // namespace math
|
} // namespace math
|
||||||
|
|
||||||
} // namespace myx
|
} // namespace myx
|
||||||
|
|
||||||
#ifdef MYXLIB_HEADER_ONLY
|
|
||||||
#include "constants-inl.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // MYX_MATH_CONSTANTS_HPP_
|
#endif // MYX_MATH_CONSTANTS_HPP_
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef MYX_MATH_FLOAT_CMP_TYPES_HPP_
|
#ifndef MYX_MATH_FLOAT_CMP_TYPES_HPP_
|
||||||
#define MYX_MATH_FLOAT_CMP_TYPES_HPP_
|
#define MYX_MATH_FLOAT_CMP_TYPES_HPP_
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef MYX_MATH_FUNCTIONS_HPP_
|
#ifndef MYX_MATH_FUNCTIONS_HPP_
|
||||||
#define MYX_MATH_FUNCTIONS_HPP_
|
#define MYX_MATH_FUNCTIONS_HPP_
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <boost/math/special_functions/pow.hpp>
|
#include <boost/math/special_functions/pow.hpp>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef MYX_MATH_RADAR_HPP_
|
#ifndef MYX_MATH_RADAR_HPP_
|
||||||
#define MYX_MATH_RADAR_HPP_
|
#define MYX_MATH_RADAR_HPP_
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef MYX_MATH_UNITS_HPP_
|
#ifndef MYX_MATH_UNITS_HPP_
|
||||||
#define MYX_MATH_UNITS_HPP_
|
#define MYX_MATH_UNITS_HPP_
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
@ -90,4 +88,5 @@ T magnitude_to_decibel( T const& magnitude )
|
|||||||
|
|
||||||
} // namespace myx
|
} // namespace myx
|
||||||
|
|
||||||
|
|
||||||
#endif // MYX_MATH_UNITS_HPP_
|
#endif // MYX_MATH_UNITS_HPP_
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef MYX_QT_BACKPORTS_HPP_
|
#ifndef MYX_QT_BACKPORTS_HPP_
|
||||||
#define MYX_QT_BACKPORTS_HPP_
|
#define MYX_QT_BACKPORTS_HPP_
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#if ( defined ( TARGET_LSB_ID_AstraLinuxSE ) && defined ( TARGET_LSB_CODENAME_smolensk ) )
|
#if ( defined ( TARGET_LSB_ID_AstraLinuxSE ) && defined ( TARGET_LSB_CODENAME_smolensk ) )
|
||||||
|
|
||||||
#define override
|
#define override
|
||||||
|
@ -17,7 +17,7 @@ namespace myx {
|
|||||||
|
|
||||||
namespace qt {
|
namespace qt {
|
||||||
|
|
||||||
MYXLIB_INLINE void append_translators( QTranslatorsList& translators, const QString& appName )
|
void append_translators( QTranslatorsList& translators, const QString& appName )
|
||||||
{
|
{
|
||||||
auto* translator = new QTranslator( qApp );
|
auto* translator = new QTranslator( qApp );
|
||||||
|
|
||||||
|
@ -1,5 +1,2 @@
|
|||||||
#ifndef MYXLIB_BUILD_LIBRARIES
|
|
||||||
#error Define MYXLIB_BUILD_LIBRARIES to compile this file.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/qt/translators.hpp>
|
#include <myx/qt/translators.hpp>
|
||||||
|
#include <myx/qt/translators-inl.hpp>
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#ifndef MYX_QT_TRANSLATORS_HPP_
|
#ifndef MYX_LOG_QT_TRANSLATORS_HPP_
|
||||||
#define MYX_QT_TRANSLATORS_HPP_
|
#define MYX_LOG_QT_TRANSLATORS_HPP_
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <myx/base/config.hpp>
|
#include <myx/base/config.hpp>
|
||||||
#include <myx/qt/backports.hpp>
|
#include <myx/qt/backports.hpp>
|
||||||
@ -24,4 +22,4 @@ void append_translators( QTranslatorsList& translators, const QString& appName )
|
|||||||
#include "translators-inl.hpp"
|
#include "translators-inl.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // ifndef MYX_QT_TRANSLATORS_HPP_
|
#endif // ifndef MYX_LOG_QT_TRANSLATORS_HPP_
|
||||||
|
Loading…
Reference in New Issue
Block a user