• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CORE_PLATFORM_SETROUND_H_
17 #define TENSORFLOW_CORE_PLATFORM_SETROUND_H_
18 
19 #if defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
20 // The <cfenv> header is broken pre-API 21 for several NDK releases.
21 #define TF_BROKEN_CFENV
22 #endif
23 
24 #if defined(TF_BROKEN_CFENV)
25 #include <fenv.h>  // NOLINT
26 #else
27 #include <cfenv>  // NOLINT
28 #endif
29 
30 #include "tensorflow/core/platform/macros.h"
31 
32 namespace tensorflow {
33 namespace port {
34 
35 // While this class is active, floating point rounding mode is set to the given
36 // mode. The mode can be one of the modes defined in <cfenv>, i.e. FE_DOWNWARD,
37 // FE_TONEAREST, FE_TOWARDZERO, or FE_UPWARD. The destructor restores the
38 // original rounding mode if it could be determined. If the original rounding
39 // mode could not be determined, the destructor sets it to FE_TONEAREST.
40 class ScopedSetRound {
41  public:
42   ScopedSetRound(int mode);
43   ~ScopedSetRound();
44 
45  private:
46   int original_mode_;
47 
48   TF_DISALLOW_COPY_AND_ASSIGN(ScopedSetRound);
49 };
50 
51 }  // namespace port
52 }  // namespace tensorflow
53 
54 #endif  // TENSORFLOW_CORE_PLATFORM_SETROUND_H_
55