mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 01:24:38 +00:00
Replaced old version of printf and added some long long and
long double support. svn path=/trunk/; revision=393
This commit is contained in:
parent
a1418887c0
commit
6becb71b7c
15 changed files with 1072 additions and 920 deletions
|
@ -1,21 +1,70 @@
|
|||
/* Copyright (C) 1991, 1992, 1995 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <crtdll/math.h>
|
||||
#include <crtdll/float.h>
|
||||
#include <crtdll/internal/ieee.h>
|
||||
|
||||
|
||||
int _isnan(double x)
|
||||
int _isnan(double __x)
|
||||
{
|
||||
if ( x>= 0.0 && x < HUGE_VAL )
|
||||
return 0;
|
||||
else if ( x <= 0.0 && x > HUGE_VAL )
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
double_t * x = (double_t *)&__x;
|
||||
return ( x->exponent == 0x7ff && ( x->mantissah != 0 || x->mantissal != 0 ));
|
||||
}
|
||||
|
||||
int _isinf(double x)
|
||||
int _isnanl(long double __x)
|
||||
{
|
||||
if ( fabs(x) == HUGE_VAL )
|
||||
return 1;
|
||||
|
||||
/* Intel's extended format has the normally implicit 1 explicit
|
||||
present. Sigh! */
|
||||
|
||||
long_double_t * x = (long_double_t *)&__x;
|
||||
|
||||
|
||||
/* IEEE 854 NaN's have the maximum possible
|
||||
exponent and a nonzero mantissa. */
|
||||
|
||||
return (( x->exponent == 0x7fff)
|
||||
&& ( (x->mantissah & 0x80000000) != 0)
|
||||
&& ( (x->mantissah & (unsigned int)0x7fffffff) != 0 || x->mantissal != 0 ));
|
||||
}
|
||||
|
||||
|
||||
int _isinf(double __x)
|
||||
{
|
||||
double_t * x = (double_t *)&__x;
|
||||
return ( x->exponent == 0x7ff && ( x->mantissah == 0 && x->mantissal == 0 ));
|
||||
}
|
||||
|
||||
int _isinfl(long double __x)
|
||||
{
|
||||
/* Intel's extended format has the normally implicit 1 explicit
|
||||
present. Sigh! */
|
||||
|
||||
long_double_t * x = (long_double_t *)&__x;
|
||||
|
||||
|
||||
/* An IEEE 854 infinity has an exponent with the
|
||||
maximum possible value and a zero mantissa. */
|
||||
|
||||
|
||||
if ( x->exponent == 0x7fff && ( (x->mantissah == 0x80000000 ) && x->mantissal == 0 ))
|
||||
return x->sign ? -1 : 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ STDIO_OBJECTS = stdio/getenv.o stdio/filbuf.o \
|
|||
stdio/ungetc.o stdio/vfprintf.o stdio/vprintf.o \
|
||||
stdio/fdopen.o stdio/vsprintf.o stdio/frlist.o \
|
||||
|
||||
QUAD_OBJECTS = quad/qdivrem.o quad/divdi3.o quad/moddi3.o quad/udivdi3.o quad/umoddi3.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\
|
||||
|
@ -106,7 +107,7 @@ MATH_OBJECTS = math/acos.o math/acosh.o math/asin.o math/asinh.o math/atan.o mat
|
|||
# $(MISC_OBJECTS) $(STRING_OBJECTS) $(STDIO_OBJECTS) $(STDLIB_OBJECTS) \
|
||||
# $(IO_OBJECTS) $(PROCESS_OBJECTS) $(TIME_OBJECTS) $(MALLOC_OBJECTS)\
|
||||
# $(SYS_STAT_OBJECTS) $(SIGNAL_OBJECTS) $(MATH_OBJECTS) $(FLOAT_OBJECTS)\
|
||||
# $(SEARCH_OBJECTS)
|
||||
# $(SEARCH_OBJECTS) $(QUAD_OBJECTS)
|
||||
|
||||
|
||||
OLD_OBJECTS = $(MISC_OBJECTS) stdlib/malloc.o stdlib/abort.o \
|
||||
|
@ -115,7 +116,8 @@ OLD_OBJECTS = $(MISC_OBJECTS) stdlib/malloc.o stdlib/abort.o \
|
|||
stdio/vsprintf.o $(CTYPE_OBJECTS) stdlib/atoi.o stdlib/strtol.o \
|
||||
stdio/flsbuf.o stdio/putc.o stdio/vfprintf.o $(STRING_OBJECTS)\
|
||||
io/write.o io/isatty.o sys_stat/fstat.o misc/dllmain.o \
|
||||
stdlib/errno.o stdio/printf.o stdio/vprintf.o
|
||||
stdlib/errno.o stdio/printf.o stdio/vprintf.o\
|
||||
$(QUAD_OBJECTS)
|
||||
|
||||
OBJECTS = $(MISC_OBJECTS) $(STDLIB_OBJECTS) $(IO_OBJECTS) \
|
||||
$(FLOAT_OBJECTS) $(ASSERT_OBJECTS) $(PROCESS_OBJECTS) \
|
||||
|
|
|
@ -12,4 +12,10 @@ double ceil (double __x)
|
|||
__asm __volatile ("fldcw %0" : : "m" (__cw));
|
||||
|
||||
return __value;
|
||||
}
|
||||
|
||||
|
||||
long double ceill (long double __x)
|
||||
{
|
||||
return floor(__x)+1;
|
||||
}
|
|
@ -33,4 +33,18 @@ double floor (double __x)
|
|||
__asm __volatile ("fldcw %0" : : "m" (__cw));
|
||||
|
||||
return __value;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct IEEExp {
|
||||
unsigned manl:32;
|
||||
unsigned manh:32;
|
||||
unsigned exp:15;
|
||||
unsigned sign:1;
|
||||
} long_double_t;
|
||||
|
||||
long double floorl(long double x )
|
||||
{
|
||||
|
||||
return (long double)(long long int)x;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
|
||||
typedef struct {
|
||||
unsigned mantissal:32;
|
||||
unsigned mantissah:20;
|
||||
unsigned exponent:11;
|
||||
unsigned sign:1;
|
||||
} double_t;
|
||||
|
||||
#include <crtdll/internal/ieee.h>
|
||||
|
||||
#undef _HUGE
|
||||
double_t _HUGE = { 0x00000, 0x00000, 0x7ff, 0x0 };
|
||||
|
|
|
@ -1,25 +1,135 @@
|
|||
// from linux libc
|
||||
|
||||
|
||||
/* @(#)s_modf.c 1.3 95/01/18 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunSoft, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
|
||||
#include <crtdll/math.h>
|
||||
#include <crtdll/internal/ieee.h>
|
||||
|
||||
long double modfl(long double x,long double *pint);
|
||||
|
||||
/* Slooow version. */
|
||||
|
||||
double modf(double x,double *pint)
|
||||
//static const double one = 1.0;
|
||||
|
||||
double modf(double __x, double *__i)
|
||||
{
|
||||
if (x >= 0)
|
||||
*pint = floor(x);
|
||||
else
|
||||
*pint = ceil(x);
|
||||
return x - *pint;
|
||||
|
||||
double_t * x = (double_t *)&__x;
|
||||
double_t * iptr = ( double_t *)__i;
|
||||
|
||||
int j0;
|
||||
unsigned int i;
|
||||
j0 = x->exponent - 0x3ff; /* exponent of x */
|
||||
if(j0<20) { /* integer part in high x */
|
||||
if(j0<0) { /* |x|<1 */
|
||||
*__i = 0.0;
|
||||
iptr->sign = x->sign;
|
||||
return __x;
|
||||
} else {
|
||||
i = (0x000fffff)>>j0;
|
||||
iptr->sign = x->sign;
|
||||
iptr->exponent = x->exponent;
|
||||
iptr->mantissah = x->mantissah&(~i);
|
||||
iptr->mantissal = 0;
|
||||
if ( __x == *__i ) {
|
||||
__x = 0.0;
|
||||
x->sign = iptr->sign;
|
||||
return __x;
|
||||
}
|
||||
|
||||
return __x - *__i;
|
||||
}
|
||||
} else if (j0>51) { /* no fraction part */
|
||||
*__i = __x;
|
||||
if ( _isnan(__x) || _isinf(__x) )
|
||||
return __x;
|
||||
|
||||
|
||||
__x = 0.0;
|
||||
x->sign = iptr->sign;
|
||||
return __x;
|
||||
} else { /* fraction part in low x */
|
||||
|
||||
|
||||
i = ((unsigned)(0xffffffff))>>(j0-20);
|
||||
iptr->sign = x->sign;
|
||||
iptr->exponent = x->exponent;
|
||||
iptr->mantissah = x->mantissah;
|
||||
iptr->mantissal = x->mantissal&(~i);
|
||||
if ( __x == *__i ) {
|
||||
__x = 0.0;
|
||||
x->sign = iptr->sign;
|
||||
return __x;
|
||||
}
|
||||
return __x - *__i;
|
||||
}
|
||||
}
|
||||
|
||||
long double modfl(long double x,long double *pint)
|
||||
|
||||
long double modfl(long double __x, long double *__i)
|
||||
{
|
||||
if (x >= 0)
|
||||
*pint = floor(x);
|
||||
else
|
||||
*pint = ceil(x);
|
||||
return x - *pint;
|
||||
|
||||
|
||||
long_double_t * x = (long_double_t *)&__x;
|
||||
long_double_t * iptr = (long_double_t *)__i;
|
||||
|
||||
int j0;
|
||||
unsigned int i;
|
||||
j0 = x->exponent - 0x3fff; /* exponent of x */
|
||||
|
||||
|
||||
if(j0<32) { /* integer part in high x */
|
||||
if(j0<0) { /* |x|<1 */
|
||||
*__i = 0.0;
|
||||
iptr->sign = x->sign;
|
||||
return __x;
|
||||
} else {
|
||||
|
||||
i = ((unsigned int)(0xffffffff))>>(j0);
|
||||
iptr->sign = x->sign;
|
||||
iptr->exponent = x->exponent;
|
||||
iptr->mantissah = x->mantissah&((~i));
|
||||
iptr->mantissal = 0;
|
||||
if ( __x == *__i ) {
|
||||
__x = 0.0;
|
||||
x->sign = iptr->sign;
|
||||
return __x;
|
||||
}
|
||||
|
||||
return __x - *__i;
|
||||
}
|
||||
} else if (j0>63) { /* no fraction part */
|
||||
*__i = __x;
|
||||
if ( _isnanl(__x) || _isinfl(__x) )
|
||||
return __x;
|
||||
|
||||
__x = 0.0;
|
||||
x->sign = iptr->sign;
|
||||
return __x;
|
||||
} else { /* fraction part in low x */
|
||||
|
||||
|
||||
i = ((unsigned int)(0xffffffff))>>(j0-32);
|
||||
iptr->sign = x->sign;
|
||||
iptr->exponent = x->exponent;
|
||||
iptr->mantissah = x->mantissah;
|
||||
iptr->mantissal = x->mantissal&(~i);
|
||||
if ( __x == *__i ) {
|
||||
__x = 0.0;
|
||||
x->sign = iptr->sign;
|
||||
return __x;
|
||||
}
|
||||
return __x - *__i;
|
||||
|
||||
|
||||
}
|
||||
}
|
66
reactos/lib/crtdll/quad/divdi3.c
Normal file
66
reactos/lib/crtdll/quad/divdi3.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This software was developed by the Computer Systems Engineering group
|
||||
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
||||
* contributed to Berkeley.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*
|
||||
* $Id: divdi3.c,v 1.1 1999/04/17 09:10:23 ariadne Exp $
|
||||
*/
|
||||
|
||||
#include <crtdll/internal/quad.h>
|
||||
|
||||
/*
|
||||
* Divide two signed quads.
|
||||
* ??? if -1/2 should produce -1 on this machine, this code is wrong
|
||||
*/
|
||||
quad_t
|
||||
__divdi3(a, b)
|
||||
quad_t a, b;
|
||||
{
|
||||
u_quad_t ua, ub, uq;
|
||||
int neg;
|
||||
|
||||
if (a < 0)
|
||||
ua = -(u_quad_t)a, neg = 1;
|
||||
else
|
||||
ua = a, neg = 0;
|
||||
if (b < 0)
|
||||
ub = -(u_quad_t)b, neg ^= 1;
|
||||
else
|
||||
ub = b;
|
||||
uq = __qdivrem(ua, ub, (u_quad_t *)0);
|
||||
return (neg ? -uq : uq);
|
||||
}
|
||||
|
||||
|
||||
|
65
reactos/lib/crtdll/quad/moddi3.c
Normal file
65
reactos/lib/crtdll/quad/moddi3.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This software was developed by the Computer Systems Engineering group
|
||||
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
||||
* contributed to Berkeley.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*
|
||||
* $Id: moddi3.c,v 1.1 1999/04/17 09:10:23 ariadne Exp $
|
||||
*/
|
||||
|
||||
#include <crtdll/internal/quad.h>
|
||||
|
||||
/*
|
||||
* Return remainder after dividing two signed quads.
|
||||
*
|
||||
* XXX
|
||||
* If -1/2 should produce -1 on this machine, this code is wrong.
|
||||
*/
|
||||
quad_t
|
||||
__moddi3(a, b)
|
||||
quad_t a, b;
|
||||
{
|
||||
u_quad_t ua, ub, ur;
|
||||
int neg;
|
||||
|
||||
if (a < 0)
|
||||
ua = -(u_quad_t)a, neg = 1;
|
||||
else
|
||||
ua = a, neg = 0;
|
||||
if (b < 0)
|
||||
ub = -(u_quad_t)b, neg ^= 1;
|
||||
else
|
||||
ub = b;
|
||||
(void)__qdivrem(ua, ub, &ur);
|
||||
return (neg ? -ur : ur);
|
||||
}
|
281
reactos/lib/crtdll/quad/qdivrem.c
Normal file
281
reactos/lib/crtdll/quad/qdivrem.c
Normal file
|
@ -0,0 +1,281 @@
|
|||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This software was developed by the Computer Systems Engineering group
|
||||
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
||||
* contributed to Berkeley.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*
|
||||
* $Id: qdivrem.c,v 1.1 1999/04/17 09:10:23 ariadne Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
* Multiprecision divide. This algorithm is from Knuth vol. 2 (2nd ed),
|
||||
* section 4.3.1, pp. 257--259.
|
||||
*/
|
||||
|
||||
#include <crtdll/internal/quad.h>
|
||||
|
||||
#define B (1 << HALF_BITS) /* digit base */
|
||||
|
||||
/* Combine two `digits' to make a single two-digit number. */
|
||||
#define COMBINE(a, b) (((u_long)(a) << HALF_BITS) | (b))
|
||||
|
||||
/* select a type for digits in base B: use unsigned short if they fit */
|
||||
//#if (ULONG_MAX == 0xffffffff && USHRT_MAX >= 0xffff)
|
||||
//typedef unsigned short digit;
|
||||
//#else
|
||||
typedef u_long digit;
|
||||
//#endif
|
||||
|
||||
/*
|
||||
* Shift p[0]..p[len] left `sh' bits, ignoring any bits that
|
||||
* `fall out' the left (there never will be any such anyway).
|
||||
* We may assume len >= 0. NOTE THAT THIS WRITES len+1 DIGITS.
|
||||
*/
|
||||
static void
|
||||
shl(register digit *p, register int len, register int sh)
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
p[i] = LHALF(p[i] << sh) | (p[i + 1] >> (HALF_BITS - sh));
|
||||
p[i] = LHALF(p[i] << sh);
|
||||
}
|
||||
|
||||
/*
|
||||
* __qdivrem(u, v, rem) returns u/v and, optionally, sets *rem to u%v.
|
||||
*
|
||||
* We do this in base 2-sup-HALF_BITS, so that all intermediate products
|
||||
* fit within u_long. As a consequence, the maximum length dividend and
|
||||
* divisor are 4 `digits' in this base (they are shorter if they have
|
||||
* leading zeros).
|
||||
*/
|
||||
u_quad_t
|
||||
__qdivrem(uq, vq, arq)
|
||||
u_quad_t uq, vq, *arq;
|
||||
{
|
||||
union uu tmp;
|
||||
digit *u, *v, *q;
|
||||
register digit v1, v2;
|
||||
u_long qhat, rhat, t;
|
||||
int m, n, d, j, i;
|
||||
digit uspace[5], vspace[5], qspace[5];
|
||||
|
||||
/*
|
||||
* Take care of special cases: divide by zero, and u < v.
|
||||
*/
|
||||
if (vq == 0) {
|
||||
/* divide by zero. */
|
||||
static volatile const unsigned int zero = 0;
|
||||
|
||||
tmp.ul[H] = tmp.ul[L] = 1 / zero;
|
||||
if (arq)
|
||||
*arq = uq;
|
||||
return (tmp.q);
|
||||
}
|
||||
if (uq < vq) {
|
||||
if (arq)
|
||||
*arq = uq;
|
||||
return (0);
|
||||
}
|
||||
u = &uspace[0];
|
||||
v = &vspace[0];
|
||||
q = &qspace[0];
|
||||
|
||||
/*
|
||||
* Break dividend and divisor into digits in base B, then
|
||||
* count leading zeros to determine m and n. When done, we
|
||||
* will have:
|
||||
* u = (u[1]u[2]...u[m+n]) sub B
|
||||
* v = (v[1]v[2]...v[n]) sub B
|
||||
* v[1] != 0
|
||||
* 1 < n <= 4 (if n = 1, we use a different division algorithm)
|
||||
* m >= 0 (otherwise u < v, which we already checked)
|
||||
* m + n = 4
|
||||
* and thus
|
||||
* m = 4 - n <= 2
|
||||
*/
|
||||
tmp.uq = uq;
|
||||
u[0] = 0;
|
||||
u[1] = HHALF(tmp.ul[H]);
|
||||
u[2] = LHALF(tmp.ul[H]);
|
||||
u[3] = HHALF(tmp.ul[L]);
|
||||
u[4] = LHALF(tmp.ul[L]);
|
||||
tmp.uq = vq;
|
||||
v[1] = HHALF(tmp.ul[H]);
|
||||
v[2] = LHALF(tmp.ul[H]);
|
||||
v[3] = HHALF(tmp.ul[L]);
|
||||
v[4] = LHALF(tmp.ul[L]);
|
||||
for (n = 4; v[1] == 0; v++) {
|
||||
if (--n == 1) {
|
||||
u_long rbj; /* r*B+u[j] (not root boy jim) */
|
||||
digit q1, q2, q3, q4;
|
||||
|
||||
/*
|
||||
* Change of plan, per exercise 16.
|
||||
* r = 0;
|
||||
* for j = 1..4:
|
||||
* q[j] = floor((r*B + u[j]) / v),
|
||||
* r = (r*B + u[j]) % v;
|
||||
* We unroll this completely here.
|
||||
*/
|
||||
t = v[2]; /* nonzero, by definition */
|
||||
q1 = u[1] / t;
|
||||
rbj = COMBINE(u[1] % t, u[2]);
|
||||
q2 = rbj / t;
|
||||
rbj = COMBINE(rbj % t, u[3]);
|
||||
q3 = rbj / t;
|
||||
rbj = COMBINE(rbj % t, u[4]);
|
||||
q4 = rbj / t;
|
||||
if (arq)
|
||||
*arq = rbj % t;
|
||||
tmp.ul[H] = COMBINE(q1, q2);
|
||||
tmp.ul[L] = COMBINE(q3, q4);
|
||||
return (tmp.q);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* By adjusting q once we determine m, we can guarantee that
|
||||
* there is a complete four-digit quotient at &qspace[1] when
|
||||
* we finally stop.
|
||||
*/
|
||||
for (m = 4 - n; u[1] == 0; u++)
|
||||
m--;
|
||||
for (i = 4 - m; --i >= 0;)
|
||||
q[i] = 0;
|
||||
q += 4 - m;
|
||||
|
||||
/*
|
||||
* Here we run Program D, translated from MIX to C and acquiring
|
||||
* a few minor changes.
|
||||
*
|
||||
* D1: choose multiplier 1 << d to ensure v[1] >= B/2.
|
||||
*/
|
||||
d = 0;
|
||||
for (t = v[1]; t < B / 2; t <<= 1)
|
||||
d++;
|
||||
if (d > 0) {
|
||||
shl(&u[0], m + n, d); /* u <<= d */
|
||||
shl(&v[1], n - 1, d); /* v <<= d */
|
||||
}
|
||||
/*
|
||||
* D2: j = 0.
|
||||
*/
|
||||
j = 0;
|
||||
v1 = v[1]; /* for D3 -- note that v[1..n] are constant */
|
||||
v2 = v[2]; /* for D3 */
|
||||
do {
|
||||
register digit uj0, uj1, uj2;
|
||||
|
||||
/*
|
||||
* D3: Calculate qhat (\^q, in TeX notation).
|
||||
* Let qhat = min((u[j]*B + u[j+1])/v[1], B-1), and
|
||||
* let rhat = (u[j]*B + u[j+1]) mod v[1].
|
||||
* While rhat < B and v[2]*qhat > rhat*B+u[j+2],
|
||||
* decrement qhat and increase rhat correspondingly.
|
||||
* Note that if rhat >= B, v[2]*qhat < rhat*B.
|
||||
*/
|
||||
uj0 = u[j + 0]; /* for D3 only -- note that u[j+...] change */
|
||||
uj1 = u[j + 1]; /* for D3 only */
|
||||
uj2 = u[j + 2]; /* for D3 only */
|
||||
if (uj0 == v1) {
|
||||
qhat = B;
|
||||
rhat = uj1;
|
||||
goto qhat_too_big;
|
||||
} else {
|
||||
u_long n = COMBINE(uj0, uj1);
|
||||
qhat = n / v1;
|
||||
rhat = n % v1;
|
||||
}
|
||||
while (v2 * qhat > COMBINE(rhat, uj2)) {
|
||||
qhat_too_big:
|
||||
qhat--;
|
||||
if ((rhat += v1) >= B)
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* D4: Multiply and subtract.
|
||||
* The variable `t' holds any borrows across the loop.
|
||||
* We split this up so that we do not require v[0] = 0,
|
||||
* and to eliminate a final special case.
|
||||
*/
|
||||
for (t = 0, i = n; i > 0; i--) {
|
||||
t = u[i + j] - v[i] * qhat - t;
|
||||
u[i + j] = LHALF(t);
|
||||
t = (B - HHALF(t)) & (B - 1);
|
||||
}
|
||||
t = u[j] - t;
|
||||
u[j] = LHALF(t);
|
||||
/*
|
||||
* D5: test remainder.
|
||||
* There is a borrow if and only if HHALF(t) is nonzero;
|
||||
* in that (rare) case, qhat was too large (by exactly 1).
|
||||
* Fix it by adding v[1..n] to u[j..j+n].
|
||||
*/
|
||||
if (HHALF(t)) {
|
||||
qhat--;
|
||||
for (t = 0, i = n; i > 0; i--) { /* D6: add back. */
|
||||
t += u[i + j] + v[i];
|
||||
u[i + j] = LHALF(t);
|
||||
t = HHALF(t);
|
||||
}
|
||||
u[j] = LHALF(u[j] + t);
|
||||
}
|
||||
q[j] = qhat;
|
||||
} while (++j <= m); /* D7: loop on j. */
|
||||
|
||||
/*
|
||||
* If caller wants the remainder, we have to calculate it as
|
||||
* u[m..m+n] >> d (this is at most n digits and thus fits in
|
||||
* u[m+1..m+n], but we may need more source digits).
|
||||
*/
|
||||
if (arq) {
|
||||
if (d) {
|
||||
for (i = m + n; i > m; --i)
|
||||
u[i] = (u[i] >> d) |
|
||||
LHALF(u[i - 1] << (HALF_BITS - d));
|
||||
u[i] = 0;
|
||||
}
|
||||
tmp.ul[H] = COMBINE(uspace[1], uspace[2]);
|
||||
tmp.ul[L] = COMBINE(uspace[3], uspace[4]);
|
||||
*arq = tmp.q;
|
||||
}
|
||||
|
||||
tmp.ul[H] = COMBINE(qspace[1], qspace[2]);
|
||||
tmp.ul[L] = COMBINE(qspace[3], qspace[4]);
|
||||
return (tmp.q);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
52
reactos/lib/crtdll/quad/udivdi3.c
Normal file
52
reactos/lib/crtdll/quad/udivdi3.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This software was developed by the Computer Systems Engineering group
|
||||
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
||||
* contributed to Berkeley.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*
|
||||
* $Id: udivdi3.c,v 1.1 1999/04/17 09:10:23 ariadne Exp $
|
||||
*/
|
||||
|
||||
#include <crtdll/internal/quad.h>
|
||||
|
||||
/*
|
||||
* Divide two unsigned quads.
|
||||
*/
|
||||
u_quad_t
|
||||
__udivdi3(a, b)
|
||||
u_quad_t a, b;
|
||||
{
|
||||
|
||||
return (__qdivrem(a, b, (u_quad_t *)0));
|
||||
}
|
54
reactos/lib/crtdll/quad/umoddi3.c
Normal file
54
reactos/lib/crtdll/quad/umoddi3.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This software was developed by the Computer Systems Engineering group
|
||||
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
||||
* contributed to Berkeley.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*
|
||||
* $Id: umoddi3.c,v 1.1 1999/04/17 09:10:23 ariadne Exp $
|
||||
*/
|
||||
|
||||
#include <crtdll/internal/quad.h>
|
||||
|
||||
/*
|
||||
* Return remainder after dividing two unsigned quads.
|
||||
*/
|
||||
u_quad_t
|
||||
__umoddi3(a, b)
|
||||
u_quad_t a, b;
|
||||
{
|
||||
u_quad_t r;
|
||||
|
||||
(void)__qdivrem(a, b, &r);
|
||||
return (r);
|
||||
}
|
||||
|
|
@ -1,19 +1,34 @@
|
|||
#include <windows.h>
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/wchar.h>
|
||||
#include <crtdll/errno.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
|
||||
int getc(FILE *fp)
|
||||
{
|
||||
if(fp->_cnt > 0) {
|
||||
fp->_cnt--;
|
||||
return (int)*fp->_ptr++;
|
||||
}
|
||||
else {
|
||||
return _filbuf(fp);
|
||||
}
|
||||
return -1;
|
||||
|
||||
// check for invalid stream
|
||||
|
||||
if ( (int)fp == NULL ) {
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
// check for read access on stream
|
||||
|
||||
// if ( (fp->_flag & _IOREAD) != _IOREAD ) {
|
||||
// __set_errno(EINVAL);
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
if(fp->_cnt > 0) {
|
||||
fp->_cnt--;
|
||||
return (int)*fp->_ptr++;
|
||||
}
|
||||
else {
|
||||
return _filbuf(fp);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// not exported
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <windows.h>
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/wchar.h>
|
||||
#include <crtdll/errno.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
int putc(int c, FILE *fp)
|
||||
|
@ -9,10 +10,22 @@ int putc(int c, FILE *fp)
|
|||
if ( c == 0 )
|
||||
c = ' ';
|
||||
|
||||
// check for fp == NULL and for putc(fp,c)
|
||||
|
||||
if ( (int)fp < 256 ) {
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
// check for write access on fp
|
||||
|
||||
// if ( (fp->_flag & _IOWRT) != _IOWRT ) {
|
||||
// __set_errno(EINVAL);
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
if (fp->_cnt > 0 ) {
|
||||
fp->_cnt--;
|
||||
*(fp)->_ptr++ = (char)c;
|
||||
*(fp)->_ptr = 0;
|
||||
return (int)c;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -11,34 +11,34 @@ FILE _crtdll_iob[5] =
|
|||
{
|
||||
NULL, 0, NULL,
|
||||
_IOREAD | _IOLBF ,
|
||||
0, 0,0, NULL, 0
|
||||
0, 0,0, NULL
|
||||
},
|
||||
// stdout
|
||||
{
|
||||
NULL, 0, NULL,
|
||||
_IOWRT | _IOLBF |_IOSTRG,
|
||||
1,0,0, NULL, 0
|
||||
1,0,0, NULL
|
||||
},
|
||||
// stderr
|
||||
{
|
||||
NULL, 0, NULL,
|
||||
_IOWRT | _IONBF,
|
||||
2,0,0, NULL, 0
|
||||
2,0,0, NULL
|
||||
},
|
||||
// stdaux
|
||||
{
|
||||
NULL, 0, NULL,
|
||||
_IORW | _IONBF,
|
||||
3,0,0, NULL, 0
|
||||
3,0,0, NULL
|
||||
},
|
||||
// stdprn
|
||||
{
|
||||
NULL, 0, NULL,
|
||||
_IOWRT | _IONBF,
|
||||
4, 0,0,NULL, 0
|
||||
4, 0,0,NULL
|
||||
}
|
||||
};
|
||||
|
||||
FILE (*_iob)[] = &_crtdll_iob;
|
||||
|
||||
FILE (*__imp__iob)[] = &_crtdll_iob;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue