1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#ifndef lint
static char *RCSid = "$Id: cmath.c,v 1.9 1993/02/09 17:56:15 anders Exp anders $";
#endif
/*
* The Regina Rexx Interpreter
* Copyright (C) 1992-1994 Anders Christensen <anders@pvv.unit.no>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* More attention should be paid to overflow and underflow conditions.
* This *is* done in some of the routines for the GCC compiler, but should
* be done in an ANSI-compatible manner.
*/
#include "rexx.h"
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#ifdef SunKludges
extern double strtod( const char *, char ** ) ;
#endif
double myatof( streng *string )
{
char *ptr=NULL ;
double answer=0 ;
#if 0
extern int minus_zero ;
#endif
string = Str_ify(Str_dup(string)) ;
answer = strtod(string->value,&ptr) ;
for (;(*ptr)&&(isspace(*ptr));ptr++) ;
#ifdef SUNOS_STRTOD_BUG
for (;*ptr=='0';ptr++) ;
#endif /* SUNOS_STRTOD_BUG */
if (*ptr)
exiterror( ERR_BAD_ARITHMETIC, 0 ) ;
Free_string( string ) ;
/* only for special machines */
#if 0
if (answer == minus_zero)
answer = 0 ;
#endif
return answer ;
}
int myisnumber( streng *string )
{
register char *ptr=NULL, *eptr=NULL ;
int num=0 ;
if (!string->len)
return 0 ;
ptr = string->value ;
eptr = Str_end( string ) ;
for (; (ptr<eptr) && (isspace(*ptr)); ptr++) ;
if ((ptr<eptr) && ((*ptr=='-') || (*ptr=='+')))
for (ptr++; (ptr<eptr) && (isspace(*ptr)); ptr++) ;
for (; (ptr<eptr) && isdigit(*ptr); ptr++, num++) ;
if ((ptr<eptr) && *ptr=='.')
for (ptr++;(ptr<eptr) && isdigit(*ptr); ptr++, num++) ;
if (!num)
return 0 ;
if ((ptr<eptr) && ((*ptr=='e') || (*ptr=='E')))
{
ptr++ ;
num = 0 ;
if ((ptr<eptr) && ((*ptr=='-') || (*ptr=='+')))
ptr++ ;
for (; (ptr<eptr) && isdigit(*ptr); ptr++, num++ ) ;
if (!num)
return 0 ;
}
for (; (ptr<eptr) && (isspace(*ptr)); ptr++) ;
return (ptr==eptr) ;
}
/*
* Takes 'string' as parameter, analyze whether it is an integer, and
* return a boolean variable which is true iff 'string' is a legal
* integer. The format of a legal integer is (the regexpr):
* [ ]*([-+][ ]*)?[0-9]+[ ]*
*/
int myisinteger( streng *string )
{
char *cptr=NULL, *eptr=NULL ;
cptr = string->value ;
eptr = cptr + string->len ;
for (;cptr<eptr && isspace(*cptr); cptr++) ;
if (cptr<eptr && (*cptr=='-' || *cptr=='+'))
for (cptr++; cptr<eptr && isspace(*cptr); cptr++) ;
if (cptr>=eptr)
return 0 ;
for (;cptr<eptr && isdigit(*cptr); cptr++) ;
for (;cptr<eptr && isspace(*cptr); cptr++) ;
return (cptr==eptr) ;
}
|