Various changes to crtdll, added some files to math and float

directory.

svn path=/trunk/; revision=281
This commit is contained in:
Boudewijn Dekker 1999-03-07 13:37:38 +00:00
parent 9fd228d402
commit 01f4ff78c5
75 changed files with 1103 additions and 115 deletions

View file

@ -1,16 +1,23 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crtdll/conio/putch.c
* PURPOSE: Writes a character to stdout
* FILE: lib/crtdll/ctype/isalnum.c
* PURPOSE: Test for a alpha numeric character
* PROGRAMER: Boudewijn Dekker
* UPDATE HISTORY:
* 28/12/98: Created
*/
#include <ctype.h>
#undef isalnum
int isalnum(int c)
{
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'));
return _isctype(c,_ALPHA | _DIGIT);
}
#undef iswalnum
int iswalnum(wint_t c)
{
return iswctype(c,_ALPHA | _DIGIT);
}

View file

@ -13,5 +13,11 @@
#undef isalpha
int isalpha(int c)
{
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
return _isctype(c,_ALPHA);
}
#undef iswalpha
int iswalpha(int c)
{
return iswctype(c,_ALPHA);
}

View file

@ -10,15 +10,14 @@
#include <ctype.h>
#undef isascii
int isascii(int c)
{
return ( (unsigned)(c) <0x80 ) ;
}
int __isascii(int c)
{
return ( (unsigned)(c) <0x80 ) ;
return (!((c)&(~0x7f))) ;
}
int iswascii(int c)
{
return __isascii(c);
}

View file

@ -4,5 +4,11 @@
#undef iscntrl
int iscntrl(int c)
{
return ((c >=0x00 && c <= 0x1f) || c == 0x7f) ;
return _isctype(c,_CONTROL);
}
#undef iswcntrl
int iswcntrl(int c)
{
return iswctype(c,_CONTROL);
}

View file

@ -1,9 +1,8 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crtdll/ctype/iscsym.c
* PURPOSE: Writes a character to stdout
* PURPOSE: Check for a valid characters in a c symbol
* PROGRAMER: Boudewijn Dekker
* UPDATE HISTORY:
* 28/12/98: Created
@ -11,30 +10,12 @@
#include <ctype.h>
#undef iscsym
int
iscsym (int c)
int __iscsymf(int c)
{
return __iscsym(c);
return (isalpha(c) || ( c == '_' )) ;
}
int
__iscsym (int c)
int __iscsym(int c)
{
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || ( c == '_' );
}
#undef iscsymf
int
iscsymf (int c)
{
return __iscsymf(c);
}
int
__iscsymf (int c)
{
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || ( c == '_' );
}
return (isalnum(c) || ( c == '_' )) ;
}

View file

