Module Name: src
Committed By: christos
Date: Sat Feb 9 20:19:14 UTC 2013
Modified Files:
src/lib/libm: Makefile
src/lib/libm/src: s_nan.c s_nexttowardf.c
Log Message:
Make this work for NetBSD
To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/lib/libm/Makefile
cvs rdiff -u -r1.1 -r1.2 src/lib/libm/src/s_nan.c \
src/lib/libm/src/s_nexttowardf.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libm/Makefile
diff -u src/lib/libm/Makefile:1.126 src/lib/libm/Makefile:1.127
--- src/lib/libm/Makefile:1.126 Sun Feb 3 02:13:07 2013
+++ src/lib/libm/Makefile Sat Feb 9 15:19:13 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.126 2013/02/03 07:13:07 matt Exp $
+# $NetBSD: Makefile,v 1.127 2013/02/09 20:19:13 christos Exp $
#
# @(#)Makefile 5.1beta 93/09/24
#
@@ -66,7 +66,8 @@ COMMON_SRCS+= fenv.c
.endif
.PATH: ${.CURDIR}/arch/i387
-COMMON_SRCS+= fenv.c s_nextafterl.c s_nexttoward.c
+COMMON_SRCS+= fenv.c s_nextafterl.c s_nexttoward.c s_nexttowardf.c \
+ s_nearbyint.c # s_nan.c
ARCH_SRCS = e_acos.S e_asin.S e_atan2.S e_exp.S e_expf.S e_fmod.S e_log.S \
e_logf.S e_log10.S e_log10f.S e_log2.S e_log2f.S e_remainder.S \
e_remainderf.S e_scalb.S e_scalbf.S e_sqrt.S e_sqrtf.S s_atan.S \
@@ -75,7 +76,7 @@ ARCH_SRCS = e_acos.S e_asin.S e_atan2.S
s_ilogb.S s_ilogbf.S s_ilogbl.S s_log1p.S s_log1pf.S \
s_logb.S s_logbf.S s_logbl.S \
s_rint.S s_rintf.S s_scalbn.S s_scalbnf.S s_significand.S \
- s_significandf.S s_sin.S s_sinf.S s_tan.S s_tanf.S lrint.S
+ s_significandf.S s_sin.S s_sinf.S s_tan.S s_tanf.S lrint.S
# do not pick up the i387 asm version, it is incorrect
s_modf.o s_modf.pico s_modf.po s_modf.d: s_modf.c
Index: src/lib/libm/src/s_nan.c
diff -u src/lib/libm/src/s_nan.c:1.1 src/lib/libm/src/s_nan.c:1.2
--- src/lib/libm/src/s_nan.c:1.1 Sat Feb 9 14:37:48 2013
+++ src/lib/libm/src/s_nan.c Sat Feb 9 15:19:13 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: s_nan.c,v 1.1 2013/02/09 19:37:48 christos Exp $ */
+/* $NetBSD: s_nan.c,v 1.2 2013/02/09 20:19:13 christos Exp $ */
/*-
* Copyright (c) 2007 David Schultz
@@ -28,17 +28,27 @@
* $FreeBSD: src/lib/msun/src/s_nan.c,v 1.2 2007/12/18 23:46:32 das Exp $
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: s_nan.c,v 1.1 2013/02/09 19:37:48 christos Exp $");
+__RCSID("$NetBSD: s_nan.c,v 1.2 2013/02/09 20:19:13 christos Exp $");
#include <sys/endian.h>
#include <ctype.h>
#include <float.h>
#include <math.h>
#include <stdint.h>
-#include <strings.h>
+#include <string.h>
#include "math_private.h"
+/* XXX: Locale? not here? in <ctype.h>? */
+static int
+digittoint(char s) {
+ if (isdigit((unsigned char)s))
+ return s - '0';
+ if (islower((unsigned char)s))
+ return s - 'a' + 10;
+ return s - 'A' + 10;
+}
+
/*
* Scan a string of hexadecimal digits (the format nan(3) expects) and
* make a bit array (using the local endianness). We stop when we
@@ -51,21 +61,21 @@ __RCSID("$NetBSD: s_nan.c,v 1.1 2013/02/
* consider valid, so we might be violating the C standard. But it's
* impossible to use nan(3) portably anyway, so this seems good enough.
*/
-void
+static void
_scan_nan(uint32_t *words, int num_words, const char *s)
{
int si; /* index into s */
int bitpos; /* index into words (in bits) */
- bzero(words, num_words * sizeof(uint32_t));
+ memset(words, 0, num_words * sizeof(*words));
/* Allow a leading '0x'. (It's expected, but redundant.) */
if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
s += 2;
/* Scan forwards in the string, looking for the end of the sequence. */
- for (si = 0; isxdigit(s[si]); si++)
- ;
+ for (si = 0; isxdigit((unsigned char)s[si]); si++)
+ continue;
/* Scan backwards, filling in the bits in words[] as we go. */
#if _BYTE_ORDER == _LITTLE_ENDIAN
Index: src/lib/libm/src/s_nexttowardf.c
diff -u src/lib/libm/src/s_nexttowardf.c:1.1 src/lib/libm/src/s_nexttowardf.c:1.2
--- src/lib/libm/src/s_nexttowardf.c:1.1 Sat Feb 9 14:39:01 2013
+++ src/lib/libm/src/s_nexttowardf.c Sat Feb 9 15:19:13 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: s_nexttowardf.c,v 1.1 2013/02/09 19:39:01 christos Exp $ */
+/* $NetBSD: s_nexttowardf.c,v 1.2 2013/02/09 20:19:13 christos Exp $ */
/*
* ====================================================
@@ -15,35 +15,38 @@
#if 0
__FBSDID("$FreeBSD: src/lib/msun/src/s_nexttowardf.c,v 1.3 2011/02/10 07:38:38 das Exp $");
#else
-__RCSID("$NetBSD: s_nexttowardf.c,v 1.1 2013/02/09 19:39:01 christos Exp $");
+__RCSID("$NetBSD: s_nexttowardf.c,v 1.2 2013/02/09 20:19:13 christos Exp $");
#endif
#include <float.h>
-#include "fpmath.h"
#include "math.h"
#include "math_private.h"
-#define LDBL_INFNAN_EXP (LDBL_MAX_EXP * 2 - 1)
-
+#ifdef EXT_EXP_INFNAN
float
nexttowardf(float x, long double y)
{
- union IEEEl2bits uy;
volatile float t;
int32_t hx,ix;
+ union ieee_ext_u uy;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff; /* |x| */
- uy.e = y;
+
+ memset(&u, 0, sizeof u);
+ uy.extu_ld = y;
+ uy.extu_ext.ext_frach &= ~0x80000000;
+
+ union ieee_single_u u[2];
if((ix>0x7f800000) ||
- (uy.bits.exp == LDBL_INFNAN_EXP &&
- ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0))
+ (uy.extu_ext.ext_exp == EXT_EXP_INFNAN &&
+ (uy.extu_ext.ext_frach | uy.extu_ext.ext_fracl) != 0)
return x+y; /* x or y is nan */
if(x==y) return (float)y; /* x=y, return y */
if(ix==0) { /* x == 0 */
- SET_FLOAT_WORD(x,(uy.bits.sign<<31)|1);/* return +-minsubnormal */
+ SET_FLOAT_WORD(x,(uy.extu_ext.ext_sign<<31)|1);/* return +-minsubnormal */
t = x*x;
if(t==x) return t; else return x; /* raise underflow flag */
}
@@ -63,3 +66,4 @@ nexttowardf(float x, long double y)
SET_FLOAT_WORD(x,hx);
return x;
}
+#endif