Browse Source

- replace dtoa w/ David's gdtoa, version 2008-03-15

- provide proper dtoa locks
- use the real strtof implementation
- add strtold, __hdtoa, __hldtoa
- add %a/%A support
- don't lose precision in printf, don't round to double anymore
- implement extended-precision versions of libc functions: fpclassify,
isnan, isinf, signbit, isnormal, isfinite, now that the ieee.h is
fixed
- separate vax versions of strtof, and __hdtoa
- add complex math support.  added functions: cacos, casin, catan,
ccos, csin, ctan, cacosh, casinh, catanh, ccosh, csinh, ctanh, cexp,
clog, cabs, cpow, csqrt, carg, cimag, conj, cproj, creal, cacosf,
casinf, catanf, ccosf, csinf, ctanf, cacoshf, casinhf, catanhf,
ccoshf, csinhf, ctanhf, cexpf, clogf, cabsf, cpowf, csqrtf, cargf,
cimagf, conjf, cprojf, crealf
- add fdim, fmax, fmin
- add log2. (adapted implementation e_log.c.  could be more acruate
& faster, but it's good enough for now)
- remove wrappers & cruft in libm, supposed to work-around mistakes
in SVID, etc.;  use ieee versions.  fixes issues in python 2.6 for
djm@
- make _digittoint static
- proper definitions for i386, and amd64 in ieee.h
- sh, powerpc don't really have extended-precision
- add missing definitions for mips64 (quad), m{6,8}k (96-bit) float.h
for LDBL_*
- merge lead to frac for m{6,8}k, for gdtoa to work properly
- add FRAC*BITS & EXT_TO_ARRAY32 definitions in ieee.h, for hdtoa&ldtoa
to use
- add EXT_IMPLICIT_NBIT definition, which indicates implicit
normalization bit
- add regression tests for libc: fpclassify and printf
- arith.h & gd_qnan.h definitions
- update ieee.h: hppa doesn't have quad-precision, hppa64 does
- add missing prototypes to gdtoaimp
- on 64-bit platforms make sure gdtoa doesn't use a long when it
really wants an int
- etc., what i may have forgotten...
- bump libm major, due to removed&changed symbols
- no libc bump, since this is riding on djm's libc major crank from
a day ago
discussed with / requested by / testing theo, sthen@, djm@, jsg@,
merdely@, jsing@, tedu@, brad@, jakemsr@, and others.
looks good to millert@
parts of the diff ok kettenis@
this commit does not include:
- man page changes
OPENBSD_4_5
martynas 16 years ago
parent
commit
8805441321
7 changed files with 143 additions and 2570 deletions
  1. +2
    -2
      src/include/Makefile
  2. +122
    -0
      src/include/complex.h
  3. +14
    -67
      src/include/math.h
  4. +3
    -1
      src/include/stdlib.h
  5. +2
    -2
      src/lib/libc/stdlib/Makefile.inc
  6. +0
    -2459
      src/lib/libc/stdlib/strtod.c
  7. +0
    -39
      src/lib/libc/stdlib/strtof.c

+ 2
- 2
src/include/Makefile View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.145 2008/08/22 13:02:53 kettenis Exp $
# $OpenBSD: Makefile,v 1.146 2008/09/07 20:36:07 martynas Exp $
# $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $ # $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $
# @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91 # @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91
@ -12,7 +12,7 @@ USE_GCC3?=No
# Missing: mp.h # Missing: mp.h
FILES= a.out.h ar.h assert.h bitstring.h blf.h bm.h bsd_auth.h cast.h \ FILES= a.out.h ar.h assert.h bitstring.h blf.h bm.h bsd_auth.h cast.h \
cpio.h ctype.h curses.h db.h dbm.h des.h dirent.h disktab.h \
complex.h cpio.h ctype.h curses.h db.h dbm.h des.h dirent.h disktab.h \
dlfcn.h elf_abi.h err.h errno.h fnmatch.h fstab.h fts.h ftw.h getopt.h \ dlfcn.h elf_abi.h err.h errno.h fnmatch.h fstab.h fts.h ftw.h getopt.h \
glob.h grp.h ifaddrs.h inttypes.h iso646.h kvm.h langinfo.h \ glob.h grp.h ifaddrs.h inttypes.h iso646.h kvm.h langinfo.h \
libgen.h limits.h locale.h login_cap.h malloc.h math.h md4.h \ libgen.h limits.h locale.h login_cap.h malloc.h math.h md4.h \


+ 122
- 0
src/include/complex.h View File

@ -0,0 +1,122 @@
/* $OpenBSD: complex.h,v 1.1 2008/09/07 20:36:07 martynas Exp $ */
/*
* Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _COMPLEX_H_
#define _COMPLEX_H_
#include <sys/cdefs.h>
/*
* C99
*/
#ifdef __GNUC__
#if __STDC_VERSION__ < 199901
#define _Complex __complex__
#endif
#define _Complex_I 1.0fi
#endif
#define complex _Complex
/* XXX switch to _Imaginary_I */
#undef I
#define I _Complex_I
__BEGIN_DECLS
/*
* Double versions of C99 functions
*/
double complex cacos(double complex);
double complex casin(double complex);
double complex catan(double complex);
double complex ccos(double complex);
double complex csin(double complex);
double complex ctan(double complex);
double complex cacosh(double complex);
double complex casinh(double complex);
double complex catanh(double complex);
double complex ccosh(double complex);
double complex csinh(double complex);
double complex ctanh(double complex);
double complex cexp(double complex);
double complex clog(double complex);
double cabs(double complex);
double complex cpow(double complex, double complex);
double complex csqrt(double complex);
double carg(double complex);
double cimag(double complex);
double complex conj(double complex);
double complex cproj(double complex);
double creal(double complex);
/*
* Float versions of C99 functions
*/
float complex cacosf(float complex);
float complex casinf(float complex);
float complex catanf(float complex);
float complex ccosf(float complex);
float complex csinf(float complex);
float complex ctanf(float complex);
float complex cacoshf(float complex);
float complex casinhf(float complex);
float complex catanhf(float complex);
float complex ccoshf(float complex);
float complex csinhf(float complex);
float complex ctanhf(float complex);
float complex cexpf(float complex);
float complex clogf(float complex);
float cabsf(float complex);
float complex cpowf(float complex, float complex);
float complex csqrtf(float complex);
float cargf(float complex);
float cimagf(float complex);
float complex conjf(float complex);
float complex cprojf(float complex);
float crealf(float complex);
/*
* Long double versions of C99 functions
*/
#if 0
long double complex cacosl(long double complex);
long double complex casinl(long double complex);
long double complex catanl(long double complex);
long double complex ccosl(long double complex);
long double complex csinl(long double complex);
long double complex ctanl(long double complex);
long double complex cacoshl(long double complex);
long double complex casinhl(long double complex);
long double complex catanhl(long double complex);
long double complex ccoshl(long double complex);
long double complex csinhl(long double complex);
long double complex ctanhl(long double complex);
long double complex cexpl(long double complex);
long double complex clogl(long double complex);
long double cabsl(long double complex);
long double complex cpowl(long double complex,
long double complex);
long double complex csqrtl(long double complex);
long double cargl(long double complex);
long double cimagl(long double complex);
long double complex conjl(long double complex);
long double complex cprojl(long double complex);
long double creall(long double complex);
#endif
__END_DECLS
#endif _COMPLEX_H_ /* !_COMPLEX_H_ */

+ 14
- 67
src/include/math.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: math.h,v 1.20 2008/07/24 09:41:58 martynas Exp $ */
/* $OpenBSD: math.h,v 1.21 2008/09/07 20:36:07 martynas Exp $ */
/* /*
* ==================================================== * ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
@ -63,18 +63,6 @@ extern char __nan[];
: (sizeof (x) == sizeof (double)) ? \ : (sizeof (x) == sizeof (double)) ? \
__isfinite(x) \ __isfinite(x) \
: __isfinitel(x)) : __isfinitel(x))
#define isinf(x) \
((sizeof (x) == sizeof (float)) ? \
isinff(x) \
: (sizeof (x) == sizeof (double)) ? \
__isinf(x) \
: __isinfl(x))
#define isnan(x) \
((sizeof (x) == sizeof (float)) ? \
isnanf(x) \
: (sizeof (x) == sizeof (double)) ? \
__isnan(x) \
: __isnanl(x))
#define isnormal(x) \ #define isnormal(x) \
((sizeof (x) == sizeof (float)) ? \ ((sizeof (x) == sizeof (float)) ? \
__isnormalf(x) \ __isnormalf(x) \
@ -97,6 +85,19 @@ extern char __nan[];
#define isunordered(x, y) (isnan(x) || isnan(y)) #define isunordered(x, y) (isnan(x) || isnan(y))
#endif /* __ISO_C_VISIBLE >= 1999 */ #endif /* __ISO_C_VISIBLE >= 1999 */
#define isinf(x) \
((sizeof (x) == sizeof (float)) ? \
isinff(x) \
: (sizeof (x) == sizeof (double)) ? \
__isinf(x) \
: __isinfl(x))
#define isnan(x) \
((sizeof (x) == sizeof (float)) ? \
isnanf(x) \
: (sizeof (x) == sizeof (double)) ? \
__isnan(x) \
: __isnanl(x))
/* /*
* XOPEN/SVID * XOPEN/SVID
*/ */
@ -125,51 +126,7 @@ extern int signgam;
#endif /* __BSD_VISIBLE || __XPG_VISIBLE */ #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
#if __BSD_VISIBLE #if __BSD_VISIBLE
enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
#define _LIB_VERSION_TYPE enum fdversion
#define _LIB_VERSION _fdlib_version
/* if global variable _LIB_VERSION is not desirable, one may
* change the following to be a constant by:
* #define _LIB_VERSION_TYPE const enum version
* In that case, after one initializes the value _LIB_VERSION (see
* s_lib_version.c) during compile time, it cannot be modified
* in the middle of a program
*/
extern _LIB_VERSION_TYPE _LIB_VERSION;
#define _IEEE_ fdlibm_ieee
#define _SVID_ fdlibm_svid
#define _XOPEN_ fdlibm_xopen
#define _POSIX_ fdlibm_posix
#ifndef __cplusplus
struct exception {
int type;
char *name;
double arg1;
double arg2;
double retval;
};
#endif /* !__cplusplus */
#define HUGE MAXFLOAT #define HUGE MAXFLOAT
/*
* set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
* (one may replace the following line by "#include <values.h>")
*/
#define X_TLOSS 1.41484755040568800000e+16
#define DOMAIN 1
#define SING 2
#define OVERFLOW 3
#define UNDERFLOW 4
#define TLOSS 5
#define PLOSS 6
#endif /* __BSD_VISIBLE */ #endif /* __BSD_VISIBLE */
__BEGIN_DECLS __BEGIN_DECLS
@ -215,9 +172,7 @@ extern double exp2(double);
extern double expm1(double); extern double expm1(double);
extern int ilogb(double); extern int ilogb(double);
extern double log1p(double); extern double log1p(double);
#if 0
extern double log2(double); extern double log2(double);
#endif
extern double logb(double); extern double logb(double);
extern double scalbn(double, int); extern double scalbn(double, int);
#if 0 #if 0
@ -253,11 +208,9 @@ extern double nextafter(double, double);
extern double nexttoward(double, long double); extern double nexttoward(double, long double);
#endif #endif
#if 0
extern double fdim(double, double); extern double fdim(double, double);
extern double fmax(double, double); extern double fmax(double, double);
extern double fmin(double, double); extern double fmin(double, double);
#endif
#if 0 #if 0
extern double fma(double, double, double); extern double fma(double, double, double);
@ -292,10 +245,6 @@ extern int finite(double);
extern double gamma_r(double, int *); extern double gamma_r(double, int *);
extern double lgamma_r(double, int *); extern double lgamma_r(double, int *);
#ifdef __LIBM_PRIVATE
extern int matherr(struct exception *);
#endif /* __LIBM_PRIVATE */
/* /*
* IEEE Test Vector * IEEE Test Vector
*/ */
@ -375,11 +324,9 @@ extern float nextafterf(float, float);
extern float nexttowardf(float, long double); extern float nexttowardf(float, long double);
#endif #endif
#if 0
extern float fdimf(float, float); extern float fdimf(float, float);
extern float fmaxf(float, float); extern float fmaxf(float, float);
extern float fminf(float, float); extern float fminf(float, float);
#endif
#if 0 #if 0
extern float fmaf(float, float, float); extern float fmaf(float, float, float);


+ 3
- 1
src/include/stdlib.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: stdlib.h,v 1.44 2008/06/24 06:01:33 otto Exp $ */
/* $OpenBSD: stdlib.h,v 1.45 2008/09/07 20:36:07 martynas Exp $ */
/* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */ /* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */
/*- /*-
@ -132,6 +132,8 @@ void srand(unsigned);
double strtod(const char *, char **); double strtod(const char *, char **);
float strtof(const char *, char **); float strtof(const char *, char **);
long strtol(const char *, char **, int); long strtol(const char *, char **, int);
long double
strtold(const char *, char **);
unsigned long unsigned long
strtoul(const char *, char **, int); strtoul(const char *, char **, int);
int system(const char *); int system(const char *);


+ 2
- 2
src/lib/libc/stdlib/Makefile.inc View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile.inc,v 1.39 2008/08/22 17:14:56 otto Exp $
# $OpenBSD: Makefile.inc,v 1.40 2008/09/07 20:36:08 martynas Exp $
# stdlib sources # stdlib sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/stdlib ${LIBCSRCDIR}/stdlib .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/stdlib ${LIBCSRCDIR}/stdlib
@ -7,7 +7,7 @@ SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c atoll.c bsearch.c \
cfree.c exit.c ecvt.c gcvt.c getenv.c getopt_long.c \ cfree.c exit.c ecvt.c gcvt.c getenv.c getopt_long.c \
getsubopt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c l64a.c llabs.c \ getsubopt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c l64a.c llabs.c \
lldiv.c lsearch.c malloc.c merge.c putenv.c qsort.c radixsort.c rand.c \ lldiv.c lsearch.c malloc.c merge.c putenv.c qsort.c radixsort.c rand.c \
random.c realpath.c setenv.c strtoimax.c strtod.c strtof.c strtol.c \
random.c realpath.c setenv.c strtoimax.c strtol.c \
strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c system.c \ strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c system.c \
tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c lcong48.c \ tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c lcong48.c \
lrand48.c mrand48.c nrand48.c seed48.c srand48.c qabs.c qdiv.c _Exit.c lrand48.c mrand48.c nrand48.c seed48.c srand48.c qabs.c qdiv.c _Exit.c


+ 0
- 2459
src/lib/libc/stdlib/strtod.c
File diff suppressed because it is too large
View File


+ 0
- 39
src/lib/libc/stdlib/strtof.c View File

@ -1,39 +0,0 @@
/* $OpenBSD: strtof.c,v 1.1 2008/06/13 21:04:24 landry Exp $ */
/*
* Copyright (c) 2008 Landry Breuil
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
float
strtof(const char *s00, char **se)
{
double d;
d = strtod(s00, se);
if (d > FLT_MAX) {
errno = ERANGE;
return (FLT_MAX);
} else if (d < -FLT_MAX) {
errno = ERANGE;
return (-FLT_MAX);
}
return ((float) d);
}

Loading…
Cancel
Save