1/*******************************************************************************
2 Copyright (c) The Taichi Authors (2016- ). All Rights Reserved.
3 The use of this software is governed by the LICENSE file.
4*******************************************************************************/
5
6#pragma once
7
8#include "taichi/common/core.h"
9#include "geometry_util.h"
10#include "array.h"
11#include "linalg.h"
12
13namespace taichi {
14
15namespace math {
16template <typename T>
17TI_FORCE_INLINE T degrees(T rad) {
18 return rad * (type::element<T>(180) / pi);
19}
20
21template <typename T>
22TI_FORCE_INLINE T radians(T deg) {
23 return deg * (pi / type::element<T>(180));
24}
25
26template <typename T>
27TI_FORCE_INLINE
28 typename std::enable_if_t<!std::is_floating_point<T>::value, bool>
29 equal(const T &A, const T &B, float64 tolerance) {
30 return maximum(abs(A - B)) <= tolerance;
31}
32
33template <typename T>
34TI_FORCE_INLINE
35 typename std::enable_if_t<std::is_floating_point<T>::value, bool>
36 equal(const T &A, const T &B, float64 tolerance) {
37 return std::abs(A - B) <= tolerance;
38}
39
40} // namespace math
41
42} // namespace taichi
43