GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pr-flt-fmt.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2022 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#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "defun.h"
31#include "error.h"
32#include "pr-flt-fmt.h"
33#include "variables.h"
34
35// The precision of the numbers printed by the default output
36// routines.
37static int Voutput_precision = 5;
38
39int
41{
42 return Voutput_precision;
43}
44
45void
47{
48 Voutput_precision = prec;
49}
50
51OCTAVE_NAMESPACE_BEGIN
52
53DEFUN (output_precision, args, nargout,
54 doc: /* -*- texinfo -*-
55@deftypefn {} {@var{val} =} output_precision ()
56@deftypefnx {} {@var{old_val} =} output_precision (@var{new_val})
57@deftypefnx {} {} output_precision (@var{new_val}, "local")
58Query or set the internal variable that specifies the minimum number of
59significant figures to display for numeric output.
60
61Note that regardless of the value set for @code{output_precision}, the
62number of digits of precision displayed is limited to 16 for double
63precision values and 7 for single precision values.
64
65When called from inside a function with the @qcode{"local"} option, the
66variable is changed locally for the function and any subroutines it calls.
67The original variable value is restored when exiting the function.
68
69@seealso{format, fixed_point_format}
70@end deftypefn */)
71{
72 return set_internal_variable (Voutput_precision, args, nargout,
73 "output_precision", 0, 16);
74}
75
76OCTAVE_NAMESPACE_END
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
static int Voutput_precision
Definition: pr-flt-fmt.cc:37
int output_precision(void)
Definition: pr-flt-fmt.cc:40
void set_output_prec(int prec)
Definition: pr-flt-fmt.cc:46
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)
Definition: variables.cc:587