xref: /aosp_15_r20/external/cronet/base/numerics/angle_conversions.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2024 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_NUMERICS_ANGLE_CONVERSIONS_H_
6 #define BASE_NUMERICS_ANGLE_CONVERSIONS_H_
7 
8 #include <concepts>
9 #include <numbers>
10 
11 namespace base {
12 
13 template <typename T>
14   requires std::floating_point<T>
DegToRad(T deg)15 constexpr T DegToRad(T deg) {
16   return deg * std::numbers::pi_v<T> / 180;
17 }
18 
19 template <typename T>
20   requires std::floating_point<T>
RadToDeg(T rad)21 constexpr T RadToDeg(T rad) {
22   return rad * 180 / std::numbers::pi_v<T>;
23 }
24 
25 }  // namespace base
26 
27 #endif  // BASE_NUMERICS_ANGLE_CONVERSIONS_H_
28