Projects
mass
atmos
yalpa-copysign.diff
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File yalpa-copysign.diff of Package atmos (Revision 15)
Currently displaying revision
15
,
Show latest
--- third-party/yalpa/test/io.cpp (revision 0) +++ third-party/yalpa/test/io.cpp (revision 16) @@ -0,0 +1,21 @@ +#include <iostream> +#include <sstream> +#include <string> + +#include <yalpa/io.h> +#include <yalpa/spheric.h> + +int main( int argc, char** argv ){ + using namespace yalpa; + + double ra; + + std::string str1="-00 02 03"; + std::istringstream stm1(str1); + + stm1 >> std::hours >> std::sexagesimal >> yalpa::make_angle(ra); + std::cout << ra << std::endl; + std::cout << std::degrees << std::sexagesimal << yalpa::make_angle(ra) << std::endl; + + return 0; +} --- third-party/yalpa/test/Makefile.am (revision 14) +++ third-party/yalpa/test/Makefile.am (revision 16) @@ -1,4 +1,4 @@ -bin_PROGRAMS = convert julian sun +bin_PROGRAMS = convert julian sun io convert_SOURCES = convert.cpp convert_CPPFLAGS = -I @abs_top_srcdir@/include convert_LDADD = @abs_top_builddir@/src/libyalpa.la @@ -8,3 +8,6 @@ sun_SOURCES = sun.cpp sun_CPPFLAGS = -I @abs_top_srcdir@/include sun_LDADD = @abs_top_builddir@/src/libyalpa.la +io_SOURCES = io.cpp +io_CPPFLAGS = -I @abs_top_srcdir@/include +io_LDADD = @abs_top_builddir@/src/libyalpa.la --- third-party/yalpa/include/yalpa/io.h (revision 14) +++ third-party/yalpa/include/yalpa/io.h (revision 16) @@ -23,6 +23,8 @@ #include <iosfwd> #include <iostream> +#include <boost/math/special_functions/sign.hpp> + namespace yalpa { template<class T> struct angle { @@ -81,14 +83,16 @@ if( is_degrees(stm) ){ T degree = val()/M_PI*180; if( is_sexagesimal(stm) ) { - stm << int(degree) << stm.fill() << int(std::abs(60*std::fmod(degree,1.0))) << stm.fill() << std::abs((3600*std::fmod(degree,1.0/60.0))); + if( val() < 0 ) { stm << "-"; } + stm << int(std::abs(degree)) << stm.fill() << int(std::abs(60*std::fmod(degree,1.0))) << stm.fill() << std::abs((3600*std::fmod(degree,1.0/60.0))); } else { stm << degree; } }else if( is_hours(stm) ){ T hour = val()/M_PI*12; if( is_sexagesimal(stm) ) { - stm << int(hour) << stm.fill() << int(std::abs(60*std::fmod(hour,1.0))) << stm.fill() << std::abs((3600*std::fmod(hour,1.0/60.0))); + if( val() < 0 ) { stm << "-"; } + stm << int(std::abs(hour)) << stm.fill() << int(std::abs(60*std::fmod(hour,1.0))) << stm.fill() << std::abs((3600*std::fmod(hour,1.0/60.0))); } else { stm << hour; } @@ -99,6 +103,8 @@ return stm; } template<class T> std::istream& operator>>( std::istream& stm, yalpa::angle<T> val ) { + using boost::math::copysign; + std::istream::sentry se(stm); if( se ){ if( is_degrees(stm) ){ @@ -106,7 +112,7 @@ if( is_sexagesimal(stm) ) { T deg,min,sec; stm >> deg >> min >> sec; - val() = ( deg < 0 ? -1 : 1 ) * ( std::abs(deg) + min/60.0 + sec/3600.0 ) / 180.0 * M_PI; + val() = copysign( ( std::abs(deg) + min/60.0 + sec/3600.0 ) / 180.0 * M_PI, deg ); } else { stm >> degree; val() = degree / 180.0 * M_PI; @@ -116,7 +122,7 @@ if( is_sexagesimal(stm) ) { T hour,min,sec; stm >> hour >> min >> sec; - val() = ( hour < 0 ? -1 : 1 ) * ( std::abs(hour) + min/60.0 + sec/3600.0 ) / 12.0 * M_PI; + val() = copysign( ( std::abs(hour) + min/60.0 + sec/3600.0 ) / 12.0 * M_PI, hour ); } else { stm >> hour; val() = hour / 12.0 * M_PI;
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.