GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
fpucw-wrappers.c
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2016-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26// The fpucw macros are provided by gnulib. We don't include gnulib
27// headers directly in Octave's C++ source files to avoid problems that
28// may be caused by the way that gnulib overrides standard library
29// functions.
30
31#if defined (HAVE_CONFIG_H)
32# include "config.h"
33#endif
34
35#if defined (HAVE_FPU_CONTROL_H)
36# include <fpu_control.h>
37#endif
38
39#include "fpucw.h"
40
41#include "fpucw-wrappers.h"
42
43#if ! defined (_FPU_DEFAULT)
44# if defined __i386__ || defined __x86_64__
45# define _FPU_DEFAULT 0x037f
46# else
47# define _FPU_DEFAULT 0
48# endif
49#endif
50
51void
53{
54 fpucw_t cw = GET_FPUCW ();
55
56 if (cw != _FPU_DEFAULT)
57 SET_FPUCW (_FPU_DEFAULT);
58}
59
60// OLDCW is the name used by the fpucw.h macros and gnulib doesn't give
61// us a choice. We are also assuming that fpucw_t is unsigned, and no
62// wider than an int.
63
64unsigned int
66{
67 // Don't use DECL_LONG_DOUBLE_ROUNDING here because on some systems,
68 // it is defined to be empty.
69
70 fpucw_t oldcw = 0;
71
72 BEGIN_LONG_DOUBLE_ROUNDING ();
73
74 return oldcw;
75}
76
77void
79{
80 END_LONG_DOUBLE_ROUNDING ();
81
82 // It might be unused.
83 octave_unused_parameter (oldcw);
84}
unsigned int octave_begin_long_double_rounding(void)
#define _FPU_DEFAULT
void octave_end_long_double_rounding(unsigned int oldcw)
void octave_set_default_fpucw(void)