//===-- Floating point classification functions -----------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_LIBC_UTILS_FPUTIL_CLASSIFICATION_FUNCTIONS_H #define LLVM_LIBC_UTILS_FPUTIL_CLASSIFICATION_FUNCTIONS_H #include "BitPatterns.h" #include "FloatOperations.h" #include "FloatProperties.h" #include "utils/CPP/TypeTraits.h" namespace __llvm_libc { namespace fputil { template static inline bool bitsAreInf(BitsType bits) { using FPType = typename FloatType::Type; return ((bits & BitPatterns::inf) == BitPatterns::inf) && ((bits & FloatProperties::mantissaMask) == 0); } // Return true if x is infinity (positive or negative.) template ::Value, int> = 0> static inline bool isInf(T x) { return bitsAreInf(valueAsBits(x)); } template static inline bool bitsAreNaN(BitsType bits) { using FPType = typename FloatType::Type; return ((bits & BitPatterns::inf) == BitPatterns::inf) && ((bits & FloatProperties::mantissaMask) != 0); } // Return true if x is a NAN (quiet or signalling.) template ::Value, int> = 0> static inline bool isNaN(T x) { return bitsAreNaN(valueAsBits(x)); } template static inline bool bitsAreInfOrNaN(BitsType bits) { using FPType = typename FloatType::Type; return (bits & BitPatterns::inf) == BitPatterns::inf; } template static inline bool bitsAreZero(BitsType bits) { using FPType = typename FloatType::Type; return (bits == BitPatterns::zero) || (bits == BitPatterns::negZero); } // Return true if x is any kind of NaN or infinity. template ::Value, int> = 0> static inline bool isInfOrNaN(T x) { return bitsAreInfOrNaN(valueAsBits(x)); } // Return true if x is a quiet NAN. template ::Value, int> = 0> static inline bool isQuietNaN(T x) { using Properties = FloatProperties; using BitsType = typename FloatProperties::BitsType; BitsType bits = valueAsBits(x); return ((bits & BitPatterns::inf) == BitPatterns::inf) && ((bits & Properties::quietNaNMask) != 0); } // Return true if x is a quiet NAN with sign bit set. template ::Value, int> = 0> static inline bool isNegativeQuietNaN(T x) { using Properties = FloatProperties; using BitsType = typename FloatProperties::BitsType; BitsType bits = valueAsBits(x); return ((bits & BitPatterns::negInf) == BitPatterns::negInf) && ((bits & Properties::quietNaNMask) != 0); } } // namespace fputil } // namespace __llvm_libc #endif // LLVM_LIBC_UTILS_FPUTIL_CLASSIFICATION_FUNCTIONS_H