00001 // --8<--8<--8<--8<-- 00002 // 00003 // Copyright (C) 2006 Smithsonian Astrophysical Observatory 00004 // 00005 // This file is part of suplibxx 00006 // 00007 // suplibxx is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 00010 // of the License, or (at your option) any later version. 00011 // 00012 // suplibxx is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with this program; if not, write to the 00019 // Free Software Foundation, Inc. 00020 // 51 Franklin Street, Fifth Floor 00021 // Boston, MA 02110-1301, USA 00022 // 00023 // -->8-->8-->8-->8-- 00024 00025 #include <errno.h> 00026 #include <cstdlib> 00027 00028 using namespace std; 00029 00030 #include "str.h" 00031 00044 double suplib::str2d( const char* txt ) throw( Exception ) { 00045 00046 // Field is empty 00047 if ( NULL == txt || '\0' == *txt ) 00048 throw Exception( "suplib::str2d( ) : Empty field" ); 00049 00050 char* ptr=NULL; 00051 00052 double result = strtod( txt, &ptr ); 00053 00054 if ( ERANGE == errno ) 00055 throw Exception( "suplib::str2d( " + string( txt ) + 00056 ") : Variable overflow" ); 00057 00058 if ( '\0' != *ptr ) 00059 throw Exception( "suplib::str2d( " + string( txt ) + 00060 " ) Not a number, problem at `" + string( ptr ) + "'" ); 00061 00062 return result; 00063 00064 }