Mercurial > octave
annotate libinterp/corefcn/pr-flt-fmt.cc @ 24784:4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
* pr-flt-fmt.h, pr-flt-fmt.cc (Voutput_max_field_width,
output_max_field_width): Delete. Eliminate all uses.
(set_output_prec): Rename from set_output_prec_and_fw. Change all uses.
(Foutput_max_field_width): Always return 20. Don't do anything with
input. Document new behavior.
(Foutput_precision): Limit value to be in the range 0 to 16.
(class float_format): Always set width to 0.
* pr-output.h, pr-output.cc (pr_output_traits): New template.
(make_real_format): Limit output precision.
(octave_print_real_matrix_internal,
octave_print_real_diag_matrix_internal,
octave_print_complex_matrix_internal,
octave_print_complex_diag_matrix_internal): New template functions.
Use them to define float and double versions of octave_print_internal
for real and complex matrix and diag matrix functions.
(octave_print_internal): Define separate versions for float and float
complex N-d arrays.
(Fformat): Update doc string.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 21 Feb 2018 08:24:41 -0500 |
parents | 56f889d66b7c |
children | 0b9e7fcaab91 |
rev | line source |
---|---|
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
3 Copyright (C) 1993-2017 John W. Eaton |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 This file is part of Octave. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 (at your option) any later version. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 GNU General Public License for more details. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 */ |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 # include "config.h" |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 #endif |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #include "defun.h" |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #include "error.h" |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 #include "pr-flt-fmt.h" |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include "variables.h" |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 // 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
|
33 // routines. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 static int Voutput_precision = 5; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 int |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 output_precision (void) |
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 return Voutput_precision; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 } |
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 void |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
43 set_output_prec (int prec) |
24667
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 Voutput_precision = prec; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
48 DEFUN (output_max_field_width, , , |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 doc: /* -*- texinfo -*- |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
50 @deftypefn {} {} output_max_field_width |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
51 This function is obsolete and will be removed from a future version |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
52 of Octave. |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 @end deftypefn */) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 { |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
55 return octave_value (20); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 DEFUN (output_precision, args, nargout, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 doc: /* -*- texinfo -*- |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 @deftypefn {} {@var{val} =} output_precision () |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 @deftypefnx {} {@var{old_val} =} output_precision (@var{new_val}) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 @deftypefnx {} {} output_precision (@var{new_val}, "local") |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 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
|
64 significant figures to display for numeric output. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
66 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
|
67 number of digits of precision displayed is limited to 16 for double |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
68 precision values and 7 for single precision values. |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
69 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
74 @seealso{format, fixed_point_format} |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 @end deftypefn */) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 { |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
77 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, 0, 16); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 } |