GNU Octave  8.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-2023 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.
37 static int Voutput_precision = 5;
38 
39 int
41 {
42  return Voutput_precision;
43 }
44 
45 void
46 set_output_prec (int prec)
47 {
48  Voutput_precision = prec;
49 }
50 
52 
53 DEFUN (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 {} {@var{old_val} =} output_precision (@var{new_val}, "local")
58 Query or set the internal variable that specifies the minimum number of
59 significant figures to display for numeric output.
60 
61 Note that regardless of the value set for @code{output_precision}, the
62 number of digits of precision displayed is limited to 16 for double
63 precision values and 7 for single precision values. Also, calls to the
64 @code{format} function that change numeric display can also change the set
65 value for @code{output_precision}.
66 
67 When called from inside a function with the @qcode{"local"} option, the
68 variable is changed locally for the function and any subroutines it calls.
69 The original variable value is restored when exiting the function.
70 
71 @seealso{format, fixed_point_format}
72 @end deftypefn */)
73 {
74  return set_internal_variable (Voutput_precision, args, nargout,
75  "output_precision", 0, 16);
76 }
77 
OCTAVE_END_NAMESPACE(octave)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#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:584