26 #if defined (HAVE_CONFIG_H)
80 char *tmp =
new char [
len+1];
81 tmp = strcpy (tmp, s);
91 std::string
fgets (FILE *
f,
bool& eof)
98 int max_size = grow_size;
100 char *buf =
static_cast<char *
> (
std::malloc (max_size));
102 (*current_liboctave_error_handler) (
"octave_fgets: unable to malloc %d bytes", max_size);
113 if (
len == grow_size - 1)
115 int tmp = bufptr - buf + grow_size - 1;
117 max_size += grow_size;
118 auto tmpbuf =
static_cast<char *
> (std::realloc (buf, max_size));
122 (*current_liboctave_error_handler) (
"octave_fgets: unable to realloc %d bytes", max_size);
127 if (*(bufptr-1) ==
'\n')
133 else if (bufptr[
len-1] !=
'\n')
135 bufptr[
len++] =
'\n';
156 while (retval.empty ());
173 std::string retval =
fgets (
f, eof);
175 if (! retval.empty () && retval.back () ==
'\n')
181 template <
typename T>
203 template <
typename T>
214 if (c1 ==
'n' || c1 ==
'N')
217 if (c2 ==
'f' || c2 ==
'F')
218 val = std::numeric_limits<T>::infinity ();
220 is.setstate (std::ios::failbit);
223 is.setstate (std::ios::failbit);
230 if (c1 ==
'a' || c1 ==
'A')
233 if (c2 ==
'n' || c2 ==
'N')
234 val = std::numeric_limits<T>::quiet_NaN ();
237 val = numeric_limits<T>::NA ();
238 if (c2 != std::istream::traits_type::eof ())
241 is.clear (is.rdstate () & ~std::ios::failbit);
245 is.setstate (std::ios::failbit);
250 (*current_liboctave_error_handler)
251 (
"read_inf_nan_na: invalid character '%c'", c0);
259 template <
typename T>
267 std::streampos pos = is.tellg ();
286 if (c2 ==
'i' || c2 ==
'I' || c2 ==
'n' || c2 ==
'N')
287 val = read_inf_nan_na<T> (is, c2);
294 if (neg && ! is.fail ())
301 val = read_inf_nan_na<T> (is, c1);
310 std::ios::iostate status = is.rdstate ();
311 if (status & std::ios::failbit)
317 val = -std::numeric_limits<T>::infinity ();
319 val = std::numeric_limits<T>::infinity ();
320 is.clear (status & ~std::ios::failbit);
327 is.setstate (status);
334 template <
typename T>
341 std::complex<T> cx = 0.0;
350 re = read_value<T> (is);
355 im = read_value<T> (is);
359 cx = std::complex<T> (re, im);
361 is.setstate (std::ios::failbit);
366 is.setstate (std::ios::failbit);
371 cx = read_value<T> (is);
382 return read_fp_value<double> (is);
387 return read_cx_fp_value<double> (is);
392 return read_fp_value<float> (is);
397 return read_cx_fp_value<float> (is);
400 template <
typename T>
437 os << (value < 0 ?
"-Inf" :
"Inf");
446 write_value<double> (os,
real (value));
448 write_value<double> (os,
imag (value));
463 os << (value < 0 ?
"-Inf" :
"Inf");
472 write_value<float> (os,
real (value));
474 write_value<float> (os,
imag (value));
490 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
494 return octave_lli_multiply_overflow_wrapper (a, b,
r);
505 unsigned long int *
r)
510 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
512 unsigned long long int b,
513 unsigned long long int *
r)
515 return octave_ulli_multiply_overflow_wrapper (a, b,
r);
charNDArray max(char d, const charNDArray &m)
ColumnVector real(const ComplexColumnVector &a)
ColumnVector imag(const ComplexColumnVector &a)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
int octave_i_multiply_overflow_wrapper(int a, int b, int *r)
int octave_li_multiply_overflow_wrapper(long int a, long int b, long int *r)
int octave_uli_multiply_overflow_wrapper(unsigned long int a, unsigned long int b, unsigned long int *r)
int octave_ui_multiply_overflow_wrapper(unsigned int a, unsigned int b, unsigned int *r)
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f
void write_value(std::ostream &os, const T &value)
template OCTAVE_API octave_int64 read_value< octave_int64 >(std::istream &is)
bool is_int_or_inf_or_nan(double x)
bool int_multiply_overflow(int a, int b, int *r)
template OCTAVE_API void write_value< octave_uint8 >(std::ostream &os, const octave_uint8 &value)
template OCTAVE_API void write_value< octave_int8 >(std::ostream &os, const octave_int8 &value)
template OCTAVE_API octave_uint64 read_value< octave_uint64 >(std::istream &is)
template OCTAVE_API void write_value< octave_int16 >(std::ostream &os, const octave_int16 &value)
template OCTAVE_API void write_value< octave_int32 >(std::ostream &os, const octave_int32 &value)
template OCTAVE_API void write_value< octave_uint64 >(std::ostream &os, const octave_uint64 &value)
std::string fgetl(FILE *f)
std::complex< T > read_cx_fp_value(std::istream &is)
double read_fp_value(std::istream &is)
template OCTAVE_API void write_value< octave_int64 >(std::ostream &os, const octave_int64 &value)
bool too_large_for_float(double x)
template OCTAVE_API octave_uint8 read_value< octave_uint8 >(std::istream &is)
template OCTAVE_API octave_int32 read_value< octave_int32 >(std::istream &is)
template OCTAVE_API octave_int8 read_value< octave_int8 >(std::istream &is)
template OCTAVE_API void write_value< bool >(std::ostream &os, const bool &value)
std::string fgets(FILE *f)
template OCTAVE_API bool read_value< bool >(std::istream &is)
template OCTAVE_API octave_int16 read_value< octave_int16 >(std::istream &is)
template OCTAVE_API octave_uint16 read_value< octave_uint16 >(std::istream &is)
template OCTAVE_API octave_uint32 read_value< octave_uint32 >(std::istream &is)
template OCTAVE_API void write_value< octave_uint16 >(std::ostream &os, const octave_uint16 &value)
char * strsave(const char *s)
template OCTAVE_API void write_value< octave_uint32 >(std::ostream &os, const octave_uint32 &value)
T read_inf_nan_na(std::istream &is, char c0)
T read_value(std::istream &is)
std::complex< double > Complex
std::complex< float > FloatComplex
T::size_type strlen(const typename T::value_type *str)