00001 /* $Id$ */ 00002 00003 /* GenLib2 - General Library 2 00004 * Copyright (C) 2005 Dirk Stallmann 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #ifndef GENLIB2_DMSCONV_INCLUDED 00022 #define GENLIB2_DMSCONV_INCLUDED 00023 00024 #if defined(_WIN32) 00025 #define COPYSIGN _copysign 00026 #else 00027 #define COPYSIGN copysign 00028 #endif 00029 00030 00031 // external math-subroutines 00032 // #if !defined(_WIN32) 00033 // extern "C" 00034 // { 00035 // double COPYSIGN(double x, double y); 00036 // double fabs(double x); 00037 // double floor(double x); 00038 // } 00039 // #endif 00040 00041 00042 namespace GenLib2 00043 { 00044 00046 template<class T> inline 00047 T dms2dec(T d, T m, T s) 00048 { 00049 return T(COPYSIGN(fabs(d) + m / 60. + s / 3600., d)); 00050 } 00051 00052 00054 template<class T> inline 00055 void dec2dms(T a, T& d, T& m, T& s) 00056 { 00057 T b = fabs(a); // absolute value 00058 d = floor(b); // degree 00059 T t = (b - d) * 60.; // remainder 00060 m = floor(t); // minutes 00061 s = (t - m) * 60; // seconds 00062 d = COPYSIGN(d, a); // copy sign 00063 } 00064 00065 } // namespace GenLib2 00066 00067 #endif /* GENLIB2_DMSCONV_INCLUDED */ 00068