2 * Copyright 2016 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 * Most platforms hopefully provide std::nextafter.
29 /* using override */ using std::nextafter;
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
40 #if defined(__GNUC__) && !defined(__clang__)
42 constexpr float nextafter(float x, float y) {
43 return __builtin_nextafterf(x, y);
46 constexpr double nextafter(double x, double y) {
47 return __builtin_nextafter(x, y);
50 constexpr long double nextafter(long double x, long double y) {
51 return __builtin_nextafterl(x, y);
56 inline float nextafter(float x, float y) {
57 return ::nextafterf(x, y);
60 inline double nextafter(double x, double y) {
61 return ::nextafter(x, y);
64 inline long double nextafter(long double x, long double y) {
65 return ::nextafterl(x, y);