This version of atof checks for overflow conditions, rather
than simply causing a SIGFP. It also takes advantage of the overlap
between atof() and strtod() functionality to finally implement the
long-missing strtod in libc (yay!). Also adjusts awk's config.h to
live with this new fact.
[ Editor's note: ]
ALSO BE SURE TO READ THE TOP LEVEL README FILE FOR THE PATCH KIT.
There are important instructions on how to properly build things
after installing this patch. If you do not do so, this patch will
not do anything for you.
AUTHOR: Joerg Wunsch
386BSD-Patchkit: patch00089
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
+ * -------------------- ----- ----------------------
+ * CURRENT PATCH LEVEL: 1 00089
+ * -------------------- ----- ----------------------
+ *
+ * 27 Feb 93 Joerg Wunsch Implement strtod, fix atof.
+ *
*/
#if defined(LIBC_SCCS) && !defined(lint)
*/
#if defined(LIBC_SCCS) && !defined(lint)
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
static double twoemax = 9007199254740992.; /*2^53*/
static double twoemax = 9007199254740992.; /*2^53*/
{
register int c;
register int exp = 0;
{
register int c;
register int exp = 0;
int bexp;
int neg = 1;
int negexp = 1;
int bexp;
int neg = 1;
int negexp = 1;
+ /* according to ANSI, check for over-/underflow */
+ if(exp > 0) {
+ if(endp)
+ *endp = oldp;
+ errno = ERANGE;
+ return neg < 0? -HUGE_VAL: HUGE_VAL;
+ }
+
if (bexp < 0)
fl /= flexp;
else
if (bexp < 0)
fl /= flexp;
else
return neg < 0 ? -fl : fl;
}
return neg < 0 ? -fl : fl;
}
+
+
+double
+atof(p)
+ const char *p;
+{
+ return strtod(p, (char **)NULL);
+}
+
* Revision 3.1 91/06/07 10:39:33 brennan
* VERSION 0.995
*
* Revision 3.1 91/06/07 10:39:33 brennan
* VERSION 0.995
*
+ *
+ * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
+ * -------------------- ----- ----------------------
+ * CURRENT PATCH LEVEL: 1 00089
+ * -------------------- ----- ----------------------
+ *
+ * 01 Mar 93 Chris Demetriou Adjust to life with strtod in libc
+ *
+ */
#define FPE_ZERODIVIDE FPE_FLTDIV_FAULT
#define FPE_OVERFLOW FPE_FLTOVF_FAULT
#define FPE_ZERODIVIDE FPE_FLTDIV_FAULT
#define FPE_OVERFLOW FPE_FLTOVF_FAULT
#define HAVE_MATHERR 0
#define HAVE_FMOD 1
#define HAVE_MATHERR 0
#define HAVE_FMOD 1