bringing SDL 1.2.14 from vendor into the main branch
[AROS-Contrib.git] / regina / cmath.c
blobc679f59f18bc57690c204f7f2281574bcbd9f396
1 #ifndef lint
2 static char *RCSid = "$Id$";
3 #endif
5 /*
6 * The Regina Rexx Interpreter
7 * Copyright (C) 1992-1994 Anders Christensen <anders@pvv.unit.no>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * More attention should be paid to overflow and underflow conditions.
26 * This *is* done in some of the routines for the GCC compiler, but should
27 * be done in an ANSI-compatible manner.
31 #include "rexx.h"
32 #include <math.h>
33 #include <stdio.h>
34 #include <ctype.h>
35 #include <string.h>
37 #ifdef SunKludges
38 double strtod( const char *, char ** ) ;
39 #endif
41 double myatof( const tsd_t *TSD, const streng *string )
43 char *str,*ptr ;
44 double answer ;
46 str = str_ofTSD(string) ;
47 answer = strtod(str,&ptr) ;
49 /* remove leading spaces */
50 for (;(*ptr)&&(isspace(*ptr));ptr++) ;
51 #ifdef SUNOS_STRTOD_BUG
52 for (;*ptr=='0';ptr++) ;
53 #endif /* SUNOS_STRTOD_BUG */
54 if (*ptr)
55 exiterror( ERR_BAD_ARITHMETIC, 0 ) ;
56 FreeTSD( str ) ;
58 return answer ;
62 int myisnumber( const streng *string )
64 const register char *ptr=NULL, *eptr=NULL ;
65 int num=0 ;
67 if (!string->len)
68 return 0 ;
70 ptr = string->value ;
71 eptr = Str_end( string ) ;
73 for (; (ptr<eptr) && (isspace(*ptr)); ptr++) ;
74 if ((ptr<eptr) && ((*ptr=='-') || (*ptr=='+')))
75 for (ptr++; (ptr<eptr) && (isspace(*ptr)); ptr++) ;
77 for (; (ptr<eptr) && isdigit(*ptr); ptr++, num++) ;
78 if ((ptr<eptr) && *ptr=='.')
79 for (ptr++;(ptr<eptr) && isdigit(*ptr); ptr++, num++) ;
81 if (!num)
82 return 0 ;
84 if ((ptr<eptr) && ((*ptr=='e') || (*ptr=='E')))
86 ptr++ ;
87 num = 0 ;
88 if ((ptr<eptr) && ((*ptr=='-') || (*ptr=='+')))
89 ptr++ ;
91 for (; (ptr<eptr) && isdigit(*ptr); ptr++, num++ ) ;
92 if (!num)
93 return 0 ;
96 for (; (ptr<eptr) && (isspace(*ptr)); ptr++) ;
97 return (ptr==eptr) ;
102 * Takes 'string' as parameter, analyze whether it is an integer, and
103 * return a boolean variable which is true iff 'string' is a legal
104 * integer. The format of a legal integer is (the regexpr):
105 * [ ]*([-+][ ]*)?[0-9]+[ ]*
107 int myisinteger( const streng *string )
109 const char *cptr=NULL, *eptr=NULL ;
111 cptr = string->value ;
112 eptr = cptr + string->len ;
114 for (;cptr<eptr && isspace(*cptr); cptr++) ;
115 if (cptr<eptr && (*cptr=='-' || *cptr=='+'))
116 for (cptr++; cptr<eptr && isspace(*cptr); cptr++) ;
118 if (cptr>=eptr)
119 return 0 ;
121 for (;cptr<eptr && isdigit(*cptr); cptr++) ;
122 for (;cptr<eptr && isspace(*cptr); cptr++) ;
123 return (cptr==eptr) ;