26#if defined (HAVE_CONFIG_H)
52 return math::isnan (
x) || math::x_nint (
x) ==
x;
58 return (math::isfinite (
x)
59 && fabs (
x) > std::numeric_limits<float>::max ());
72 return math::isnan (
x) || math::x_nint (
x) ==
x;
84 char *tmp =
new char [
len+1];
85 tmp = strcpy (tmp, s);
103 int grow_size = 1024;
104 int max_size = grow_size;
106 char *buf =
static_cast<char *
> (std::malloc (max_size));
108 (*current_liboctave_error_handler) (
"octave_fgets: unable to malloc %d bytes", max_size);
115 if (std::fgets (bufptr, grow_size,
f))
119 if (
len == grow_size - 1)
121 int tmp = bufptr - buf + grow_size - 1;
123 max_size += grow_size;
124 auto tmpbuf =
static_cast<char *
> (std::realloc (buf, max_size));
128 (*current_liboctave_error_handler) (
"octave_fgets: unable to realloc %d bytes", max_size);
133 if (*(bufptr-1) ==
'\n')
139 else if (bufptr[
len-1] !=
'\n')
141 bufptr[
len++] =
'\n';
162 while (retval.empty ());
181 std::string retval =
fgets (
f, eof);
183 if (! retval.empty () && retval.back () ==
'\n')
222 if (c1 ==
'n' || c1 ==
'N')
225 if (c2 ==
'f' || c2 ==
'F')
227 val = std::numeric_limits<T>::infinity ();
231 is.setstate (std::ios::failbit);
234 is.setstate (std::ios::failbit);
241 if (c1 ==
'a' || c1 ==
'A')
244 if (c2 ==
'n' || c2 ==
'N')
245 val = std::numeric_limits<T>::quiet_NaN ();
248 val = numeric_limits<T>::NA ();
250 is.clear (is.rdstate () & ~std::ios::failbit);
255 is.setstate (std::ios::failbit);
260 (*current_liboctave_error_handler)
261 (
"read_inf_nan_na: invalid character '%c'", c0);
277 std::streampos pos = is.tellg ();
293 if (c2 ==
'i' || c2 ==
'I' || c2 ==
'n' || c2 ==
'N')
294 val = read_inf_nan_na<T> (is, c2);
295 else if (isspace (c2))
296 is.setstate (std::ios::failbit);
303 if (neg && ! math::isnan (val) && ! is.fail ())
310 val = read_inf_nan_na<T> (is, c1);
319 std::ios::iostate status = is.rdstate ();
320 if (status & std::ios::failbit)
323 if (val == std::numeric_limits<T>::max ())
326 val = -std::numeric_limits<T>::infinity ();
328 val = std::numeric_limits<T>::infinity ();
329 is.clear (status & ~std::ios::failbit);
337 is.setstate (status & ~std::ios_base::eofbit);
351 std::complex<T> cx = 0.0;
360 re = read_value<T> (is);
365 im = read_value<T> (is);
369 cx = std::complex<T> (re, im);
371 is.setstate (std::ios::failbit);
376 is.setstate (std::ios::failbit);
381 cx = read_value<T> (is);
392 return read_fp_value<double> (is);
397 return read_cx_fp_value<double> (is);
402 return read_fp_value<float> (is);
407 return read_cx_fp_value<float> (is);
445 else if (math::isnan (value))
447 else if (math::isinf (value))
448 os << (value < 0 ?
"-Inf" :
"Inf");
458 write_value<double> (os,
real (value));
460 write_value<double> (os,
imag (value));
473 else if (math::isnan (value))
475 else if (math::isinf (value))
476 os << (value < 0 ?
"-Inf" :
"Inf");
486 write_value<float> (os,
real (value));
488 write_value<float> (os,
imag (value));
506#if defined (OCTAVE_HAVE_LONG_LONG_INT)
510 return octave_lli_multiply_overflow_wrapper (a, b, r);
522 unsigned long int *r)
527#if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
530 unsigned long long int *r)
532 return octave_ulli_multiply_overflow_wrapper (a, b, r);
536OCTAVE_END_NAMESPACE(math)
537OCTAVE_END_NAMESPACE(octave)
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
template void write_value< octave_uint64 >(std::ostream &os, const octave_uint64 &value)
void write_value(std::ostream &os, const T &value)
template void write_value< octave_uint8 >(std::ostream &os, const octave_uint8 &value)
bool is_int_or_inf_or_nan(double x)
bool int_multiply_overflow(int a, int b, int *r)
std::complex< T > read_cx_fp_value(std::istream &is)
template void write_value< octave_int16 >(std::ostream &os, const octave_int16 &value)
template void write_value< octave_int32 >(std::ostream &os, const octave_int32 &value)
template void write_value< octave_uint32 >(std::ostream &os, const octave_uint32 &value)
std::string fgetl(FILE *f)
template octave_uint8 read_value< octave_uint8 >(std::istream &is)
char * strsave(const char *s)
template octave_int64 read_value< octave_int64 >(std::istream &is)
double read_fp_value(std::istream &is)
template void write_value< octave_int64 >(std::ostream &os, const octave_int64 &value)
bool too_large_for_float(double x)
template void write_value< octave_uint16 >(std::ostream &os, const octave_uint16 &value)
template octave_uint64 read_value< octave_uint64 >(std::istream &is)
template octave_int32 read_value< octave_int32 >(std::istream &is)
std::string fgets(FILE *f)
template octave_int8 read_value< octave_int8 >(std::istream &is)
template octave_uint32 read_value< octave_uint32 >(std::istream &is)
template void write_value< octave_int8 >(std::ostream &os, const octave_int8 &value)
template void write_value< bool >(std::ostream &os, const bool &value)
template bool read_value< bool >(std::istream &is)
template octave_uint16 read_value< octave_uint16 >(std::istream &is)
template octave_int16 read_value< octave_int16 >(std::istream &is)
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)