Fix copyright lines
[folly.git] / folly / portability / Math.h
1 /*
2  * Copyright 2016-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <cmath>
20
21 namespace folly {
22
23 #ifndef __ANDROID__
24
25 /**
26  * Most platforms hopefully provide std::nextafter.
27  */
28
29 /* using override */ using std::nextafter;
30
31 #else // !__ANDROID__
32
33 /**
34  * On Android, std::nextafter isn't implemented. However, the C functions and
35  * compiler builtins are still provided. Using the GCC builtin is actually
36  * slightly faster, as they're constexpr and the use cases within folly are in
37  * constexpr context.
38  */
39
40 #if defined(__GNUC__) && !defined(__clang__)
41
42 constexpr float nextafter(float x, float y) {
43   return __builtin_nextafterf(x, y);
44 }
45
46 constexpr double nextafter(double x, double y) {
47   return __builtin_nextafter(x, y);
48 }
49
50 constexpr long double nextafter(long double x, long double y) {
51   return __builtin_nextafterl(x, y);
52 }
53
54 #else // __GNUC__
55
56 inline float nextafter(float x, float y) {
57   return ::nextafterf(x, y);
58 }
59
60 inline double nextafter(double x, double y) {
61   return ::nextafter(x, y);
62 }
63
64 inline long double nextafter(long double x, long double y) {
65   return ::nextafterl(x, y);
66 }
67
68 #endif // __GNUC__
69
70 #endif // __ANDROID__
71 } // namespace folly