2021-05-20 10:49:33 +00:00
|
|
|
// Copyright 2009-2021 Intel Corporation
|
2020-12-19 13:50:20 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../sys/platform.h"
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
#define _USE_MATH_DEFINES
|
|
|
|
#include <math.h> // using cmath causes issues under Windows
|
|
|
|
#include <cfloat>
|
|
|
|
#include <climits>
|
|
|
|
|
|
|
|
namespace embree
|
|
|
|
{
|
|
|
|
static MAYBE_UNUSED const float one_over_255 = 1.0f/255.0f;
|
|
|
|
static MAYBE_UNUSED const float min_rcp_input = 1E-18f; // for abs(x) >= min_rcp_input the newton raphson rcp calculation does not fail
|
|
|
|
|
|
|
|
/* we consider floating point numbers in that range as valid input numbers */
|
|
|
|
static MAYBE_UNUSED float FLT_LARGE = 1.844E18f;
|
|
|
|
|
|
|
|
struct TrueTy {
|
|
|
|
__forceinline operator bool( ) const { return true; }
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr TrueTy True = TrueTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct FalseTy {
|
|
|
|
__forceinline operator bool( ) const { return false; }
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr FalseTy False = FalseTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct ZeroTy
|
|
|
|
{
|
|
|
|
__forceinline operator double ( ) const { return 0; }
|
|
|
|
__forceinline operator float ( ) const { return 0; }
|
|
|
|
__forceinline operator long long( ) const { return 0; }
|
|
|
|
__forceinline operator unsigned long long( ) const { return 0; }
|
|
|
|
__forceinline operator long ( ) const { return 0; }
|
|
|
|
__forceinline operator unsigned long ( ) const { return 0; }
|
|
|
|
__forceinline operator int ( ) const { return 0; }
|
|
|
|
__forceinline operator unsigned int ( ) const { return 0; }
|
|
|
|
__forceinline operator short ( ) const { return 0; }
|
|
|
|
__forceinline operator unsigned short ( ) const { return 0; }
|
2021-05-20 10:49:33 +00:00
|
|
|
__forceinline operator char ( ) const { return 0; }
|
|
|
|
__forceinline operator unsigned char ( ) const { return 0; }
|
2020-12-19 13:50:20 +00:00
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr ZeroTy zero = ZeroTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct OneTy
|
|
|
|
{
|
|
|
|
__forceinline operator double ( ) const { return 1; }
|
|
|
|
__forceinline operator float ( ) const { return 1; }
|
|
|
|
__forceinline operator long long( ) const { return 1; }
|
|
|
|
__forceinline operator unsigned long long( ) const { return 1; }
|
|
|
|
__forceinline operator long ( ) const { return 1; }
|
|
|
|
__forceinline operator unsigned long ( ) const { return 1; }
|
|
|
|
__forceinline operator int ( ) const { return 1; }
|
|
|
|
__forceinline operator unsigned int ( ) const { return 1; }
|
|
|
|
__forceinline operator short ( ) const { return 1; }
|
|
|
|
__forceinline operator unsigned short ( ) const { return 1; }
|
2021-05-20 10:49:33 +00:00
|
|
|
__forceinline operator char ( ) const { return 1; }
|
|
|
|
__forceinline operator unsigned char ( ) const { return 1; }
|
2020-12-19 13:50:20 +00:00
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr OneTy one = OneTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct NegInfTy
|
|
|
|
{
|
|
|
|
__forceinline operator double ( ) const { return -std::numeric_limits<double>::infinity(); }
|
|
|
|
__forceinline operator float ( ) const { return -std::numeric_limits<float>::infinity(); }
|
|
|
|
__forceinline operator long long( ) const { return std::numeric_limits<long long>::min(); }
|
|
|
|
__forceinline operator unsigned long long( ) const { return std::numeric_limits<unsigned long long>::min(); }
|
|
|
|
__forceinline operator long ( ) const { return std::numeric_limits<long>::min(); }
|
|
|
|
__forceinline operator unsigned long ( ) const { return std::numeric_limits<unsigned long>::min(); }
|
|
|
|
__forceinline operator int ( ) const { return std::numeric_limits<int>::min(); }
|
|
|
|
__forceinline operator unsigned int ( ) const { return std::numeric_limits<unsigned int>::min(); }
|
|
|
|
__forceinline operator short ( ) const { return std::numeric_limits<short>::min(); }
|
|
|
|
__forceinline operator unsigned short ( ) const { return std::numeric_limits<unsigned short>::min(); }
|
2021-05-20 10:49:33 +00:00
|
|
|
__forceinline operator char ( ) const { return std::numeric_limits<char>::min(); }
|
|
|
|
__forceinline operator unsigned char ( ) const { return std::numeric_limits<unsigned char>::min(); }
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr NegInfTy neg_inf = NegInfTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct PosInfTy
|
|
|
|
{
|
|
|
|
__forceinline operator double ( ) const { return std::numeric_limits<double>::infinity(); }
|
|
|
|
__forceinline operator float ( ) const { return std::numeric_limits<float>::infinity(); }
|
|
|
|
__forceinline operator long long( ) const { return std::numeric_limits<long long>::max(); }
|
|
|
|
__forceinline operator unsigned long long( ) const { return std::numeric_limits<unsigned long long>::max(); }
|
|
|
|
__forceinline operator long ( ) const { return std::numeric_limits<long>::max(); }
|
|
|
|
__forceinline operator unsigned long ( ) const { return std::numeric_limits<unsigned long>::max(); }
|
|
|
|
__forceinline operator int ( ) const { return std::numeric_limits<int>::max(); }
|
|
|
|
__forceinline operator unsigned int ( ) const { return std::numeric_limits<unsigned int>::max(); }
|
|
|
|
__forceinline operator short ( ) const { return std::numeric_limits<short>::max(); }
|
|
|
|
__forceinline operator unsigned short ( ) const { return std::numeric_limits<unsigned short>::max(); }
|
2021-05-20 10:49:33 +00:00
|
|
|
__forceinline operator char ( ) const { return std::numeric_limits<char>::max(); }
|
|
|
|
__forceinline operator unsigned char ( ) const { return std::numeric_limits<unsigned char>::max(); }
|
2020-12-19 13:50:20 +00:00
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr PosInfTy inf = PosInfTy();
|
|
|
|
const constexpr PosInfTy pos_inf = PosInfTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct NaNTy
|
|
|
|
{
|
|
|
|
__forceinline operator double( ) const { return std::numeric_limits<double>::quiet_NaN(); }
|
|
|
|
__forceinline operator float ( ) const { return std::numeric_limits<float>::quiet_NaN(); }
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr NaNTy nan = NaNTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct UlpTy
|
|
|
|
{
|
|
|
|
__forceinline operator double( ) const { return std::numeric_limits<double>::epsilon(); }
|
|
|
|
__forceinline operator float ( ) const { return std::numeric_limits<float>::epsilon(); }
|
|
|
|
};
|
2022-11-24 14:45:59 +00:00
|
|
|
|
|
|
|
const constexpr UlpTy ulp = UlpTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct PiTy
|
|
|
|
{
|
|
|
|
__forceinline operator double( ) const { return double(M_PI); }
|
|
|
|
__forceinline operator float ( ) const { return float(M_PI); }
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr PiTy pi = PiTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct OneOverPiTy
|
|
|
|
{
|
|
|
|
__forceinline operator double( ) const { return double(M_1_PI); }
|
|
|
|
__forceinline operator float ( ) const { return float(M_1_PI); }
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr OneOverPiTy one_over_pi = OneOverPiTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct TwoPiTy
|
|
|
|
{
|
|
|
|
__forceinline operator double( ) const { return double(2.0*M_PI); }
|
|
|
|
__forceinline operator float ( ) const { return float(2.0*M_PI); }
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr TwoPiTy two_pi = TwoPiTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct OneOverTwoPiTy
|
|
|
|
{
|
|
|
|
__forceinline operator double( ) const { return double(0.5*M_1_PI); }
|
|
|
|
__forceinline operator float ( ) const { return float(0.5*M_1_PI); }
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr OneOverTwoPiTy one_over_two_pi = OneOverTwoPiTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct FourPiTy
|
|
|
|
{
|
|
|
|
__forceinline operator double( ) const { return double(4.0*M_PI); }
|
|
|
|
__forceinline operator float ( ) const { return float(4.0*M_PI); }
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr FourPiTy four_pi = FourPiTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct OneOverFourPiTy
|
|
|
|
{
|
|
|
|
__forceinline operator double( ) const { return double(0.25*M_1_PI); }
|
|
|
|
__forceinline operator float ( ) const { return float(0.25*M_1_PI); }
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr OneOverFourPiTy one_over_four_pi = OneOverFourPiTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct StepTy {
|
2022-11-24 14:45:59 +00:00
|
|
|
__forceinline operator double ( ) const { return 0; }
|
|
|
|
__forceinline operator float ( ) const { return 0; }
|
|
|
|
__forceinline operator long long( ) const { return 0; }
|
|
|
|
__forceinline operator unsigned long long( ) const { return 0; }
|
|
|
|
__forceinline operator long ( ) const { return 0; }
|
|
|
|
__forceinline operator unsigned long ( ) const { return 0; }
|
|
|
|
__forceinline operator int ( ) const { return 0; }
|
|
|
|
__forceinline operator unsigned int ( ) const { return 0; }
|
|
|
|
__forceinline operator short ( ) const { return 0; }
|
|
|
|
__forceinline operator unsigned short ( ) const { return 0; }
|
|
|
|
__forceinline operator char ( ) const { return 0; }
|
|
|
|
__forceinline operator unsigned char ( ) const { return 0; }
|
2020-12-19 13:50:20 +00:00
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr StepTy step = StepTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct ReverseStepTy {
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr ReverseStepTy reverse_step = ReverseStepTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct EmptyTy {
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr EmptyTy empty = EmptyTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct FullTy {
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr FullTy full = FullTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
|
|
|
|
struct UndefinedTy {
|
|
|
|
};
|
|
|
|
|
2022-11-24 14:45:59 +00:00
|
|
|
const constexpr UndefinedTy undefined = UndefinedTy();
|
2020-12-19 13:50:20 +00:00
|
|
|
}
|