Fix fesetround issue when targeting pre-21 Android APIs

PiperOrigin-RevId: 249079196
This commit is contained in:
Jared Duke 2019-05-20 10:43:25 -07:00 committed by TensorFlower Gardener
parent 79ee9071c9
commit 992d22cc3c
2 changed files with 24 additions and 2 deletions

View File

@ -15,11 +15,22 @@ limitations under the License.
#include "tensorflow/core/platform/setround.h"
#include <cfenv> // NOLINT
#include "tensorflow/core/platform/logging.h"
namespace tensorflow {
namespace port {
#if defined(TF_BROKEN_CFENV)
ScopedSetRound::ScopedSetRound(const int mode) : original_mode_(mode) {
// If cfenv usage is broken, assume support only for TONEAREST.
DCHECK_EQ(mode, FE_TONEAREST);
}
ScopedSetRound::~ScopedSetRound() {}
#else
ScopedSetRound::ScopedSetRound(const int mode) {
original_mode_ = std::fegetround();
if (original_mode_ < 0) {
@ -31,5 +42,7 @@ ScopedSetRound::ScopedSetRound(const int mode) {
ScopedSetRound::~ScopedSetRound() { std::fesetround(original_mode_); }
#endif // TF_BROKEN_CFENV
} // namespace port
} // namespace tensorflow

View File

@ -16,7 +16,16 @@ limitations under the License.
#ifndef TENSORFLOW_CORE_PLATFORM_SETROUND_H_
#define TENSORFLOW_CORE_PLATFORM_SETROUND_H_
#include <cfenv>
#if defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
// The <cfenv> header is broken pre-API 21 for several NDK releases.
#define TF_BROKEN_CFENV
#endif
#if defined(TF_BROKEN_CFENV)
#include <fenv.h> // NOLINT
#else
#include <cfenv> // NOLINT
#endif
#include "tensorflow/core/platform/macros.h"