mirror of
https://github.com/reactos/reactos.git
synced 2024-09-05 18:26:53 +00:00
[CRT]
* Update MSVCRT_I10_OUTPUT(). CORE-8540 svn path=/trunk/; revision=64710
This commit is contained in:
parent
80ecfd75ed
commit
9144185ad8
|
@ -11,7 +11,7 @@ struct _I10_OUTPUT_DATA {
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* $I10_OUTPUT (MSVCRT.@)
|
* $I10_OUTPUT (MSVCRT.@)
|
||||||
* ld - long double to be printed to data
|
* ld80 - long double (Intel 80 bit FP in 12 bytes) to be printed to data
|
||||||
* prec - precision of part, we're interested in
|
* prec - precision of part, we're interested in
|
||||||
* flag - 0 for first prec digits, 1 for fractional part
|
* flag - 0 for first prec digits, 1 for fractional part
|
||||||
* data - data to be populated
|
* data - data to be populated
|
||||||
|
@ -24,16 +24,22 @@ struct _I10_OUTPUT_DATA {
|
||||||
* Native sets last byte of data->str to '0' or '9', I don't know what
|
* Native sets last byte of data->str to '0' or '9', I don't know what
|
||||||
* it means. Current implementation sets it always to '0'.
|
* it means. Current implementation sets it always to '0'.
|
||||||
*/
|
*/
|
||||||
int CDECL MSVCRT_I10_OUTPUT(long double ld, int prec, int flag, struct _I10_OUTPUT_DATA *data)
|
int CDECL MSVCRT_I10_OUTPUT(_LDOUBLE ld80, int prec, int flag, struct _I10_OUTPUT_DATA *data)
|
||||||
{
|
{
|
||||||
static const char inf_str[] = "1#INF";
|
static const char inf_str[] = "1#INF";
|
||||||
static const char nan_str[] = "1#QNAN";
|
static const char nan_str[] = "1#QNAN";
|
||||||
|
|
||||||
double d = ld;
|
/* MS' long double type wants 12 bytes for Intel's 80 bit FP format.
|
||||||
|
* Some UNIX have sizeof(long double) == 16, yet only 80 bit are used.
|
||||||
|
* Assume long double uses 80 bit FP, never seen 128 bit FP. */
|
||||||
|
long double ld = 0;
|
||||||
|
double d;
|
||||||
char format[8];
|
char format[8];
|
||||||
char buf[I10_OUTPUT_MAX_PREC+9]; /* 9 = strlen("0.e+0000") + '\0' */
|
char buf[I10_OUTPUT_MAX_PREC+9]; /* 9 = strlen("0.e+0000") + '\0' */
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
|
memcpy(&ld, &ld80, 10);
|
||||||
|
d = ld;
|
||||||
TRACE("(%lf %d %x %p)\n", d, prec, flag, data);
|
TRACE("(%lf %d %x %p)\n", d, prec, flag, data);
|
||||||
|
|
||||||
if(d<0) {
|
if(d<0) {
|
||||||
|
@ -59,7 +65,7 @@ int CDECL MSVCRT_I10_OUTPUT(long double ld, int prec, int flag, struct _I10_OUTP
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flag&1) {
|
if(flag&1) {
|
||||||
int exp = (int)(1+floor(log10(d)));
|
int exp = 1+floor(log10(d));
|
||||||
|
|
||||||
prec += exp;
|
prec += exp;
|
||||||
if(exp < 0)
|
if(exp < 0)
|
||||||
|
@ -83,7 +89,7 @@ int CDECL MSVCRT_I10_OUTPUT(long double ld, int prec, int flag, struct _I10_OUTP
|
||||||
data->pos++;
|
data->pos++;
|
||||||
|
|
||||||
for(p = buf+prec+1; p>buf+1 && *p=='0'; p--);
|
for(p = buf+prec+1; p>buf+1 && *p=='0'; p--);
|
||||||
data->len = (BYTE)(p - buf);
|
data->len = p-buf;
|
||||||
|
|
||||||
memcpy(data->str, buf+1, data->len);
|
memcpy(data->str, buf+1, data->len);
|
||||||
data->str[data->len] = '\0';
|
data->str[data->len] = '\0';
|
||||||
|
|
Loading…
Reference in a new issue