@ -1,24 +1,25 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#define __dj_ISUPPER _UPPER
#define __dj_ISLOWER _LOWER
#define __dj_ISDIGIT _DIGIT
#define __dj_ISSPACE _SPACE
#define __dj_ISPUNCT _PUNCT
#define __dj_ISCNTRL _CONTROL
#define __dj_ISBLANK _BLANK
#define __dj_ISXDIGIT _HEX
#define __dj_ISALPHA _ALPHA
#define __dj_ISPRINT _PRINT
#define __dj_ISALNUM ( _ALPHA | _DIGIT )
#define __dj_ISGRAPH _GRAPH
#define __dj_ISUPPER 0x1
#define __dj_ISLOWER 0x2
#define __dj_ISDIGIT 0x4
#define __dj_ISSPACE 0x8
#define __dj_ISPUNCT 0x10
#define __dj_ISCNTRL 0x20
#define __dj_ISBLANK 0x40
#define __dj_ISXDIGIT 0x80
#define __dj_ISPRINT (__dj_ISBLANK|__dj_ISPUNCT|__dj_ISUPPER|__dj_ISLOWER|__dj_ISDIGIT)
#define __dj_ISALNUM (__dj_ISUPPER|__dj_ISLOWER|__dj_ISDIGIT)
#define __dj_ISGRAPH (__dj_ISPUNCT|__dj_ISUPPER|__dj_ISLOWER|__dj_ISDIGIT)
#define __dj_ISALPHA (0x0100|__dj_ISUPPER|__dj_ISLOWER)
int __mb_cur_max = 2;
// removed the first value
unsigned short __dj_ctype_flags[] = {
0, /* CTRL+?, 0xffff */
unsigned short _pctype_dll[] = {
__dj_ISCNTRL, /* CTRL+@, 0x00 */
__dj_ISCNTRL, /* CTRL+A, 0x01 */
__dj_ISCNTRL, /* CTRL+B, 0x02 */
@ -277,14 +278,27 @@ unsigned short __dj_ctype_flags[] = {
0, /* 0xff */
};
unsigned short *_ctype = _pctype_dll -1; // unused
unsigned short *_pwctype_dll = _pctype_dll;
int _isctype(int c, int t)
int _isctype(unsigned char c, int t)
{
return (__dj_ctype_flags[(c & 0xFF)]&t == t );
return ((_pctype_dll[(c & 0xFF)]&t) == t );
}
int iswctype(unsigned short c, int t)
{
return ((_pwctype_dll[(c & 0xFF)]&t) == t );
}
// obsolete
int is_wctype(unsigned short c, int t)
{
return ((_pctype_dll[(c & 0xFF)]&t) == t );
}
unsigned short *_pctype = __dj_ctype_flags;
int __mb_cur_max = 2;

View file

@ -4,5 +4,11 @@
#undef isdigit
int isdigit(int c)
{
return (c >= '0' && c <= '9');
return _isctype(c,_DIGIT);
}
#undef iswdigit
int iswdigit(int c)
{
return iswctype(c,_DIGIT);
}

View file

@ -4,5 +4,11 @@
#undef isgraph
int isgraph(int c)
{
return 0;
return _isctype(c,_GRAPH);
}
#undef iswgraph
int iswgraph(int c)
{
return iswctype(c,_GRAPH);
}

View file

@ -4,5 +4,10 @@
#undef islower
int islower(int c)
{
return (c >= 'a' && c <= 'z');
return _isctype((unsigned char)c,_LOWER);
}
int iswlower(int c)
{
return iswctype((unsigned short)c,_LOWER);
}

View file

@ -4,5 +4,10 @@
#undef isprint
int isprint(int c)
{
return c;
return _isctype((unsigned char)c,_PRINT);
}
int iswprint(int c)
{
return iswctype((unsigned short)c,_PRINT);
}

View file

@ -4,5 +4,11 @@
#undef ispunct
int ispunct(int c)
{
return (c == '.');
return _isctype(c,_PUNCT);
}
#undef iswpunct
int iswpunct(int c)
{
return iswctype(c,_PUNCT);
}

View file

@ -1,8 +1,22 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crtdll/ctype/isspace.c
* PURPOSE: Test for a space character
* PROGRAMER: Boudewijn Dekker
* UPDATE HISTORY:
* 28/12/98: Created
*/
#include <ctype.h>
#undef isspace
int isspace(int c)
{
return ( c == ' ' || c == '\t' );
return _isctype((unsigned char)c,_SPACE);
}
#undef iswspace
int iswspace(int c)
{
return iswctype((unsigned short)c,_SPACE);
}

View file

@ -4,5 +4,10 @@
#undef isupper
int isupper(int c)
{
return (c >= 'A' && c <= 'Z' );
return _isctype(c,_UPPER);
}
int iswupper(int c)
{
return iswctype(c,_UPPER);
}

View file

@ -4,5 +4,12 @@
#undef isxdigit
int isxdigit(int c)
{
return (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || ( c >= '0' && c >= '9' );
return _isctype(c,_HEX);
}
#undef iswxdigit
int iswxdigit(int c)
{
return iswctype(c,_HEX);
}

View file

@ -2,13 +2,8 @@
#include <ctype.h>
#undef toascii
int toascii(int c)
{
return (c);
}
int __toascii(int c)
{
return (c);
return ((unsigned)(c) & 0x7F );
}

View file

@ -5,3 +5,21 @@ int tolower(int c)
{
return (c >= 'A' && c <= 'Z') ? c - ( 'A' - 'a' ) : c;
}
#undef towlower
wchar_t towlower(wchar_t c)
{
return (c >= 'A' && c <= 'Z') ? c - ( 'A' - 'a' ) : c;
}
int _tolower(int c)
{
return (c >= 'A' && c <= 'Z') ? c - ( 'A' - 'a' ) : c;
}
wchar_t _towlower(wchar_t c)
{
return (c >= 'A' && c <= 'Z') ? c - ( 'A' - 'a' ) : c;
}

View file

@ -6,3 +6,18 @@ int toupper(int c)
{
return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c;
}
#undef towupper
int towupper(int c)
{
return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c;
}
int _toupper(int c)
{
return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c;
}
int _towupper(int c)
{
return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c;
}

View file

@ -0,0 +1,13 @@
#include <float.h>
unsigned int _clearfp (void)
{
unsigned short __res = _statusfp();
__asm__ __volatile__ (
"fclex \n\t"
);
return __res;
}

View file

@ -0,0 +1,37 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <float.h>
unsigned int _controlfp (unsigned int unNew, unsigned int unMask)
{
return _control87(unNew,unMask);
}
unsigned int _control87 (unsigned int unNew, unsigned int unMask)
{
register unsigned int __res;
__asm__ __volatile__ (
"pushl %%eax \n\t" /* make room on stack */
"fstcw (%%esp) \n\t"
"fwait \n\t"
"popl %%eax \n\t"
"andl $0xffff, %%eax \n\t" /* OK; we have the old value ready */
"movl %1, %%ecx \n\t"
"notl %%ecx \n\t"
"andl %%eax, %%ecx \n\t" /* the bits we want to keep */
"movl %2, %%edx \n\t"
"andl %1, %%edx \n\t" /* the bits we want to change */
"orl %%ecx, %%edx\n\t" /* the new value */
"pushl %%edx \n\t"
"fldcw (%%esp) \n\t"
"popl %%edx \n\t"
:"=a" (__res):"c" (unNew),"d" (unMask):"ax", "dx", "cx");
return __res;
}

View file

@ -1,7 +1,7 @@
#include <float.h>
void _fpreset( void )
void _fpreset (void)
{
__asm__ __volatile__("fninit\n\t");
return;
}
}

View file

@ -0,0 +1,14 @@
#include <float.h>
unsigned int _statusfp (void)
{
register unsigned short __res;
__asm__ __volatile__ (
"fstsw %0 \n\t"
// "movzwl %ax, %eax"
:"=a" (__res)
);
return __res;
}

View file

@ -4,7 +4,7 @@
int
_chmod(const char *filename, int func)
{
DWROD FileAttributes = 0;
DWORD FileAttributes = 0;
if ( func == _S_IREAD )
FileAttributes &= FILE_ATTRIBUTE_READONLY;
if ( ((func & _S_IREAD) == _S_IREAD) && ((func & _S_IWRITE) == _S_IWRITE) )

View file

@ -1,7 +1,10 @@
#include <windows.h>
#include <io.h>
unsigned int _commit(int _fd)
int _commit(int _fd)
{
return FlushFileBuffers(_get_osfhandle(_fd)) ? 0 : GetLastError();
if (! FlushFileBuffers(_get_osfhandle(_fd)) )
return -1;
return 0;
}

View file

@ -3,5 +3,17 @@
int _eof( int _fd )
{
int cur_pos = _lseek(_fd, 0, SEEK_CUR);
int end_pos = _filelength( _fd );
if ( cur_pos == -1 || end_pos == -1)
return -1;
if ( cur_pos == end_pos )
return 1;
return 0;
}

View file

@ -1,7 +1,7 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crtdll/conio/cputs.c
* FILE: lib/crtdll/io/open.c
* PURPOSE: Opens a file and translates handles to fileno
* PROGRAMER: Boudewijn Dekker
* UPDATE HISTORY:
@ -36,10 +36,6 @@ char __is_text_file(FILE *p) {
int __fileno_alloc(HANDLE hFile, int mode);
int _open(const char *_path, int _oflag,...)
{
@ -133,7 +129,7 @@ __fileno_alloc(HANDLE hFile, int mode)
for(i=minfno;i<maxfno;i++) {
if (fileno_modes[i].fd == -1 ) {
fileno_modes[i].fd = i;
fileno_modes[i].mode = 666;
fileno_modes[i].mode = mode;
fileno_modes[i].hFile = hFile;
return i;
}
@ -157,7 +153,7 @@ __fileno_alloc(HANDLE hFile, int mode)
/* Fill in the value */
fileno_modes[i].fd = i;
fileno_modes[i].mode = _fmode;
fileno_modes[i].mode = mode;
fileno_modes[i].hFile = hFile;
return i;
}

View file

@ -1,7 +1,26 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crtdll/io/pipe.c
* PURPOSE: Creates a pipe
* PROGRAMER: DJ Delorie
* UPDATE HISTORY:
* 28/12/98: Appropriated for Reactos
*/
#include <windows.h>
#include <io.h>
#include <libc/file.h>
int _pipe(int _fildes[2], unsigned int size, int mode )
{
return -1;
{
HANDLE hReadPipe, hWritePipe;
if ( !CreatePipe(&hReadPipe,&hWritePipe,NULL,size))
return -1;
_fildes[0] = __fileno_alloc(hReadPipe, mode);
_fildes[1] = __fileno_alloc(hWritePipe, mode);
return 0;
}

View file

@ -2,16 +2,18 @@
all: crtdll.a
CTYPE_OBJECTS = ctype/ct_flags.o ctype/ct_lower.o ctype/ct_upper.o ctype/isalnum.o \
CTYPE_OBJECTS = ctype/isalnum.o \
ctype/isalpha.o ctype/isascii.o ctype/iscntrl.o ctype/isdigit.o ctype/isgraph.o \
ctype/islower.o ctype/isprint.o ctype/ispunct.o ctype/isspace.o ctype/isupper.o \
ctype/isxdigit.o ctype/toascii.o ctype/tolower.o ctype/toupper.o
ctype/isxdigit.o ctype/toascii.o ctype/tolower.o ctype/toupper.o\
ctype/iscsym.o ctype/isctype.o
CONIO_OBJECTS = conio/cputs.o conio/getch.o conio/getche.o conio/putch.o conio/ungetch.o
DIRECT_OBJECTS = direct/chdir.o direct/chdrive.o direct/getcwd.o direct/getdrive.o \
direct/rmdir.o direct/mkdir.o direct/getdfree.o
MISC_OBJECTS = misc/sleep.o misc/getargs.o misc/crtfmode.o misc/crtglob.o
STRING_OBJECTS = string/memchr.o string/memcmp.o string/strcat.o \
@ -46,7 +48,9 @@ STDIO_OBJECTS = stdio/getenv.o stdio/doprnt.o stdio/doscan.o stdio/filbuf.o \
IO_OBJECTS = io/access.o io/close.o io/create.o io/dup.o io/dup2.o io/find.o io/isatty.o io/lseek.o \
io/open.o io/read.o io/setmode.o io/unlink.o io/write.o io/fmode.o io/mktemp.o
io/open.o io/read.o io/setmode.o io/unlink.o io/write.o io/fmode.o io/mktemp.o\
io/chmod.o io/chsize.o io/commit.o io/locking.o io/pipe.o io/sopen.o io/filelen.o\
io/umask.o io/tell.o io/eof.o
STDLIB_OBJECTS = stdlib/abort.o stdlib/abs.o stdlib/atexit.o stdlib/atof.o stdlib/atoi.o stdlib/atold.o \
stdlib/bsearch.o stdlib/div.o stdlib/errno.o stdlib/exit.o \
@ -55,22 +59,30 @@ STDLIB_OBJECTS = stdlib/abort.o stdlib/abs.o stdlib/atexit.o stdlib/atof.o stdli
stdlib/rand.o stdlib/senv.o stdlib/splitp.o stdlib/strtod.o stdlib/strtol.o \
stdlib/strtoul.o stdlib/strtold.o
PROCESS_OBJECTS = process/spawnl.o process/spawnlp.o process/spawnlpe.o process/spawnvpe.o process/spawnvp.o \
SIGNAL_OBJECTS = signal/signal.o
PROCESS_OBJECTS = process/cwait.o process/dll.o process/spawnl.o process/spawnlp.o process/spawnlpe.o process/spawnvpe.o process/spawnvp.o \
process/spawnv.o process/spawnve.o process/spawnle.o process/execl.o process/execlp.o process/execlpe.o \
process/execvpe.o process/execvp.o process/execv.o process/execle.o
TIME_OBJECTS = time/ctime.o time/difftime.o time/strftime.o
FLOAT_OBJECTS = float/fpreset.o
FLOAT_OBJECTS = float/fpreset.o float/clearfp.o float/cntrlfp.o float/statfp.o
SYS_STAT_OBJECTS = sys_stat/fstat.o sys_stat/stat.o
MATH_OBJECTS = math/acos.o math/acosh.o math/asin.o math/asinh.o math/atan.o math/atan2.o\
math/atanh.o math/ceil.o math/cos.o math/cosh.o math/exp.o math/fabs.o\
math/floor.o math/fmod.o math/frexp.o math/huge_val.o math/hypot.o\
math/ldexp.o math/log.o math/log10.o math/modf.o math/modfl.o math/pow.o\
math/pow10.o math/pow2.o math/sin.o math/sinh.o math/sqrt.o math/tan.o\
math/tanh.o
OBJECTS = $(CTYPE_OBJECTS) $(CONIO_OBJECTS) $(DIRECT_OBJECTS) $(MISC_OBJECTS) \
$(STRING_OBJECTS) $(STDIO_OBJECTS) $(STDLIB_OBJECTS) \
$(IO_OBJECTS) $(PROCESS_OBJECTS) $(TIME_OBJECTS) $(FLOAT_OBJECTS) \
$(SYS_STAT_OBJECTS)
$(IO_OBJECTS) $(PROCESS_OBJECTS) $(TIME_OBJECTS) \
$(SYS_STAT_OBJECTS) $(SIGNAL_OBJECTS) $(MATH_OBJECTS) $(FLOAT_OBJECTS)
crtdll.a: $(OBJECTS)

View file

@ -0,0 +1,22 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.text
LC0:
.double 0d1.00000000000000000000e+00
.globl _acos
_acos:
fldl 4(%esp)
fld1
fsubp %st(0),%st(1)
fsqrt
fldl 4(%esp)
fld1
faddp %st(0),%st(1)
fsqrt
fpatan
fld %st(0)
faddp
ret

View file

@ -0,0 +1,8 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double
acosh(double x)
{
return log(x + sqrt(x*x - 1));
}

View file

@ -0,0 +1,14 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.globl _asin
_asin:
fldl 4(%esp)
fld %st(0)
fmulp
fld1
fsubp
fsqrt
fldl 4(%esp)
fxch %st(1)
fpatan
ret

View file

@ -0,0 +1,9 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double
asinh(double x)
{
return x>0 ? log(x + sqrt(x*x + 1)) : -log(sqrt(x*x+1)-x);
}

View file

@ -0,0 +1,8 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.globl _atan
_atan:
fldl 4(%esp)
fld1
fpatan
ret

View file

@ -0,0 +1,35 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
.data
.align 2
nan:
.long 0xffffffff
.byte 0xff
.byte 0xff
.byte 0xff
.byte 0x7f
.text
.globl _atan2
_atan2:
fldl 4(%esp)
fldl 12(%esp)
ftst
fnstsw %ax
sahf
jne doit
fxch %st(1)
ftst
fnstsw %ax
sahf
je isanan
fxch %st(1)
doit:
fpatan
ret
isanan:
movl $1,_errno
fstp %st(0)
fstp %st(0)
fldl nan
ret

View file

@ -0,0 +1,8 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double
atanh(double x)
{
return log((1+x)/(1-x)) / 2.0;
}

View file

@ -0,0 +1,24 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
.globl _ceil
_ceil:
pushl %ebp
movl %esp,%ebp
subl $8,%esp /* -4 = old CW, -2 = new CW */
fstcw -4(%ebp)
fwait
movw -4(%ebp),%ax
andw $0xf3ff,%ax
orw $0x0800,%ax
movw %ax,-2(%ebp)
fldcww -2(%ebp)
fldl 8(%ebp)
frndint
fldcww -4(%ebp)
movl %ebp,%esp
popl %ebp
ret

View file

@ -0,0 +1,16 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
L0:
.quad 0xffffffffffffffff
.globl _cos
_cos:
fldl 4(%esp)
fcos
fstsw
sahf
jnp L1
fstp %st(0)
fldl L0
L1:
ret

View file

@ -0,0 +1,8 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double cosh(double x)
{
const double ebig = exp(fabs(x));
return (ebig + 1.0/ebig) / 2.0;
}

View file

@ -0,0 +1,32 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.data
LCW1:
.word 0
LCW2:
.word 0
LC0:
.double 0d1.0e+00
.text
.globl _exp
_exp:
fldl 4(%esp)
fldl2e
fmulp
fstcww LCW1
fstcww LCW2
fwait
andw $0xf3ff,LCW2
orw $0x0400,LCW2
fldcww LCW2
fldl %st(0)
frndint
fldcww LCW1
fxch %st(1)
fsub %st(1),%st
f2xm1
faddl LC0
fscale
fstp %st(1)
ret

View file

@ -0,0 +1,6 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.globl _fabs
_fabs:
fldl 4(%esp)
fabs
ret

View file

@ -0,0 +1,24 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
.globl _floor
_floor:
pushl %ebp
movl %esp,%ebp
subl $8,%esp /* -4 = old CW, -2 = new CW */
fstcw -4(%ebp)
fwait
movw -4(%ebp),%ax
andw $0xf3ff,%ax
orw $0x0400,%ax
movw %ax,-2(%ebp)
fldcww -2(%ebp)
fldl 8(%ebp)
frndint
fldcww -4(%ebp)
movl %ebp,%esp
popl %ebp
ret

View file

@ -0,0 +1,29 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.data
LCW1:
.word 0
.align 4
.text
.globl _fmod
_fmod:
fldl 4(%esp)
fldl 12(%esp)
ftst
fnstsw %ax
fxch %st(1)
sahf
jnz next
fstpl %st(0)
jmp out
next:
fpreml
fnstsw %ax
sahf
jpe next
fstpl %st(1)
out:
ret

View file

@ -0,0 +1,26 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double
frexp(double x, int *exptr)
{
union {
double d;
unsigned char c[8];
} u;
u.d = x;
/*
* The format of the number is:
* Sign, 12 exponent bits, 51 mantissa bits
* The exponent is 1023 biased and there is an implicit zero.
* We get the exponent from the upper bits and set the exponent
* to 0x3fe (1022).
*/
*exptr = (int)(((u.c[7] & 0x7f) << 4) | (u.c[6] >> 4)) - 1022;
u.c[7] &= 0x80;
u.c[7] |= 0x3f;
u.c[6] &= 0x0f;
u.c[6] |= 0xe0;
return u.d;
}

View file

@ -0,0 +1,4 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/ieee.h>
double_t _HUGE_dll = { 0x00000, 0x00000, 0x7ff, 0x0 };

View file

@ -0,0 +1,100 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* hypot() function for DJGPP.
*
* hypot() computes sqrt(x^2 + y^2). The problem with the obvious
* naive implementation is that it might fail for very large or
* very small arguments. For instance, for large x or y the result
* might overflow even if the value of the function should not,
* because squaring a large number might trigger an overflow. For
* very small numbers, their square might underflow and will be
* silently replaced by zero; this won't cause an exception, but might
* have an adverse effect on the accuracy of the result.
*
* This implementation tries to avoid the above pitfals, without
* inflicting too much of a performance hit.
*
*/
#include <float.h>
#include <math.h>
#include <errno.h>
/* Approximate square roots of DBL_MAX and DBL_MIN. Numbers
between these two shouldn't neither overflow nor underflow
when squared. */
#define __SQRT_DBL_MAX 1.3e+154
#define __SQRT_DBL_MIN 2.3e-162
double
hypot(double x, double y)
{
double abig = fabs(x), asmall = fabs(y);
double ratio;
/* Make abig = max(|x|, |y|), asmall = min(|x|, |y|). */
if (abig < asmall)
{
double temp = abig;
abig = asmall;
asmall = temp;
}
/* Trivial case. */
if (asmall == 0.)
return abig;
/* Scale the numbers as much as possible by using its ratio.
For example, if both ABIG and ASMALL are VERY small, then
X^2 + Y^2 might be VERY inaccurate due to loss of
significant digits. Dividing ASMALL by ABIG scales them
to a certain degree, so that accuracy is better. */
if ((ratio = asmall / abig) > __SQRT_DBL_MIN && abig < __SQRT_DBL_MAX)
return abig * sqrt(1.0 + ratio*ratio);
else
{
/* Slower but safer algorithm due to Moler and Morrison. Never
produces any intermediate result greater than roughly the
larger of X and Y. Should converge to machine-precision
accuracy in 3 iterations. */
double r = ratio*ratio, t, s, p = abig, q = asmall;
do {
t = 4. + r;
if (t == 4.)
break;
s = r / t;
p += 2. * s * p;
q *= s;
r = (q / p) * (q / p);
} while (1);
return p;
}
}
#ifdef TEST
#include <stdio.h>
int
main(void)
{
printf("hypot(3, 4) =\t\t\t %25.17e\n", hypot(3., 4.));
printf("hypot(3*10^150, 4*10^150) =\t %25.17g\n", hypot(3.e+150, 4.e+150));
printf("hypot(3*10^306, 4*10^306) =\t %25.17g\n", hypot(3.e+306, 4.e+306));
printf("hypot(3*10^-320, 4*10^-320) =\t %25.17g\n",
hypot(3.e-320, 4.e-320));
printf("hypot(0.7*DBL_MAX, 0.7*DBL_MAX) =%25.17g\n",
hypot(0.7*DBL_MAX, 0.7*DBL_MAX));
printf("hypot(DBL_MAX, 1.0) =\t\t %25.17g\n", hypot(DBL_MAX, 1.0));
printf("hypot(1.0, DBL_MAX) =\t\t %25.17g\n", hypot(1.0, DBL_MAX));
printf("hypot(0.0, DBL_MAX) =\t\t %25.17g\n", hypot(0.0, DBL_MAX));
return 0;
}
#endif

View file

@ -0,0 +1,32 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double
ldexp(double v, int e)
{
double two = 2.0;
if (e < 0)
{
e = -e; /* This just might overflow on two-complement machines. */
if (e < 0) return 0.0;
while (e > 0)
{
if (e & 1) v /= two;
two *= two;
e >>= 1;
}
}
else if (e > 0)
{
while (e > 0)
{
if (e & 1) v *= two;
two *= two;
e >>= 1;
}
}
return v;
}

View file

@ -0,0 +1,7 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.globl _log
_log:
fldln2
fldl 4(%esp)
fyl2x
ret

View file

@ -0,0 +1,7 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.globl _log10
_log10:
fldlg2
fldl 4(%esp)
fyl2x
ret

View file

@ -0,0 +1,33 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.text
.globl _modf
_modf:
pushl %ebp
movl %esp,%ebp
subl $16,%esp
pushl %ebx
fnstcw -4(%ebp)
fwait
movw -4(%ebp),%ax
orw $0x0c3f,%ax
movw %ax,-8(%ebp)
fldcw -8(%ebp)
fwait
fldl 8(%ebp)
frndint
fstpl -16(%ebp)
fwait
movl -16(%ebp),%edx
movl -12(%ebp),%ecx
movl 16(%ebp),%ebx
movl %edx,(%ebx)
movl %ecx,4(%ebx)
fldl 8(%ebp)
fsubl -16(%ebp)
leal -20(%ebp),%esp
fclex
fldcw -4(%ebp)
fwait
popl %ebx
leave
ret

View file

@ -0,0 +1,22 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.text
.globl ___modfl
___modfl:
pushl %ebp
movl %esp,%ebp
subl $4,%esp
fldt 8(%ebp)
movl 20(%ebp),%eax
fnstcw -2(%ebp)
movw -2(%ebp),%dx
orb $0x0c,%dh
movw %dx,-4(%ebp)
fldcw -4(%ebp)
fld %st(0)
frndint
fldcw -2(%ebp)
fld %st(0)
fstpt (%eax)
fsubrp %st,%st(1)
leave
ret

View file

@ -0,0 +1,86 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.data
yint:
.word 0,0
LCW1:
.word 0
LCW2:
.word 0
.text
LC0:
.double 0d1.0e+00
frac:
fstcww LCW1
fstcww LCW2
fwait
andw $0xf3ff,LCW2
orw $0x0400,LCW2
fldcww LCW2
fldl %st(0)
frndint
fldcww LCW1
fxch %st(1)
fsub %st(1),%st
ret
Lpow2:
call frac
f2xm1
faddl LC0
fscale
fstp %st(1)
ret
.globl _pow
_pow:
fldl 12(%esp)
fldl 4(%esp)
ftst
fnstsww %ax
sahf
jbe xltez
fyl2x
jmp Lpow2
xltez:
jb xltz
fstp %st(0)
ftst
fnstsww %ax
sahf
ja ygtz
jb error
fstp %st(0)
fld1l
fchs
error:
fsqrt
ret
ygtz:
fstp %st(0)
fldzl
ret
xltz:
fabs
fxch %st(1)
call frac
ftst
fnstsww %ax
fstp %st(0)
sahf
je yisint
fstp %st(0)
fchs
jmp error
yisint:
fistl yint
fxch %st(1)
fyl2x
call Lpow2
andl $1,yint
jz yeven
fchs
yeven:
ret

View file

@ -0,0 +1,32 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.data
LCW1:
.word 0
LCW2:
.word 0
LC0:
.double 0d1.0e+00
.text
.globl ___pow10
___pow10:
fldl 4(%esp)
fldl2t
fmulp
fstcww LCW1
fstcww LCW2
fwait
andw $0xf3ff,LCW2
orw $0x0400,LCW2
fldcww LCW2
fldl %st(0)
frndint
fldcww LCW1
fxch %st(1)
fsub %st(1),%st
f2xm1
faddl LC0
fscale
fstp %st(1)
ret

View file

@ -0,0 +1,30 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
.data
LCW1:
.word 0
LCW2:
.word 0
LC0:
.double 0d1.0e+00
.text
.globl ___pow2
___pow2:
fldl 4(%esp)
fstcww LCW1
fstcww LCW2
fwait
andw $0xf3ff,LCW2
orw $0x0400,LCW2
fldcww LCW2
fldl %st(0)
frndint
fldcww LCW1
fxch %st(1)
fsub %st(1),%st
f2xm1
faddl LC0
fscale
fstp %st(1)
ret

View file

@ -0,0 +1,16 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
L0:
.quad 0xffffffffffffffff
.globl _sin
_sin:
fldl 4(%esp)
fsin
fstsw
sahf
jnp L1
fstp %st(0)
fldl L0
L1:
ret

View file

@ -0,0 +1,16 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double sinh(double x)
{
if(x >= 0.0)
{
const double epos = exp(x);
return (epos - 1.0/epos) / 2.0;
}
else
{
const double eneg = exp(-x);
return (1.0/eneg - eneg) / 2.0;
}
}

View file

@ -0,0 +1,6 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.globl _sqrt
_sqrt:
fldl 4(%esp)
fsqrt
ret

View file

@ -0,0 +1,17 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
L0:
.quad 0xffffffffffffffff
.globl _tan
_tan:
fldl 4(%esp)
fptan
fstsw
fstp %st(0)
sahf
jnp L1
/* fstp %st(0) - if exception, there is nothing on the stack */
fldl L0
L1:
ret

View file

@ -0,0 +1,17 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double tanh(double x)
{
if (x > 50)
return 1;
else if (x < -50)
return -1;
else
{
const double ebig = exp(x);
const double esmall = 1.0/ebig;
return (ebig - esmall) / (ebig + esmall);
}
}

View file

@ -2,7 +2,11 @@
#include <stdio.h>
#include <libc/file.h>
#undef clearerr
#ifdef clearerr
#undef clearerr
void clearerr(FILE *stream);
#endif
void
clearerr(FILE *f)
{

View file

@ -6,12 +6,12 @@
#include <ctype.h>
#include <libc/file.h>
long double
_atold(const char *ascii);
//long double
//atold(const char *ascii);
#define atold atof
// dubious variable
int _fltused = 0;
//static int _fltused = 0;
int
_doscan_low(FILE *iop, int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *),
@ -58,6 +58,12 @@ _doscan(FILE *iop, const char *fmt, void **argp)
return(_doscan_low(iop, fgetc, ungetc, fmt, argp));
}
int
_dowscan(FILE *iop, const wchar_t *fmt, void **argp)
{
return(_doscan_low(iop, fgetwc, ungetwc, fmt, argp));
}
int
_doscan_low(FILE *iop, int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *),
const char *fmt, void **argp)
@ -290,7 +296,7 @@ _innum(int **ptr, int type, int len, int size, FILE *iop,
break;
case (FLOAT<<4) | LONGDOUBLE:
**(long double **)ptr = _atold(numbuf);
**(long double **)ptr = atold(numbuf);
break;
case (INT<<4) | SHORT:

View file

@ -1,6 +1,6 @@
#include <stdio.h>
FILE *fdopen(int handle, char *mode)
FILE *_fdopen(int handle, char *mode)
{
FILE *file;
int rw;
@ -52,4 +52,4 @@ FILE *fdopen(int handle, char *mode)

View file

@ -2,8 +2,11 @@
#include <stdio.h>
#include <libc/file.h>
#ifdef feof
#undef feof
int
feof(FILE *stream);
#endif
feof(FILE *stream)
{
return stream->_flag & _IOEOF;

View file

@ -2,7 +2,11 @@
#include <stdio.h>
#include <libc/file.h>
#ifdef ferror
#undef ferror
ferror(FILE *stream);
#endif
int
ferror(FILE *stream)
{

View file

@ -1,3 +1,13 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crtdll/stdio/fgetc.c
* PURPOSE: Get a character string from stdin
* PROGRAMER: Boudewijn Dekker
* UPDATE HISTORY:
* 28/12/98: Appropriated for Reactos
25/02/99: Added fgetwc
*/
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
@ -7,3 +17,9 @@ fgetc(FILE *f)
{
return getc(f);
}
int
fgetwc(FILE *f)
{
return getc(f);
}

View file

@ -10,6 +10,6 @@ fgetpos(FILE *stream, fpos_t *pos)
*pos = (fpos_t)ftell(stream);
return 0;
}
errno = EFAULT;
//errno = EFAULT;
return 1;
}

View file

@ -7,3 +7,9 @@ fputc(int c, FILE *fp)
{
return putc(c, fp);
}
int
fputwc(int c, FILE *fp)
{
return putc(c, fp);
}

View file

@ -13,3 +13,14 @@ fscanf(FILE *f, const char *fmt, ...)
va_end(a);
return r;
}
int
fwscanf(FILE *f, const wchar_t *fmt, ...)
{
int r;
va_list a=0;
va_start(a, fmt);
r = _dowscan(f, fmt,(void *) a);
va_end(a);
return r;
}

View file

@ -10,6 +10,6 @@ fsetpos(FILE *stream, fpos_t *pos)
fseek(stream, (long)(*pos), SEEK_SET);
return 0;
}
errno = EFAULT;
//errno = EFAULT;
return 1;
}

View file

@ -15,3 +15,5 @@ int getc(FILE *f)
return -1;
return c;
}

View file

@ -1,3 +1,12 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crtdll/stdio/gets.c
* PURPOSE: Get a character string from stdin
* PROGRAMER: DJ Delorie
* UPDATE HISTORY:
* 28/12/98: Appropriated for Reactos
*/
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>

View file

@ -4,6 +4,10 @@
#include <errno.h>
#ifdef perror
#undef perror
void perror(const char *s);
#endif
void
perror(const char *s)

View file

@ -4,15 +4,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <unistd.h>
#include <libc/file.h>
int __fileno_alloc(HANDLE hFile, int mode);
FILE *
_popen (const char *cm, const char *md) /* program name, pipe mode */
{
@ -36,10 +29,10 @@ _popen (const char *cm, const char *md) /* program name, pipe mode */
if ( *md == 'r' ) {
pf = _fdopen( __fileno_alloc(hReadPipe, O_RDONLY) , "r" );
pf = _fdopen( __fileno_alloc(hReadPipe, _fmode) , "r" );
}
else {
pf = _fdopen( __fileno_alloc(hWritePipe, _O_WRONLY) , "w" );
pf = _fdopen( __fileno_alloc(hWritePipe, _fmode) , "w" );
}
pf->name_to_remove = SpawnedProcess;

View file

@ -13,3 +13,15 @@ scanf(const char *fmt, ...)
va_end(a);
return r;
}
int
wscanf(const wchar_t *fmt, ...)
{
int r;
va_list a=0;
va_start(a, fmt);
r = _dowscan(stdin, fmt, a);
va_end(a);
return r;
}

View file

@ -24,3 +24,24 @@ sscanf(const char *str, const char *fmt, ...)
va_end(a);
return r;
}
int
swscanf(const wchar_t *str, const wchar_t *fmt, ...)
{
int r;
va_list a=0;
FILE _strbuf;
va_start(a, fmt);
_strbuf._flag = _IOREAD|_IOSTRG;
_strbuf._ptr = (char *)str;
_strbuf._base = (char *)str;
_strbuf._cnt = 0;
while (*str++)
_strbuf._cnt++;
_strbuf._bufsiz = _strbuf._cnt;
r = _dowscan(&_strbuf, fmt, a);
va_end(a);
return r;
}

View file

@ -4,7 +4,7 @@
FILE _iob[] =
FILE _crtdll_iob[] =
{
// stdin
{
@ -37,3 +37,5 @@ FILE _iob[] =
4, 0,0,NULL
}
};
FILE (*__imp__iob)[] = &_crtdll_iob;

View file

@ -1,7 +1,7 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
//#include <libc/local.h>
static void fcloseall_helper(FILE *f)
{