Mercurial > octave
annotate libinterp/corefcn/pr-flt-fmt.cc @ 31660:ccbf38427774 stable
doc: Note interaction between format and output_precision (bug #39832)
* libinterp/corefcn/pr-flt-fmt.cc (output_precision), pr-output.cc (format):
Add note to docstring indicating that format can change the set value of
output_precision.
author | Nicholas R. Jankowski <jankowski.nicholas@gmail.com> |
---|---|
date | Sat, 10 Dec 2022 07:19:18 -0500 |
parents | e88a07dec498 |
children | 597f3ee61a48 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30001
diff
changeset
|
3 // Copyright (C) 1993-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 # include "config.h" |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #endif |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include "defun.h" |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include "error.h" |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include "pr-flt-fmt.h" |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #include "variables.h" |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 // The precision of the numbers printed by the default output |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 // routines. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 static int Voutput_precision = 5; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 int |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 output_precision (void) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 return Voutput_precision; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 void |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
46 set_output_prec (int prec) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 Voutput_precision = prec; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
51 OCTAVE_BEGIN_NAMESPACE(octave) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
52 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 DEFUN (output_precision, args, nargout, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 doc: /* -*- texinfo -*- |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 @deftypefn {} {@var{val} =} output_precision () |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 @deftypefnx {} {@var{old_val} =} output_precision (@var{new_val}) |
30588
ed17822e7662
doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
57 @deftypefnx {} {@var{old_val} =} output_precision (@var{new_val}, "local") |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 Query or set the internal variable that specifies the minimum number of |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 significant figures to display for numeric output. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
61 Note that regardless of the value set for @code{output_precision}, the |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
62 number of digits of precision displayed is limited to 16 for double |
31660
ccbf38427774
doc: Note interaction between format and output_precision (bug #39832)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
31605
diff
changeset
|
63 precision values and 7 for single precision values. Also, calls to the |
ccbf38427774
doc: Note interaction between format and output_precision (bug #39832)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
31605
diff
changeset
|
64 @code{format} function that change numeric display can also change the set |
ccbf38427774
doc: Note interaction between format and output_precision (bug #39832)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
31605
diff
changeset
|
65 value for @code{output_precision}. |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
66 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 When called from inside a function with the @qcode{"local"} option, the |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 variable is changed locally for the function and any subroutines it calls. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 The original variable value is restored when exiting the function. |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
70 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
71 @seealso{format, fixed_point_format} |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 @end deftypefn */) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 { |
30001
428cccc75cc9
move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
74 return set_internal_variable (Voutput_precision, args, nargout, |
428cccc75cc9
move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
75 "output_precision", 0, 16); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
77 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
78 OCTAVE_END_NAMESPACE(octave) |