Mercurial > octave
annotate liboctave/util/lo-utils.cc @ 31605:e88a07dec498 stable
maint: Use macros to begin/end C++ namespaces.
* oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE,
OCTAVE_END_NAMESPACE) that can be used to start/end a namespace.
* mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc,
__dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc,
__ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc,
__magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc,
auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h,
besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc,
colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc,
defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc,
display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc,
ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h,
event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc,
fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc,
ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc,
getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc,
gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc,
graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc,
help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h,
interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h,
inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc,
ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h,
mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc,
oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h,
oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h,
oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h,
oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy,
ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc,
pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc,
qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h,
sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc,
sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h,
stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc,
symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h,
text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc,
toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc,
url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc,
variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h,
__delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc,
audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh,
mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc,
ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h,
ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc,
ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h,
ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc,
op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc,
op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc,
op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc,
op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc,
op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc,
op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc,
op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc,
op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc,
op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc,
op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc,
op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc,
op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc,
op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc,
op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h,
anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h,
comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc,
oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h,
pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h,
pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h,
pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h,
pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h,
pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc,
pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc,
pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc,
pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc,
pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc,
pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc,
pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h,
pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h,
range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc,
chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h,
lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h,
oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc,
qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc,
randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc,
sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc,
child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc,
file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h,
mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h,
oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc,
oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h,
base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h,
file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc,
lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h,
oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h,
oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h,
oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h,
pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h,
url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 01 Dec 2022 14:23:45 -0800 |
parents | 796f54d4ddbf |
children | dfa5d9c3ae72 aac27ad79be6 |
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:
30394
diff
changeset
|
3 // Copyright (C) 1996-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 //////////////////////////////////////////////////////////////////////// |
1967 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21723
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
27 # include "config.h" |
1967 | 28 #endif |
29 | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
30 #include <cstdlib> |
7048 | 31 #include <cstring> |
1967 | 32 |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
33 #include <complex> |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
34 #include <istream> |
6490 | 35 #include <limits> |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
36 #include <ostream> |
2926 | 37 #include <string> |
38 | |
10068
ca93f583573d
handle interrupts octave_fgets
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
39 #include "quit.h" |
ca93f583573d
handle interrupts octave_fgets
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
40 |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
41 #include "intprops-wrappers.h" |
2926 | 42 #include "lo-error.h" |
4130 | 43 #include "lo-ieee.h" |
1967 | 44 #include "lo-mappers.h" |
45 #include "lo-utils.h" | |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
46 #include "oct-inttypes.h" |
1967 | 47 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
48 OCTAVE_BEGIN_NAMESPACE(octave) |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
49 |
29937
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
50 bool is_int_or_inf_or_nan (double x) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
51 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
52 return math::isnan (x) || math::x_nint (x) == x; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
53 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
54 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
55 bool too_large_for_float (double x) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
56 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
57 return (math::isfinite (x) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
58 && fabs (x) > std::numeric_limits<float>::max ()); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
59 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
60 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
61 bool too_large_for_float (const Complex& x) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
62 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
63 return (too_large_for_float (x.real ()) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
64 || too_large_for_float (x.imag ())); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
65 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
66 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
67 bool is_int_or_inf_or_nan (float x) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
68 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
69 return math::isnan (x) || math::x_nint (x) == x; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
70 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
71 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
72 // Save a string. |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
73 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
74 char * strsave (const char *s) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
75 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
76 if (! s) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
77 return nullptr; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
78 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
79 int len = strlen (s); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
80 char *tmp = new char [len+1]; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
81 tmp = strcpy (tmp, s); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
82 return tmp; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
83 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
84 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
85 std::string fgets (FILE *f) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
86 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
87 bool eof; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
88 return fgets (f, eof); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
89 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
90 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
91 std::string fgets (FILE *f, bool& eof) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
92 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
93 eof = false; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
94 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
95 std::string retval; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
96 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
97 int grow_size = 1024; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
98 int max_size = grow_size; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
99 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
100 char *buf = static_cast<char *> (std::malloc (max_size)); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
101 if (! buf) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
102 (*current_liboctave_error_handler) ("octave_fgets: unable to malloc %d bytes", max_size); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
103 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
104 char *bufptr = buf; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
105 int len = 0; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
106 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
107 do |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
108 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
109 if (std::fgets (bufptr, grow_size, f)) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
110 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
111 len = strlen (bufptr); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
112 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
113 if (len == grow_size - 1) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
114 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
115 int tmp = bufptr - buf + grow_size - 1; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
116 grow_size *= 2; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
117 max_size += grow_size; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
118 auto tmpbuf = static_cast<char *> (std::realloc (buf, max_size)); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
119 if (! tmpbuf) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
120 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
121 free (buf); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
122 (*current_liboctave_error_handler) ("octave_fgets: unable to realloc %d bytes", max_size); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
123 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
124 buf = tmpbuf; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
125 bufptr = buf + tmp; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
126 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
127 if (*(bufptr-1) == '\n') |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
128 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
129 *bufptr = '\0'; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
130 retval = buf; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
131 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
132 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
133 else if (bufptr[len-1] != '\n') |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
134 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
135 bufptr[len++] = '\n'; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
136 bufptr[len] = '\0'; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
137 retval = buf; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
138 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
139 else |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
140 retval = buf; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
141 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
142 else |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
143 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
144 if (len == 0) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
145 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
146 eof = true; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
147 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
148 free (buf); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
149 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
150 buf = nullptr; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
151 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
152 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
153 break; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
154 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
155 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
156 while (retval.empty ()); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
157 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
158 free (buf); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
159 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
160 octave_quit (); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
161 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
162 return retval; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
163 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
164 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
165 std::string fgetl (FILE *f) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
166 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
167 bool eof; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
168 return fgetl (f, eof); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
169 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
170 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
171 std::string fgetl (FILE *f, bool& eof) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
172 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
173 std::string retval = fgets (f, eof); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
174 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
175 if (! retval.empty () && retval.back () == '\n') |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
176 retval.pop_back (); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
177 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
178 return retval; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
179 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
180 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
181 template <typename T> |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
182 T |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
183 read_value (std::istream& is) |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
184 { |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
185 T retval; |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
186 is >> retval; |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
187 return retval; |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
188 } |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
189 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
190 template OCTAVE_API bool read_value<bool> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
191 template OCTAVE_API octave_int8 read_value<octave_int8> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
192 template OCTAVE_API octave_int16 read_value<octave_int16> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
193 template OCTAVE_API octave_int32 read_value<octave_int32> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
194 template OCTAVE_API octave_int64 read_value<octave_int64> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
195 template OCTAVE_API octave_uint8 read_value<octave_uint8> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
196 template OCTAVE_API octave_uint16 read_value<octave_uint16> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
197 template OCTAVE_API octave_uint32 read_value<octave_uint32> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
198 template OCTAVE_API octave_uint64 read_value<octave_uint64> (std::istream& is); |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
199 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
200 // Note that the caller is responsible for repositioning the stream on |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
201 // failure. |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
202 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
203 template <typename T> |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
204 T |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
205 read_inf_nan_na (std::istream& is, char c0) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
206 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
207 T val = 0.0; |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
208 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
209 switch (c0) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
210 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
211 case 'i': case 'I': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
212 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
213 char c1 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
214 if (c1 == 'n' || c1 == 'N') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
215 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
216 char c2 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
217 if (c2 == 'f' || c2 == 'F') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
218 val = std::numeric_limits<T>::infinity (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
219 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
220 is.setstate (std::ios::failbit); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
221 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
222 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
223 is.setstate (std::ios::failbit); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
224 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
225 break; |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
226 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
227 case 'n': case 'N': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
228 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
229 char c1 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
230 if (c1 == 'a' || c1 == 'A') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
231 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
232 char c2 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
233 if (c2 == 'n' || c2 == 'N') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
234 val = std::numeric_limits<T>::quiet_NaN (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
235 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
236 { |
28857
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28849
diff
changeset
|
237 val = numeric_limits<T>::NA (); |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
238 if (c2 != std::istream::traits_type::eof ()) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
239 is.putback (c2); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
240 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
241 is.clear (is.rdstate () & ~std::ios::failbit); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
242 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
243 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
244 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
245 is.setstate (std::ios::failbit); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
246 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
247 break; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
248 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
249 default: |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
250 (*current_liboctave_error_handler) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
251 ("read_inf_nan_na: invalid character '%c'", c0); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
252 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
253 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
254 return val; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
255 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
256 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
257 // Read a double value. Discard any sign on NaN and NA. |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
258 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
259 template <typename T> |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
260 double |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
261 read_fp_value (std::istream& is) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
262 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
263 T val = 0.0; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
264 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
265 // FIXME: resetting stream position is likely to fail unless we are |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
266 // reading from a file. |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
267 std::streampos pos = is.tellg (); |
4130 | 268 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
269 char c1 = ' '; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
270 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
271 while (isspace (c1)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
272 c1 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
273 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
274 bool neg = false; |
4130 | 275 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
276 switch (c1) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
277 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
278 case '-': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
279 neg = true; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
280 OCTAVE_FALLTHROUGH; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
281 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
282 case '+': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
283 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
284 char c2 = 0; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
285 c2 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
286 if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
287 val = read_inf_nan_na<T> (is, c2); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
288 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
289 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
290 is.putback (c2); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
291 is >> val; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
292 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
293 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
294 if (neg && ! is.fail ()) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
295 val = -val; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
296 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
297 break; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
298 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
299 case 'i': case 'I': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
300 case 'n': case 'N': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
301 val = read_inf_nan_na<T> (is, c1); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
302 break; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
303 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
304 default: |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
305 is.putback (c1); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
306 is >> val; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
307 break; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
308 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
309 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
310 std::ios::iostate status = is.rdstate (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
311 if (status & std::ios::failbit) |
4130 | 312 { |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
313 // Convert MAX_VAL returned by C++ streams for very large numbers to Inf |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
314 if (val == std::numeric_limits<T>::max ()) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
315 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
316 if (neg) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
317 val = -std::numeric_limits<T>::infinity (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
318 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
319 val = std::numeric_limits<T>::infinity (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
320 is.clear (status & ~std::ios::failbit); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
321 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
322 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
323 { |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
324 // True error. Reset stream to original position and pass status on. |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
325 is.clear (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
326 is.seekg (pos); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
327 is.setstate (status); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
328 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
329 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
330 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
331 return val; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
332 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
333 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
334 template <typename T> |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
335 std::complex<T> |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
336 read_cx_fp_value (std::istream& is) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
337 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
338 T re = 0.0; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
339 T im = 0.0; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
340 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
341 std::complex<T> cx = 0.0; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
342 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
343 char ch = ' '; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
344 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
345 while (isspace (ch)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
346 ch = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
347 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
348 if (ch == '(') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
349 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
350 re = read_value<T> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
351 ch = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
352 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
353 if (ch == ',') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
354 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
355 im = read_value<T> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
356 ch = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
357 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
358 if (ch == ')') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
359 cx = std::complex<T> (re, im); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
360 else |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
361 is.setstate (std::ios::failbit); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
362 } |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
363 else if (ch == ')') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
364 cx = re; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
365 else |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
366 is.setstate (std::ios::failbit); |
4130 | 367 } |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
368 else |
6194 | 369 { |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
370 is.putback (ch); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
371 cx = read_value<T> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
372 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
373 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
374 return cx; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
375 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
376 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
377 // FIXME: Could we use traits and enable_if to avoid duplication in the |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
378 // following specializations? |
6194 | 379 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
380 template <> OCTAVE_API double read_value (std::istream& is) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
381 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
382 return read_fp_value<double> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
383 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
384 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
385 template <> OCTAVE_API Complex read_value (std::istream& is) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
386 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
387 return read_cx_fp_value<double> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
388 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
389 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
390 template <> OCTAVE_API float read_value (std::istream& is) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
391 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
392 return read_fp_value<float> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
393 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
394 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
395 template <> OCTAVE_API FloatComplex read_value (std::istream& is) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
396 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
397 return read_cx_fp_value<float> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
398 } |
4130 | 399 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
400 template <typename T> |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
401 void |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
402 write_value (std::ostream& os, const T& value) |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
403 { |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
404 os << value; |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
405 } |
6194 | 406 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
407 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
408 write_value<bool> (std::ostream& os, const bool& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
409 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
410 write_value<octave_int8> (std::ostream& os, const octave_int8& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
411 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
412 write_value<octave_int16> (std::ostream& os, const octave_int16& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
413 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
414 write_value<octave_int32> (std::ostream& os, const octave_int32& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
415 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
416 write_value<octave_int64> (std::ostream& os, const octave_int64& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
417 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
418 write_value<octave_uint8> (std::ostream& os, const octave_uint8& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
419 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
420 write_value<octave_uint16> (std::ostream& os, const octave_uint16& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
421 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
422 write_value<octave_uint32> (std::ostream& os, const octave_uint32& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
423 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
424 write_value<octave_uint64> (std::ostream& os, const octave_uint64& value); |
4130 | 425 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
426 // Note: precision is supposed to be managed outside of this function by |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
427 // setting stream parameters. |
4130 | 428 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
429 template <> OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
430 write_value (std::ostream& os, const double& value) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
431 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
432 if (lo_ieee_is_NA (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
433 os << "NA"; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
434 else if (lo_ieee_isnan (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
435 os << "NaN"; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
436 else if (lo_ieee_isinf (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
437 os << (value < 0 ? "-Inf" : "Inf"); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
438 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
439 os << value; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
440 } |
4130 | 441 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
442 template <> OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
443 write_value (std::ostream& os, const Complex& value) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
444 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
445 os << '('; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
446 write_value<double> (os, real (value)); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
447 os << ','; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
448 write_value<double> (os, imag (value)); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
449 os << ')'; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
450 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
451 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
452 // Note: precision is supposed to be managed outside of this function by |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
453 // setting stream parameters. |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
454 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
455 template <> OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
456 write_value (std::ostream& os, const float& value) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
457 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
458 if (lo_ieee_is_NA (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
459 os << "NA"; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
460 else if (lo_ieee_isnan (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
461 os << "NaN"; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
462 else if (lo_ieee_isinf (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
463 os << (value < 0 ? "-Inf" : "Inf"); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
464 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
465 os << value; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
466 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
467 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
468 template <> OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
469 write_value (std::ostream& os, const FloatComplex& value) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
470 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
471 os << '('; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
472 write_value<float> (os, real (value)); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
473 os << ','; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
474 write_value<float> (os, imag (value)); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
475 os << ')'; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
476 } |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
477 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
478 OCTAVE_BEGIN_NAMESPACE(math) |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
479 |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
480 bool int_multiply_overflow (int a, int b, int *r) |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
481 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
482 return octave_i_multiply_overflow_wrapper (a, b, r); |
4130 | 483 } |
484 | |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
485 bool int_multiply_overflow (long int a, long int b, long int *r) |
4130 | 486 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
487 return octave_li_multiply_overflow_wrapper (a, b, r); |
4130 | 488 } |
489 | |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
490 #if defined (OCTAVE_HAVE_LONG_LONG_INT) |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
491 bool int_multiply_overflow (long long int a, long long int b, |
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
492 long long int *r) |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
493 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
494 return octave_lli_multiply_overflow_wrapper (a, b, r); |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
495 } |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
496 #endif |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
497 |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
498 bool int_multiply_overflow (unsigned int a, unsigned int b, |
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
499 unsigned int *r) |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
500 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
501 return octave_ui_multiply_overflow_wrapper (a, b, r); |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
502 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
503 |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
504 bool int_multiply_overflow (unsigned long int a, unsigned long int b, |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29937
diff
changeset
|
505 unsigned long int *r) |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
506 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
507 return octave_uli_multiply_overflow_wrapper (a, b, r); |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
508 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
509 |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
510 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT) |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
511 bool int_multiply_overflow (unsigned long long int a, |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29937
diff
changeset
|
512 unsigned long long int b, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29937
diff
changeset
|
513 unsigned long long int *r) |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
514 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
515 return octave_ulli_multiply_overflow_wrapper (a, b, r); |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
516 } |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
517 #endif |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
518 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
519 OCTAVE_END_NAMESPACE(math) |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
520 OCTAVE_END_NAMESPACE(octave) |