Mercurial > hg > octave-shane
changeset 10379:f578e6468d0c
use C++-0x code in str2double
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 01 Mar 2010 15:24:05 +0100 |
parents | eeb6c09ec51a |
children | 60acc47c203f |
files | src/ChangeLog src/DLD-FUNCTIONS/str2double.cc |
diffstat | 2 files changed, 24 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-03-01 Jaroslav Hajek <highegg@gmail.com> + + * DLD-FUNCTIONS/str2double.cc (set_component): New helper func. + (str2double1): Use it here. + 2010-03-01 Jaroslav Hajek <highegg@gmail.com> * DLD-FUNCTIONS/str2double.cc (str2double1): Use ISO-conformant code
--- a/src/DLD-FUNCTIONS/str2double.cc +++ b/src/DLD-FUNCTIONS/str2double.cc @@ -136,6 +136,23 @@ return is; } +static inline void +set_component (Complex& c, double num, bool imag) +{ + // FIXME: this is C++-0x. +#if defined (__GNUC__) || defined (__MSVC__) + if (imag) + c.imag (r); + else + c.real (r); +#else + if (imag) + c = Complex (c.real (), num); + else + c = Complex (num, c.imag ()); +#endif +} + static Complex str2double1 (std::string str) { @@ -156,38 +173,14 @@ val = octave_NaN; else { - if (i1) -#ifdef __GNUC__ - val.imag () = num; // GNU C++ -#else - val = Complex (val.real (), num); // ISO C++ -#endif - else -#ifdef __GNUC__ - val.real () = num; // GNU C++ -#else - val = Complex (num, val.imag ()); // ISO C++ -#endif + set_component (c, num, i1); if (! is.eof ()) { if (! extract_num (is, num, i2, s2) || i1 == i2 || ! s2) val = octave_NaN; else - { - if (i2) -#ifdef __GNUC__ - val.imag () = num; // GNU C++ -#else - val = Complex (val.real (), num); // ISO C++ -#endif - else -#ifdef __GNUC__ - val.real () = num; // GNU C++ -#else - val = Complex (num, val.imag ()); // ISO C++ -#endif - } + set_component (c, num, i2); } }