Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1#ifndef _BBM_DRJIT_MATH_H_
2#define _BBM_DRJIT_MATH_H_
3
4#include <cmath>
5
6#include "drjit/math.h"
7
8#include "util/poly.h"
9#include "backbone/vec.h"
10
11/************************************************************************/
12/*! \file math.h
13
14 \brief Connect bbm math functions to the corresponding DrJIT methods.
15
16 Satisfies: concepts::backbone::has_math_functions
17
18*************************************************************************/
19
20namespace backbone {
21
22 /**********************************************************************/
23 /*! @{ \name Map math operations to DrJIT functions
24 **********************************************************************/
25 using drjit::exp;
26 using drjit::log;
27 using drjit::sin;
28 using drjit::asin;
29 using drjit::cos;
30 using drjit::acos;
31 using drjit::tan;
32 using drjit::atan;
33 using drjit::atan2;
34 using drjit::sinh;
35 using drjit::asinh;
36 using drjit::cosh;
37 using drjit::acosh;
38 using drjit::tanh;
39 using drjit::atanh;
40 using drjit::ceil;
41 using drjit::floor;
42 using drjit::round;
43 using drjit::clamp;
44 using drjit::fmod;
45 using drjit::copysign;
46 using drjit::sign;
47 using drjit::lerp;
48 using drjit::abs;
49 using drjit::sqrt;
50 using drjit::cbrt;
51 using drjit::pow;
52 using drjit::safe_sqrt;
53 using drjit::safe_asin;
54 using drjit::safe_acos;
55 using drjit::erf;
56 using drjit::erfinv;
57 using drjit::tgamma;
58 using drjit::lgamma;
59 using drjit::eq;
60 using drjit::neq;
61 using drjit::rcp;
62 using drjit::rsqrt;
63 using drjit::isnan;
64 using drjit::isinf;
65 using drjit::isfinite;
66 //! @}
67
68 // clean up macro
69 #undef BBM_DRJIT_MATHOP
70
71 /********************************************************************/
72 /*! \brief max between two variables
73 ********************************************************************/
74 template<typename T, typename U>
75 inline auto max(T&& t, U&& u)
76 {
77 return drjit::select(t > u, std::forward<T>(t), std::forward<U>(u));
78 }
79
80 /********************************************************************/
81 /*! \brief min between two variables
82 ********************************************************************/
83 template<typename T, typename U>
84 inline auto min(T&& t, U&& u)
85 {
86 return drjit::select(t < u, std::forward<T>(t), std::forward<U>(u));
87 }
88
89 /********************************************************************/
90 /*! \brief erfc
91
92 TODO: make more robust
93 ********************************************************************/
94 template<typename T>
95 inline T erfc(const T& t)
96 {
97 return drjit::scalar_t<T>(1) - drjit::erf(t);
98 }
99
100 /********************************************************************/
101 /*! \brief cossin
102
103 \param a = angle
104 \returns the cos and sin in a vec2d
105 ********************************************************************/
106 template<typename T>
107 vec2d<T> cossin(const T& a)
108 {
109 auto tmp = drjit::sincos(a);
110 return {tmp.second, tmp.first};
111 }
112
113} // end backbone namespace
114
115#endif /* _BBM_DRJIT_MATH_H_ */
Random number generator; built on top of Drjit.
Definition: backbone.h:53
auto min(T &&t, U &&u)
min between two variables
Definition: math.h:84
vec2d< T > cossin(const T &a)
cossin
Definition: math.h:107
drjit::Array< T, 2 > vec2d
Definition: vec.h:13
auto max(T &&t, U &&u)
max between two variables
Definition: math.h:75
T erfc(const T &t)
erfc
Definition: math.h:95
Compile time polynomial using Horner's method.