This file is indexed.

/usr/share/octave/packages/interval-2.1.0/@infsup/intervaltotext.m is in octave-interval 2.1.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
## Copyright 2014-2016 Oliver Heimlich
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @documentencoding UTF-8
## @deftypemethod {@@infsup} {@var{S} =} intervaltotext (@var{X})
## @deftypemethodx {@@infsup} {@var{S} =} intervaltotext (@var{X}, @var{FORMAT})
## 
## Build an approximate representation of the interval @var{X}.
##
## Output @var{S} is a simple string for scalar intervals, and a cell array of
## strings for interval matrices.
## 
## The interval boundaries are stored in binary floating point format and are
## converted to decimal or hexadecimal format with possible precision loss.  If
## output is not exact, the boundaries are rounded accordingly (e. g. the upper
## boundary is rounded towards infinite for output representation).
## 
## The exact decimal format may produce a lot of digits.
##
## Possible values for @var{FORMAT} are: @code{decimal} (default),
## @code{exact decimal}, @code{exact hexadecimal}, @code{auto}
## 
## Accuracy: For all intervals @var{X} is an accurate subset of
## @code{infsup (intervaltotext (@var{X}))}.
## @example
## @group
## x = infsup (1 + eps);
## intervaltotext (x)
##   @result{} [1.0000000000000002, 1.000000000000001]
## @end group
## @end example
## @example
## @group
## y = nextout (x);
## intervaltotext (y)
##   @result{} [1, 1.0000000000000005]
## @end group
## @end example
## @example
## @group
## z = infsup (1);
## intervaltotext (z)
##   @result{} [1]
## @end group
## @end example
## @seealso{@@infsup/intervaltoexact}
## @end deftypemethod

## Author: Oliver Heimlich
## Keywords: interval
## Created: 2014-09-30

function [s, isexact] = intervaltotext (x, format)

if (nargin > 2)
    print_usage ();
    return
endif

isexact = true ();

if (nargin < 2)
    format = "decimal";
endif

s = l = u = cell (size (x.inf));
s(isempty (x)) = "[Empty]";
s(isentire (x)) = "[Entire]";

select = not (isempty (x) | isentire (x));
if (any (select(:)))
    [l(select), lexact] = mpfr_to_string_d (-inf, format, x.inf(select));
    [u(select), uexact] = mpfr_to_string_d (+inf, format, x.sup(select));
    isexact = lexact && uexact;
    
    l(x.inf == 0) = "0"; # no sign for zero
    
    ## Normalize case of +-Inf
    l(select & x.inf == -inf) = "-Inf";
    u(select & x.sup == inf) = "Inf";
    
    ## If l is negative, then u shall also carry a sign (not zero)
    change_of_sign = select & x.inf < 0 & x.sup > 0;
    u(change_of_sign) = strcat ("+", u(change_of_sign));
    
    singleton_string = strcmp (l, u);
    s(select & singleton_string) = strcat ("[", ...
                                           l(select & singleton_string), ...
                                           "]");
    s(select & not (singleton_string)) = strcat (...
                                        "[", ...
                                        l(select & not (singleton_string)), ...
                                        {", "}, ...
                                        u(select & not (singleton_string)), ...
                                        "]");
endif

if (isscalar (s))
    s = s{1};
endif

endfunction

%!assert (intervaltotext (infsup (1 + eps), "exact decimal"), "[1.0000000000000002220446049250313080847263336181640625]");
%!assert (intervaltotext (infsup (1 + eps), "exact hexadecimal"), "[0x1.0000000000001p+0]");
%!test
%! output_precision (3, 'local');
%! assert (intervaltotext (infsup (pi), "auto"), "[3.14, 3.15]");
%! output_precision (4, 'local');
%! assert (intervaltotext (infsup (pi), "auto"), "[3.141, 3.142]");
%!# from the documentation string
%!assert (intervaltotext (infsup (1 + eps)), "[1.0000000000000002, 1.000000000000001]");
%!assert (intervaltotext (nextout (infsup (1 + eps))), "[1, 1.0000000000000005]");
%!assert (intervaltotext (infsup (1)), "[1]");