mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-26 15:59:04 +00:00
Add long double printf formatting support
You can now easily print numbers that have 80 bits of precision. This change also imports many of the test vectors from the gdtoa codebase.
This commit is contained in:
parent
dae0583ee5
commit
1c387727fe
9 changed files with 808 additions and 287 deletions
examples
libc
test/libc
third_party/gdtoa
|
@ -11,7 +11,8 @@
|
|||
#include "libc/stdio/stdio.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
volatile double x = 123;
|
||||
printf("cos(%g) is %g\n", x, cos(x));
|
||||
volatile long double x = -.5;
|
||||
volatile long double y = 1.5;
|
||||
printf("atan2l(%.19Lg, %.19Lg) is %.19Lg\n", x, y, atan2l(x, y));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,20 +1,28 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright (C) 2022 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright (C) 1997, 1999, 2001 Lucent Technologies │
|
||||
│ All Rights Reserved │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or 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. │
|
||||
│ Permission to use, copy, modify, and distribute this software and │
|
||||
│ its documentation for any purpose and without fee is hereby │
|
||||
│ granted, provided that the above copyright notice appear in all │
|
||||
│ copies and that both that the copyright notice and this │
|
||||
│ permission notice and warranty disclaimer appear in supporting │
|
||||
│ documentation, and that the name of Lucent or any of its entities │
|
||||
│ not be used in advertising or publicity pertaining to │
|
||||
│ distribution of the software without specific, written prior │
|
||||
│ permission. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, │
|
||||
│ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. │
|
||||
│ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY │
|
||||
│ SPECIAL, 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 "libc/assert.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
|
@ -24,60 +32,252 @@
|
|||
#include "libc/nexgen32e/bsr.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
|
||||
static const char kSpecialFloats[2][2][4] = {{"INF", "inf"}, {"NAN", "nan"}};
|
||||
/**
|
||||
* @fileoverview Floating-Point Formatting
|
||||
*
|
||||
* This implements most of ANSI C's printf floating-point directives.
|
||||
* omitting L, with %.0g and %.0G giving the shortest decimal string
|
||||
* that rounds to the number being converted, and with negative
|
||||
* precisions allowed for %f.
|
||||
*/
|
||||
|
||||
static void __fmt_free_dtoa(char **mem) {
|
||||
if (*mem) {
|
||||
freedtoa(*mem);
|
||||
*mem = 0;
|
||||
struct FPBits {
|
||||
uint32_t bits[4];
|
||||
const FPI *fpi;
|
||||
int sign;
|
||||
int ex; // exponent
|
||||
int kind;
|
||||
};
|
||||
|
||||
union U {
|
||||
double d;
|
||||
uint64_t q;
|
||||
long double ld;
|
||||
unsigned int ui[4];
|
||||
unsigned short us[5];
|
||||
};
|
||||
|
||||
static const FPI kFpiDbl = {
|
||||
.nbits = 53,
|
||||
.emin = 1 - 1023 - 53 + 1,
|
||||
.emax = 2046 - 1023 - 53 + 1,
|
||||
.rounding = FPI_Round_near,
|
||||
.sudden_underflow = 0,
|
||||
};
|
||||
|
||||
static const FPI kFpiLdbl = {
|
||||
.nbits = 64,
|
||||
.emin = 1 - 16383 - 64 + 1,
|
||||
.emax = 32766 - 16383 - 64 + 1,
|
||||
.rounding = FPI_Round_near,
|
||||
.sudden_underflow = 0,
|
||||
};
|
||||
|
||||
static const char kSpecialFloats[2][2][4] = {
|
||||
{"INF", "inf"},
|
||||
{"NAN", "nan"},
|
||||
};
|
||||
|
||||
static void dfpbits(union U *u, struct FPBits *b) {
|
||||
int ex, i;
|
||||
uint32_t *bits;
|
||||
b->fpi = &kFpiDbl;
|
||||
b->sign = u->ui[1] & 0x80000000L;
|
||||
bits = b->bits;
|
||||
bits[1] = u->ui[1] & 0xfffff;
|
||||
bits[0] = u->ui[0];
|
||||
if ((ex = (u->ui[1] & 0x7ff00000L) >> 20) != 0) {
|
||||
if (ex == 0x7ff) {
|
||||
// Infinity or NaN
|
||||
i = bits[0] | bits[1] ? STRTOG_NaN : STRTOG_Infinite;
|
||||
} else {
|
||||
i = STRTOG_Normal;
|
||||
bits[1] |= 0x100000;
|
||||
}
|
||||
} else if (bits[0] | bits[1]) {
|
||||
i = STRTOG_Denormal;
|
||||
ex = 1;
|
||||
} else {
|
||||
i = STRTOG_Zero;
|
||||
}
|
||||
b->kind = i;
|
||||
b->ex = ex - (0x3ff + 52);
|
||||
}
|
||||
|
||||
static void xfpbits(union U *u, struct FPBits *b) {
|
||||
uint32_t *bits;
|
||||
int ex, i;
|
||||
b->fpi = &kFpiLdbl;
|
||||
b->sign = u->us[4] & 0x8000;
|
||||
bits = b->bits;
|
||||
bits[1] = ((unsigned)u->us[3] << 16) | u->us[2];
|
||||
bits[0] = ((unsigned)u->us[1] << 16) | u->us[0];
|
||||
if ((ex = u->us[4] & 0x7fff) != 0) {
|
||||
i = STRTOG_Normal;
|
||||
if (ex == 0x7fff) // Infinity or NaN
|
||||
i = bits[0] | bits[1] ? STRTOG_NaN : STRTOG_Infinite;
|
||||
} else if (bits[0] | bits[1]) {
|
||||
i = STRTOG_Denormal;
|
||||
ex = 1;
|
||||
} else {
|
||||
i = STRTOG_Zero;
|
||||
}
|
||||
b->kind = i;
|
||||
b->ex = ex - (0x3fff + 63);
|
||||
}
|
||||
|
||||
// returns number of hex digits minus 1, or 0 for zero
|
||||
static int fpiprec(struct FPBits *b) {
|
||||
FPI *fpi;
|
||||
int i, j, k, m;
|
||||
uint32_t *bits;
|
||||
if (b->kind == STRTOG_Zero) return (b->ex = 0);
|
||||
fpi = b->fpi;
|
||||
bits = b->bits;
|
||||
for (k = (fpi->nbits - 1) >> 2; k > 0; --k) {
|
||||
if ((bits[k >> 3] >> 4 * (k & 7)) & 0xf) {
|
||||
m = k >> 3;
|
||||
for (i = 0; i <= m; ++i)
|
||||
if (bits[i]) {
|
||||
if (i > 0) {
|
||||
k -= 8 * i;
|
||||
b->ex += 32 * i;
|
||||
for (j = i; j <= m; ++j) {
|
||||
bits[j - i] = bits[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < 28 && !((bits[0] >> i) & 0xf); i += 4) donothing;
|
||||
if (i) {
|
||||
b->ex += i;
|
||||
m = k >> 3;
|
||||
k -= (i >> 2);
|
||||
for (j = 0;; ++j) {
|
||||
bits[j] >>= i;
|
||||
if (j == m) break;
|
||||
bits[j] |= bits[j + 1] << (32 - i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
// round to prec hex digits after the "."
|
||||
// prec1 = incoming precision (after ".")
|
||||
static int bround(struct FPBits *b, int prec, int prec1) {
|
||||
uint32_t *bits, t;
|
||||
int i, inc, j, k, m, n;
|
||||
m = prec1 - prec;
|
||||
bits = b->bits;
|
||||
inc = 0;
|
||||
k = m - 1;
|
||||
if ((t = bits[k >> 3] >> (j = (k & 7) * 4)) & 8) {
|
||||
if (t & 7) goto inc1;
|
||||
if (j && bits[k >> 3] << (32 - j)) goto inc1;
|
||||
while (k >= 8) {
|
||||
k -= 8;
|
||||
if (bits[k >> 3]) {
|
||||
inc1:
|
||||
inc = 1;
|
||||
goto haveinc;
|
||||
}
|
||||
}
|
||||
}
|
||||
haveinc:
|
||||
b->ex += m * 4;
|
||||
i = m >> 3;
|
||||
k = prec1 >> 3;
|
||||
j = i;
|
||||
if ((n = 4 * (m & 7)))
|
||||
for (;; ++j) {
|
||||
bits[j - i] = bits[j] >> n;
|
||||
if (j == k) break;
|
||||
bits[j - i] |= bits[j + 1] << (32 - n);
|
||||
}
|
||||
else
|
||||
for (;; ++j) {
|
||||
bits[j - i] = bits[j];
|
||||
if (j == k) break;
|
||||
}
|
||||
k = prec >> 3;
|
||||
if (inc) {
|
||||
for (j = 0; !(++bits[j] & 0xffffffff); ++j) donothing;
|
||||
if (j > k) {
|
||||
onebit:
|
||||
bits[0] = 1;
|
||||
b->ex += 4 * prec;
|
||||
return 1;
|
||||
}
|
||||
if ((j = prec & 7) < 7 && bits[k] >> (j + 1) * 4) goto onebit;
|
||||
}
|
||||
for (i = 0; !(bits[i >> 3] & (0xf << 4 * (i & 7))); ++i) donothing;
|
||||
if (i) {
|
||||
b->ex += 4 * i;
|
||||
prec -= i;
|
||||
j = i >> 3;
|
||||
i &= 7;
|
||||
i *= 4;
|
||||
for (m = j;; ++m) {
|
||||
bits[m - j] = bits[m] >> i;
|
||||
if (m == k) break;
|
||||
bits[m - j] |= bits[m + 1] << (32 - i);
|
||||
}
|
||||
}
|
||||
return prec;
|
||||
}
|
||||
|
||||
int __fmt_dtoa(int (*out)(const char *, void *, size_t), void *arg, int d,
|
||||
int flags, int prec, int sign, int width, bool longdouble,
|
||||
char qchar, unsigned char signbit, const char *alphabet,
|
||||
va_list va) {
|
||||
union {
|
||||
double d;
|
||||
uint32_t u[2];
|
||||
uint64_t q;
|
||||
} pun;
|
||||
double x;
|
||||
union U u;
|
||||
struct FPBits fpb;
|
||||
char *s, *q, *se, *s0, special[8];
|
||||
int c, k, i1, ui, bw, bex, sgn, prec1, decpt;
|
||||
char *s, *p, *q, *se, *mem, special[8];
|
||||
mem = 0;
|
||||
x = 0;
|
||||
switch (d) {
|
||||
case 'F':
|
||||
case 'f':
|
||||
if (!(flags & FLAGS_PRECISION)) prec = 6;
|
||||
if (longdouble) {
|
||||
pun.d = va_arg(va, long double);
|
||||
if (!longdouble) {
|
||||
x = va_arg(va, double);
|
||||
s = s0 = dtoa(x, 3, prec, &decpt, &fpb.sign, &se);
|
||||
if (decpt == 9999) {
|
||||
if (s && s[0] == 'N') {
|
||||
fpb.kind = STRTOG_NaN;
|
||||
} else {
|
||||
fpb.kind = STRTOG_Infinite;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pun.d = va_arg(va, double);
|
||||
u.ld = va_arg(va, long double);
|
||||
xfpbits(&u, &fpb);
|
||||
s = s0 =
|
||||
gdtoa(fpb.fpi, fpb.ex, fpb.bits, &fpb.kind, 3, prec, &decpt, &se);
|
||||
}
|
||||
FormatDtoa:
|
||||
assert(!mem);
|
||||
s = mem = dtoa(pun.d, 3, prec, &decpt, &sgn, &se);
|
||||
if (decpt == 9999) {
|
||||
Format9999:
|
||||
if (s0) freedtoa(s0);
|
||||
bzero(special, sizeof(special));
|
||||
p = q = special;
|
||||
if (sgn) {
|
||||
s = q = special;
|
||||
if (fpb.sign) {
|
||||
*q++ = '-';
|
||||
} else if (flags & FLAGS_PLUS) {
|
||||
*q++ = '+';
|
||||
} else if (flags & FLAGS_SPACE) {
|
||||
*q++ = ' ';
|
||||
}
|
||||
memcpy(q, kSpecialFloats[*s == 'N'][d >= 'a'], 4);
|
||||
FormatThatThing:
|
||||
__fmt_free_dtoa(&mem);
|
||||
mem = 0;
|
||||
memcpy(q, kSpecialFloats[fpb.kind == STRTOG_NaN][d >= 'a'], 4);
|
||||
flags &= ~(FLAGS_PRECISION | FLAGS_PLUS | FLAGS_HASH | FLAGS_SPACE);
|
||||
prec = 0;
|
||||
flags &= ~(FLAGS_PRECISION | FLAGS_PLUS | FLAGS_SPACE);
|
||||
goto FormatString;
|
||||
return __fmt_stoa(out, arg, s, flags, prec, width, signbit, qchar);
|
||||
}
|
||||
FormatReal:
|
||||
if (sgn) sign = '-';
|
||||
if (fpb.sign /* && (x || sign) */) sign = '-';
|
||||
if (prec > 0) width -= prec;
|
||||
if (width > 0) {
|
||||
if (sign) --width;
|
||||
|
@ -87,26 +287,23 @@ int __fmt_dtoa(int (*out)(const char *, void *, size_t), void *arg, int d,
|
|||
} else {
|
||||
if (s == se) decpt = 1;
|
||||
width -= decpt;
|
||||
if (prec > 0) --width;
|
||||
if (prec > 0 || (flags & FLAGS_HASH)) --width;
|
||||
}
|
||||
}
|
||||
if (width > 0 && !(flags & FLAGS_LEFT)) {
|
||||
if (flags & FLAGS_ZEROPAD) {
|
||||
if ((flags & FLAGS_ZEROPAD)) {
|
||||
if (sign) __FMT_PUT(sign);
|
||||
sign = 0;
|
||||
do
|
||||
__FMT_PUT('0');
|
||||
do __FMT_PUT('0');
|
||||
while (--width > 0);
|
||||
} else {
|
||||
do
|
||||
__FMT_PUT(' ');
|
||||
} else
|
||||
do __FMT_PUT(' ');
|
||||
while (--width > 0);
|
||||
}
|
||||
}
|
||||
if (sign) __FMT_PUT(sign);
|
||||
if (decpt <= 0) {
|
||||
__FMT_PUT('0');
|
||||
if (prec > 0) __FMT_PUT('.');
|
||||
if (prec > 0 || (flags & FLAGS_HASH)) __FMT_PUT('.');
|
||||
while (decpt < 0) {
|
||||
__FMT_PUT('0');
|
||||
prec--;
|
||||
|
@ -121,7 +318,7 @@ int __fmt_dtoa(int (*out)(const char *, void *, size_t), void *arg, int d,
|
|||
}
|
||||
__FMT_PUT(c);
|
||||
} while (--decpt > 0);
|
||||
if (prec > 0) __FMT_PUT('.');
|
||||
if (prec > 0 || (flags & FLAGS_HASH)) __FMT_PUT('.');
|
||||
}
|
||||
while (--prec >= 0) {
|
||||
if ((c = *s)) {
|
||||
|
@ -131,61 +328,77 @@ int __fmt_dtoa(int (*out)(const char *, void *, size_t), void *arg, int d,
|
|||
}
|
||||
__FMT_PUT(c);
|
||||
}
|
||||
while (--width >= 0) {
|
||||
__FMT_PUT(' ');
|
||||
}
|
||||
__fmt_free_dtoa(&mem);
|
||||
while (--width >= 0) __FMT_PUT(' ');
|
||||
if (s0) freedtoa(s0);
|
||||
break;
|
||||
|
||||
case 'G':
|
||||
case 'g':
|
||||
if (!(flags & FLAGS_PRECISION)) prec = 6;
|
||||
if (longdouble) {
|
||||
pun.d = va_arg(va, long double);
|
||||
} else {
|
||||
pun.d = va_arg(va, double);
|
||||
}
|
||||
if (prec < 0) prec = 0;
|
||||
assert(!mem);
|
||||
s = mem = dtoa(pun.d, prec ? 2 : 0, prec, &decpt, &sgn, &se);
|
||||
if (!longdouble) {
|
||||
x = va_arg(va, double);
|
||||
s = s0 = dtoa(x, prec ? 2 : 0, prec, &decpt, &fpb.sign, &se);
|
||||
if (decpt == 9999) {
|
||||
if (s && s[0] == 'N') {
|
||||
fpb.kind = STRTOG_NaN;
|
||||
} else {
|
||||
fpb.kind = STRTOG_Infinite;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
u.ld = va_arg(va, long double);
|
||||
xfpbits(&u, &fpb);
|
||||
s = s0 = gdtoa(fpb.fpi, fpb.ex, fpb.bits, &fpb.kind, prec ? 2 : 0, prec,
|
||||
&decpt, &se);
|
||||
}
|
||||
if (decpt == 9999) goto Format9999;
|
||||
c = se - s;
|
||||
prec1 = prec;
|
||||
if (!prec) {
|
||||
prec = c;
|
||||
prec1 = c + (s[1] ? 5 : 4);
|
||||
prec1 = c + (s[1] || (flags & FLAGS_HASH) ? 5 : 4);
|
||||
// %.0g gives 10 rather than 1e1
|
||||
}
|
||||
if (decpt > -4 && decpt <= prec1) {
|
||||
prec = c - decpt;
|
||||
if ((flags & FLAGS_HASH))
|
||||
prec -= decpt;
|
||||
else
|
||||
prec = c - decpt;
|
||||
if (prec < 0) prec = 0;
|
||||
goto FormatReal;
|
||||
}
|
||||
d -= 2;
|
||||
if (prec > c) prec = c;
|
||||
if (!(flags & FLAGS_HASH) && prec > c) prec = c;
|
||||
--prec;
|
||||
goto FormatExpo;
|
||||
|
||||
case 'e':
|
||||
case 'E':
|
||||
if (!(flags & FLAGS_PRECISION)) prec = 6;
|
||||
if (longdouble) {
|
||||
pun.d = va_arg(va, long double);
|
||||
} else {
|
||||
pun.d = va_arg(va, double);
|
||||
}
|
||||
if (prec < 0) prec = 0;
|
||||
if (!dtoa) {
|
||||
p = "?";
|
||||
goto FormatThatThing;
|
||||
if (!longdouble) {
|
||||
x = va_arg(va, double);
|
||||
s = s0 = dtoa(x, prec ? 2 : 0, prec + 1, &decpt, &fpb.sign, &se);
|
||||
if (decpt == 9999) {
|
||||
if (s && s[0] == 'N') {
|
||||
fpb.kind = STRTOG_NaN;
|
||||
} else {
|
||||
fpb.kind = STRTOG_Infinite;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
u.ld = va_arg(va, long double);
|
||||
xfpbits(&u, &fpb);
|
||||
s = s0 = gdtoa(fpb.fpi, fpb.ex, fpb.bits, &fpb.kind, prec ? 2 : 0, prec,
|
||||
&decpt, &se);
|
||||
}
|
||||
assert(!mem);
|
||||
s = mem = dtoa(pun.d, 2, prec + 1, &decpt, &sgn, &se);
|
||||
if (decpt == 9999) goto Format9999;
|
||||
FormatExpo:
|
||||
if (sgn) sign = '-';
|
||||
if (fpb.sign /* && (x || sign) */) sign = '-';
|
||||
if ((width -= prec + 5) > 0) {
|
||||
if (sign) --width;
|
||||
if (prec) --width;
|
||||
if (prec || (flags & FLAGS_HASH)) --width;
|
||||
}
|
||||
if ((c = --decpt) < 0) c = -c;
|
||||
while (c >= 100) {
|
||||
|
@ -193,38 +406,32 @@ int __fmt_dtoa(int (*out)(const char *, void *, size_t), void *arg, int d,
|
|||
c /= 10;
|
||||
}
|
||||
if (width > 0 && !(flags & FLAGS_LEFT)) {
|
||||
if (flags & FLAGS_ZEROPAD) {
|
||||
if ((flags & FLAGS_ZEROPAD)) {
|
||||
if (sign) __FMT_PUT(sign);
|
||||
sign = 0;
|
||||
do
|
||||
__FMT_PUT('0');
|
||||
do __FMT_PUT('0');
|
||||
while (--width > 0);
|
||||
} else {
|
||||
do
|
||||
__FMT_PUT(' ');
|
||||
} else
|
||||
do __FMT_PUT(' ');
|
||||
while (--width > 0);
|
||||
}
|
||||
}
|
||||
if (sign) __FMT_PUT(sign);
|
||||
__FMT_PUT(*s++);
|
||||
if (prec) __FMT_PUT('.');
|
||||
if (prec || (flags & FLAGS_HASH)) __FMT_PUT('.');
|
||||
while (--prec >= 0) {
|
||||
if ((c = *s)) {
|
||||
if ((c = *s))
|
||||
s++;
|
||||
} else {
|
||||
else
|
||||
c = '0';
|
||||
}
|
||||
__FMT_PUT(c);
|
||||
}
|
||||
__fmt_free_dtoa(&mem);
|
||||
__FMT_PUT(d);
|
||||
if (decpt < 0) {
|
||||
__FMT_PUT('-');
|
||||
decpt = -decpt;
|
||||
} else {
|
||||
} else
|
||||
__FMT_PUT('+');
|
||||
}
|
||||
for (c = 2, k = 10; 10 * k <= decpt; c++) k *= 10;
|
||||
for (c = 2, k = 10; 10 * k <= decpt; c++, k *= 10) donothing;
|
||||
for (;;) {
|
||||
i1 = decpt / k;
|
||||
__FMT_PUT(i1 + '0');
|
||||
|
@ -232,99 +439,33 @@ int __fmt_dtoa(int (*out)(const char *, void *, size_t), void *arg, int d,
|
|||
decpt -= i1 * k;
|
||||
decpt *= 10;
|
||||
}
|
||||
while (--width >= 0) {
|
||||
__FMT_PUT(' ');
|
||||
}
|
||||
while (--width >= 0) __FMT_PUT(' ');
|
||||
freedtoa(s0);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
alphabet = "0123456789abcdefpx";
|
||||
goto FormatBinary;
|
||||
case 'A':
|
||||
alphabet = "0123456789ABCDEFPX";
|
||||
goto FormatBinary;
|
||||
case 'a':
|
||||
alphabet = "0123456789abcdefpx";
|
||||
FormatBinary:
|
||||
if (longdouble) {
|
||||
pun.d = va_arg(va, long double);
|
||||
u.ld = va_arg(va, long double);
|
||||
xfpbits(&u, &fpb);
|
||||
} else {
|
||||
pun.d = va_arg(va, double);
|
||||
u.d = va_arg(va, double);
|
||||
dfpbits(&u, &fpb);
|
||||
}
|
||||
if ((pun.u[1] & 0x7ff00000) == 0x7ff00000) {
|
||||
goto FormatDtoa;
|
||||
if (fpb.kind == STRTOG_Infinite || fpb.kind == STRTOG_NaN) {
|
||||
s0 = 0;
|
||||
goto Format9999;
|
||||
}
|
||||
if (pun.u[1] & 0x80000000) {
|
||||
sign = '-';
|
||||
pun.u[1] &= 0x7fffffff;
|
||||
}
|
||||
if (pun.d) {
|
||||
c = '1';
|
||||
bex = (pun.u[1] >> 20) - 1023;
|
||||
pun.u[1] &= 0xfffff;
|
||||
if (bex == -1023) {
|
||||
++bex;
|
||||
if (pun.u[1]) {
|
||||
do {
|
||||
--bex;
|
||||
pun.u[1] <<= 1;
|
||||
if (pun.u[0] & 0x80000000) pun.u[1] |= 1;
|
||||
pun.u[0] <<= 1;
|
||||
} while (pun.u[1] < 0x100000);
|
||||
} else {
|
||||
while (!(pun.u[0] & 0x80000000)) {
|
||||
--bex;
|
||||
pun.u[0] <<= 1;
|
||||
}
|
||||
bex -= 21;
|
||||
pun.u[1] = pun.u[0] >> 11;
|
||||
pun.u[0] <<= 21;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c = '0';
|
||||
bex = 0;
|
||||
}
|
||||
if (flags & FLAGS_PRECISION) {
|
||||
if (prec > 13) prec = 13;
|
||||
if (pun.d && prec < 13) {
|
||||
pun.u[1] |= 0x100000;
|
||||
if (prec < 5) {
|
||||
ui = 1u << ((5 - prec) * 4 - 1);
|
||||
if (pun.u[1] & ui) {
|
||||
if (pun.u[1] & ((ui - 1) | (ui << 1)) || pun.u[0]) {
|
||||
pun.u[1] += ui;
|
||||
BexCheck:
|
||||
if (pun.u[1] & 0x200000) {
|
||||
++bex;
|
||||
pun.u[1] >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (prec == 5) {
|
||||
if (pun.u[0] & 0x80000000) {
|
||||
BumpIt:
|
||||
++pun.u[1];
|
||||
goto BexCheck;
|
||||
}
|
||||
} else {
|
||||
i1 = (13 - prec) * 4;
|
||||
ui = 1u << (i1 - 1);
|
||||
if (pun.u[0] & ui && pun.u[0] & ((ui - 1) | (ui << 1))) {
|
||||
pun.u[0] += ui;
|
||||
if (!(pun.u[0] >> i1)) goto BumpIt;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((ui = pun.u[0])) {
|
||||
ui = __builtin_ctz(ui);
|
||||
prec = 6 + ((32 - ROUNDDOWN(ui, 4)) >> 2) - 1;
|
||||
} else if ((ui = pun.u[1] & 0xfffff)) {
|
||||
ui = __builtin_ctz(ui);
|
||||
prec = (20 - ROUNDDOWN(ui, 4)) >> 2;
|
||||
} else {
|
||||
prec = 0;
|
||||
}
|
||||
prec1 = fpiprec(&fpb);
|
||||
if ((flags & FLAGS_PRECISION) && prec < prec1) {
|
||||
prec1 = bround(&fpb, prec, prec1);
|
||||
}
|
||||
bw = 1;
|
||||
bex = fpb.ex + 4 * prec1;
|
||||
if (bex) {
|
||||
if ((i1 = bex) < 0) i1 = -i1;
|
||||
while (i1 >= 10) {
|
||||
|
@ -332,49 +473,51 @@ int __fmt_dtoa(int (*out)(const char *, void *, size_t), void *arg, int d,
|
|||
i1 /= 10;
|
||||
}
|
||||
}
|
||||
if (pun.u[1] & 0x80000000) {
|
||||
pun.u[1] &= 0x7fffffff;
|
||||
if (pun.d || sign) sign = '-';
|
||||
if (fpb.sign /* && (sign || fpb.kind != STRTOG_Zero) */) {
|
||||
sign = '-';
|
||||
}
|
||||
if ((width -= bw + 5) > 0) {
|
||||
if (sign) --width;
|
||||
if (prec) --width;
|
||||
if (prec1 || (flags & FLAGS_HASH)) --width;
|
||||
}
|
||||
if (pun.q && prec > 0) {
|
||||
width -= ROUNDUP(bsrl(pun.q) + 1, 4) >> 2;
|
||||
}
|
||||
if (width > 0 && !(flags & FLAGS_LEFT)) {
|
||||
if (flags & FLAGS_ZEROPAD) {
|
||||
if (sign) {
|
||||
__FMT_PUT(sign);
|
||||
sign = 0;
|
||||
}
|
||||
do
|
||||
__FMT_PUT('0');
|
||||
while (--width > 0);
|
||||
} else {
|
||||
do
|
||||
__FMT_PUT(' ');
|
||||
while (--width > 0);
|
||||
}
|
||||
if ((width -= prec1) > 0 && !(flags & FLAGS_LEFT) &&
|
||||
!(flags & FLAGS_ZEROPAD)) {
|
||||
do __FMT_PUT(' ');
|
||||
while (--width > 0);
|
||||
}
|
||||
if (sign) __FMT_PUT(sign);
|
||||
__FMT_PUT('0');
|
||||
__FMT_PUT(alphabet[17]);
|
||||
__FMT_PUT(c);
|
||||
if (prec > 0) __FMT_PUT('.');
|
||||
while (prec-- > 0) {
|
||||
__FMT_PUT(alphabet[(pun.q >> 48) & 0xf]);
|
||||
pun.q <<= 4;
|
||||
if ((flags & FLAGS_ZEROPAD) && width > 0 && !(flags & FLAGS_LEFT)) {
|
||||
do __FMT_PUT('0');
|
||||
while (--width > 0);
|
||||
}
|
||||
i1 = prec1 & 7;
|
||||
k = prec1 >> 3;
|
||||
__FMT_PUT(alphabet[(fpb.bits[k] >> 4 * i1) & 0xf]);
|
||||
if (prec1 > 0 || (flags & FLAGS_HASH)) __FMT_PUT('.');
|
||||
if (prec1 > 0) {
|
||||
prec -= prec1;
|
||||
while (prec1 > 0) {
|
||||
if (--i1 < 0) {
|
||||
if (--k < 0) break;
|
||||
i1 = 7;
|
||||
}
|
||||
__FMT_PUT(alphabet[(fpb.bits[k] >> 4 * i1) & 0xf]);
|
||||
--prec1;
|
||||
}
|
||||
if ((flags & FLAGS_HASH) && prec > 0) {
|
||||
do __FMT_PUT(0);
|
||||
while (--prec > 0);
|
||||
}
|
||||
}
|
||||
__FMT_PUT(alphabet[16]);
|
||||
if (bex < 0) {
|
||||
__FMT_PUT('-');
|
||||
bex = -bex;
|
||||
} else {
|
||||
} else
|
||||
__FMT_PUT('+');
|
||||
}
|
||||
for (c = 1; 10 * c <= bex;) c *= 10;
|
||||
for (c = 1; 10 * c <= bex; c *= 10) donothing;
|
||||
for (;;) {
|
||||
i1 = bex / c;
|
||||
__FMT_PUT('0' + i1);
|
||||
|
@ -382,13 +525,10 @@ int __fmt_dtoa(int (*out)(const char *, void *, size_t), void *arg, int d,
|
|||
bex -= i1 * c;
|
||||
bex *= 10;
|
||||
}
|
||||
while (--width >= 0) __FMT_PUT(' ');
|
||||
break;
|
||||
|
||||
FormatString:
|
||||
if (__fmt_stoa(out, arg, p, flags, prec, width, signbit, qchar) == -1) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
*/
|
||||
char *xdtoal(long double d) {
|
||||
char *p = xmalloc(32);
|
||||
g_xfmt_p(p, &d, 16, 32, 2);
|
||||
/* g_xfmt_p(p, &d, 20, 32, 2); */
|
||||
g_xfmt_p(p, &d, 16, 32, NIK(2, 0, 0));
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -638,9 +638,13 @@ BENCH(palandprintf, bench) {
|
|||
EZBENCH2("23 %x", donothing, Format("%x", VEIL("r", 23)));
|
||||
EZBENCH2("23 %d", donothing, Format("%d", VEIL("r", 23)));
|
||||
EZBENCH2("%f M_PI", donothing, Format("%f", VEIL("x", M_PI)));
|
||||
EZBENCH2("%Lf M_PI", donothing, Format("%Lf", VEIL("t", M_PI)));
|
||||
EZBENCH2("%g M_PI", donothing, Format("%g", VEIL("x", M_PI)));
|
||||
EZBENCH2("%Lg M_PI", donothing, Format("%Lg", VEIL("t", M_PI)));
|
||||
EZBENCH2("%a M_PI", donothing, Format("%a", VEIL("x", M_PI)));
|
||||
EZBENCH2("%La M_PI", donothing, Format("%La", VEIL("t", M_PI)));
|
||||
EZBENCH2("%e M_PI", donothing, Format("%e", VEIL("x", M_PI)));
|
||||
EZBENCH2("%Le M_PI", donothing, Format("%Le", VEIL("t", M_PI)));
|
||||
EZBENCH2("ULONG_MAX %lo", donothing, Format("%lo", VEIL("r", ULONG_MAX)));
|
||||
EZBENCH2("INT_MIN %x", donothing, Format("%x", VEIL("r", INT_MIN)));
|
||||
EZBENCH2("INT_MIN %d", donothing, Format("%d", VEIL("r", INT_MIN)));
|
||||
|
|
|
@ -30,6 +30,20 @@
|
|||
|
||||
#define THREADS 16
|
||||
|
||||
#define DUB(i) (union Dub){i}.x
|
||||
|
||||
#define DUBBLE(a, b, c, d, e) \
|
||||
{ \
|
||||
{ 0x##e, 0x##d, 0x##c, 0x##b, 0x##a } \
|
||||
}
|
||||
|
||||
char buf[128];
|
||||
|
||||
union Dub {
|
||||
uint64_t i;
|
||||
double x;
|
||||
};
|
||||
|
||||
char *stack[THREADS];
|
||||
char tls[THREADS][64];
|
||||
|
||||
|
@ -60,3 +74,81 @@ TEST(dtoa, test) {
|
|||
_spinlock((int *)(tls[i] + 0x38));
|
||||
}
|
||||
}
|
||||
|
||||
static const struct {
|
||||
uint64_t i;
|
||||
const char *f;
|
||||
const char *s;
|
||||
} Vd[] = {
|
||||
{0x3ff3ae147ae147ae, "%.8a", "0x1.3ae147aep+0"}, //
|
||||
{0x3ff3ae147ae147ae, "%.7a", "0x1.3ae147bp+0"}, //
|
||||
{0x3ff3ae147ae147ae, "%.2a", "0x1.3bp+0"}, //
|
||||
};
|
||||
|
||||
TEST(printf, double) {
|
||||
int i;
|
||||
for (i = 0; i < ARRAYLEN(Vd); ++i) {
|
||||
++g_testlib_ran;
|
||||
snprintf(buf, sizeof(buf), Vd[i].f, DUB(Vd[i].i));
|
||||
if (strcmp(Vd[i].s, buf)) {
|
||||
fprintf(stderr,
|
||||
"TEST FAILED\n"
|
||||
"EXPECT_STREQ(%`'s, FMT(%`'s, DUB(0x%016lx)))\n"
|
||||
" BUT GOT %`'s\n",
|
||||
Vd[i].s, Vd[i].f, Vd[i].i, buf);
|
||||
testlib_incrementfailed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const struct {
|
||||
const char *s;
|
||||
const char *f;
|
||||
union {
|
||||
uint16_t i[5];
|
||||
long double x;
|
||||
} u;
|
||||
} Vx[] = {
|
||||
{"1.23000000000000000002", "%.21Lg", DUBBLE(3fff, 9d70, a3d7, a3d, 70a4)},
|
||||
{"123000000000000000000", "%.21Lg", DUBBLE(4041, d55e, f90a, 2da1, 8000)},
|
||||
{"1.22999999999999999997e-20", "%.21Lg",
|
||||
DUBBLE(3fbc, e857, 267b, b3a9, 84f2)},
|
||||
{"1.23456789000000000003", "%.21Lg", DUBBLE(3fff, 9e06, 5214, 1ef0, dbf6)},
|
||||
{"123456589000000000000", "%.21Lg", DUBBLE(4041, d629, bd33, 5cc, ba00)},
|
||||
{"1.22999999999999999999e+30", "%.21Lg",
|
||||
DUBBLE(4062, f865, 8274, 7dbc, 824a)},
|
||||
{"1.22999999999999999999e-30", "%.21Lg",
|
||||
DUBBLE(3f9b, c794, 337a, 8085, 54eb)},
|
||||
{"1.23456788999999999998e-20", "%.21Lg",
|
||||
DUBBLE(3fbc, e934, a38, f3d6, d352)},
|
||||
{"1.23456788999999999999e-30", "%.21Lg",
|
||||
DUBBLE(3f9b, c851, f19d, decc, a8fc)},
|
||||
{"1.23456789012345678899", "%.21Lg", DUBBLE(3fff, 9e06, 5214, 62cf, db8d)},
|
||||
{"1.22999999999999999997e+306", "%.21Lg",
|
||||
DUBBLE(43f7, e033, b668, e30f, a6d5)},
|
||||
{"1.23000000000000000002e-306", "%.21Lg",
|
||||
DUBBLE(3c06, dd1d, c2ed, 1cb7, 3f25)},
|
||||
{"1.23000000000000000002e-320", "%.21Lg",
|
||||
DUBBLE(3bd8, 9b98, c371, 844c, 3f1a)},
|
||||
{"0xap-3", "%.La", DUBBLE(3fff, 9d70, a3d7, a3d, 70a4)},
|
||||
{"0x9.d70a3d70a3d70a4p-3", "%.20La", DUBBLE(3fff, 9d70, a3d7, a3d, 70a4)},
|
||||
{"0x9.b18ab5df7180b6cp+88", "%La", DUBBLE(405a, 9b18, ab5d, f718, b6c)},
|
||||
{"0xa.fc6a015291b4024p+87", "%La", DUBBLE(4059, afc6, a015, 291b, 4024)},
|
||||
};
|
||||
|
||||
TEST(printf, longdouble) {
|
||||
int i;
|
||||
for (i = 0; i < ARRAYLEN(Vx); ++i) {
|
||||
++g_testlib_ran;
|
||||
snprintf(buf, sizeof(buf), Vx[i].f, Vx[i].u.x);
|
||||
if (strcmp(Vx[i].s, buf)) {
|
||||
fprintf(stderr,
|
||||
"TEST FAILED\n"
|
||||
"\t{%`'s, %`'s, DUBBLE(%x, %x, %x, %x, %x)}\n"
|
||||
"\t→%`'s\n",
|
||||
Vx[i].s, Vx[i].f, Vx[i].u.i[0], Vx[i].u.i[1], Vx[i].u.i[2],
|
||||
Vx[i].u.i[3], Vx[i].u.i[4], buf);
|
||||
testlib_incrementfailed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ TEST_LIBC_STDIO_DIRECTDEPS = \
|
|||
LIBC_UNICODE \
|
||||
LIBC_X \
|
||||
LIBC_ZIPOS \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_ZLIB \
|
||||
THIRD_PARTY_ZLIB_GZ
|
||||
|
||||
|
|
|
@ -16,12 +16,345 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
|
||||
#define HEX(d) (union Pun){d}.i
|
||||
|
||||
union Pun {
|
||||
double x;
|
||||
uint64_t i;
|
||||
};
|
||||
|
||||
static const struct {
|
||||
uint64_t i;
|
||||
const char *s;
|
||||
} V[] = {
|
||||
{0x2fa7b6d71d20b96c, "4e-079"}, //
|
||||
{0x09eb8d7e32be6396, "7e-261"}, //
|
||||
{0x3ae7361cb863de62, "6e-025"}, //
|
||||
{0x1eaf7e0db3799aa3, "7e-161"}, //
|
||||
{0x7c1cbb547777a285, "7e0289"}, //
|
||||
{0x507afcef51f0fb5f, "5e0079"}, //
|
||||
{0x508afcef51f0fb5f, "1e0080"}, //
|
||||
{0x0133339131c46f8b, "7e-303"}, //
|
||||
{0x5fa317e5ef3ab327, "5e0152"}, //
|
||||
{0x5a07a2ecc414a03f, "5e0125"}, //
|
||||
{0x5a27a2ecc414a03f, "2e0126"}, //
|
||||
{0x22d5570f59bd178c, "7e-141"}, //
|
||||
{0x18323ff06eea847a, "4e-192"}, //
|
||||
{0x49102498ea6df0c4, "9e0043"}, //
|
||||
{0x7ed754e31cd072da, "1e0303"}, //
|
||||
{0x2dde3cbc9907fdc8, "95e-089"}, //
|
||||
{0x689d1c26db7d0dae, "85e0194"}, //
|
||||
{0x77c0b7cb60c994da, "69e0267"}, //
|
||||
{0x3c665dde8e688ba6, "97e-019"}, //
|
||||
{0x49d033d7eca0adef, "37e0046"}, //
|
||||
{0x49e033d7eca0adef, "74e0046"}, //
|
||||
{0x2bc0ad836f269a17, "61e-099"}, //
|
||||
{0x151b39ae1909c31b, "53e-208"}, //
|
||||
{0x0fc27b2e4f210075, "93e-234"}, //
|
||||
{0x2c9a5db812948281, "79e-095"}, //
|
||||
{0x0772d36cf48e7abd, "87e-274"}, //
|
||||
{0x4585747ab143e353, "83e0025"}, //
|
||||
{0x38b698ccdc60015a, "17e-036"}, //
|
||||
{0x47246a3418629ef6, "53e0033"}, //
|
||||
{0x30ecd5bee57763e6, "51e-074"}, //
|
||||
{0x3bbdc03b8fd7016a, "63e-022"}, //
|
||||
{0x5e3ae03f245703e2, "839e0143"}, //
|
||||
{0x1abf14727744c63e, "749e-182"}, //
|
||||
{0x3b282782afe1869e, "999e-026"}, //
|
||||
{0x77b0b7cb60c994da, "345e0266"}, //
|
||||
{0x2b5ffc81bc29f02b, "914e-102"}, //
|
||||
{0x55b7221a79cdd1d9, "829e0102"}, //
|
||||
{0x5322d6b183fe4b55, "307e0090"}, //
|
||||
{0x6654374d8b87ac63, "859e0182"}, //
|
||||
{0x5216c309024bab4b, "283e0085"}, //
|
||||
{0x675526be9c22eb17, "589e0187"}, //
|
||||
{0x64fdcf7df8f573b7, "302e0176"}, //
|
||||
{0x650dcf7df8f573b7, "604e0176"}, //
|
||||
{0x0de03cea3586452e, "761e-244"}, //
|
||||
{0x7044d64d4079150c, "647e0230"}, //
|
||||
{0x64a7d93193f78fc6, "755e0174"}, //
|
||||
{0x30dcd5bee57763e6, "255e-075"}, //
|
||||
{0x4c159bd3ad46e346, "3391e0055"}, //
|
||||
{0x3d923d1b5eb1d778, "4147e-015"}, //
|
||||
{0x3b482782afe1869e, "3996e-026"}, //
|
||||
{0x3b382782afe1869e, "1998e-026"}, //
|
||||
{0x0335519ac5142aab, "3338e-296"}, //
|
||||
{0x0325519ac5142aab, "1669e-296"}, //
|
||||
{0x0772d2df246ecd2d, "8699e-276"}, //
|
||||
{0x73284e91f4aa0fdb, "5311e0243"}, //
|
||||
{0x2cd07c2d27a5b989, "7903e-096"}, //
|
||||
{0x11d19b8744033457, "7611e-226"}, //
|
||||
{0x4cb444b34a6fb3eb, "3257e0058"}, //
|
||||
{0x4cc444b34a6fb3eb, "6514e0058"}, //
|
||||
{0x77462644c61d41aa, "3571e0263"}, //
|
||||
{0x77562644c61d41aa, "7142e0263"}, //
|
||||
{0x72f3720e5d54d97c, "5311e0242"}, //
|
||||
{0x3384c98fce16152e, "1617e-063"}, //
|
||||
{0x4897d2950dc76da4, "51881e0037"}, //
|
||||
{0x285ef890f5de4c86, "31441e-118"}, //
|
||||
{0x5143e272a77478e8, "30179e0079"}, //
|
||||
{0x5153e272a77478e8, "60358e0079"}, //
|
||||
{0x3cc703856844bdbf, "63876e-020"}, //
|
||||
{0x3cb703856844bdbf, "31938e-020"}, //
|
||||
{0x3a42405b773fbdf3, "46073e-032"}, //
|
||||
{0x4b757eb8ad52a5c9, "32941e0051"}, //
|
||||
{0x49770105df3d47cb, "82081e0041"}, //
|
||||
{0x1440492a4a8a37fd, "38701e-215"}, //
|
||||
{0x4ab0c52fe6dc6a1b, "62745e0047"}, //
|
||||
{0x4ac0c52fe6dc6a1b, "12549e0048"}, //
|
||||
{0x1af099b393b84832, "64009e-183"}, //
|
||||
{0x77262644c61d41aa, "89275e0261"}, //
|
||||
{0x46232645e1ba93f0, "75859e0025"}, //
|
||||
{0x7c8272ed2307f56a, "57533e0287"}, //
|
||||
{0x70ad657059dc79aa, "584169e0229"}, //
|
||||
{0x29eb99d6240c1a28, "940189e-112"}, //
|
||||
{0x6a00fd07ed297f80, "416121e0197"}, //
|
||||
{0x6a10fd07ed297f80, "832242e0197"}, //
|
||||
{0x50e8a85eb277e645, "584738e0076"}, //
|
||||
{0x241b248728b9c117, "933587e-140"}, //
|
||||
{0x5a2dda592e398dd7, "252601e0121"}, //
|
||||
{0x79f9463b59b8f2bd, "358423e0274"}, //
|
||||
{0x14f25818c7294f27, "892771e-213"}, //
|
||||
{0x49670105df3d47cb, "410405e0040"}, //
|
||||
{0x0afbe2dd66200bef, "928609e-261"}, //
|
||||
{0x0c55a462d91c6ab3, "302276e-254"}, //
|
||||
{0x3c653a9985dbde6c, "920657e-023"}, //
|
||||
{0x3bf1f99e11ea0a24, "609019e-025"}, //
|
||||
{0x59f7e1e0f1c7a4ac, "252601e0120"}, //
|
||||
{0x34b00e7db3b3f242, "654839e-060"}, //
|
||||
{0x5c5e597c0b94b7ae, "8823691e0130"}, //
|
||||
{0x709d657059dc79aa, "2920845e0228"}, //
|
||||
{0x51fda232347e6032, "9210917e0080"}, //
|
||||
{0x026e58ffa48f4fce, "5800419e-303"}, //
|
||||
{0x0ee3ecf22ea07863, "6119898e-243"}, //
|
||||
{0x0ed3ecf22ea07863, "3059949e-243"}, //
|
||||
{0x6f90f73be1dff9ad, "2572231e0223"}, //
|
||||
{0x3cf8849dd33c95af, "5444097e-021"}, //
|
||||
{0x26f7e5902ce0e151, "5783893e-127"}, //
|
||||
{0x1295d4fe53afec65, "3865421e-225"}, //
|
||||
{0x61b4689b4a5fa201, "4590831e0156"}, //
|
||||
{0x61c4689b4a5fa201, "9181662e0156"}, //
|
||||
{0x3bbbe45a312d08a0, "5906361e-027"}, //
|
||||
{0x7225f0d408362a72, "7315057e0235"}, //
|
||||
{0x5762e51a84a3c6a0, "9088115e0106"}, //
|
||||
{0x5772e51a84a3c6a0, "1817623e0107"}, //
|
||||
{0x5c4e597c0b94b7ae, "44118455e0129"}, //
|
||||
{0x7e5512d5273e62e8, "35282041e0293"}, //
|
||||
{0x05129b01b6885d36, "31279898e-291"}, //
|
||||
{0x05029b01b6885d36, "15639949e-291"}, //
|
||||
{0x5f955bcf72fd10f9, "27966061e0145"}, //
|
||||
{0x5fa55bcf72fd10f9, "55932122e0145"}, //
|
||||
{0x36900683a21de855, "70176353e-053"}, //
|
||||
{0x3adf29ca0ff893b1, "40277543e-032"}, //
|
||||
{0x622193aff1f1c8e3, "50609263e0157"}, //
|
||||
{0x518b37c4b7928317, "66094077e0077"}, //
|
||||
{0x59406e98f5ec8f37, "84863171e0114"}, //
|
||||
{0x786526f061ca9053, "89396333e0264"}, //
|
||||
{0x016e07320602056c, "87575437e-309"}, //
|
||||
{0x3870bc7b7603a2ca, "78693511e-044"}, //
|
||||
{0x16d1470083f89d48, "90285923e-206"}, //
|
||||
{0x3b423a4ad20748a2, "30155207e-030"}, //
|
||||
{0x5acc569e968e0944, "245540327e0121"}, //
|
||||
{0x7d44997a298b2f2e, "263125459e0287"}, //
|
||||
{0x0c64472ba9550e86, "566446538e-257"}, //
|
||||
{0x0c54472ba9550e86, "283223269e-257"}, //
|
||||
{0x5b01b6231e18c5cb, "245540327e0122"}, //
|
||||
{0x5b11b6231e18c5cb, "491080654e0122"}, //
|
||||
{0x27a397d3c9745d2f, "971212611e-126"}, //
|
||||
{0x4c76ce94febdc7a5, "229058583e0052"}, //
|
||||
{0x49cc7ccf90c9f8ab, "325270231e0039"}, //
|
||||
{0x3a8880a3d515e849, "989648089e-035"}, //
|
||||
{0x7a720223f2b3a881, "653777767e0273"}, //
|
||||
{0x6d30bc60e6896717, "923091487e0209"}, //
|
||||
{0x7d89bfd8b3edfafa, "526250918e0288"}, //
|
||||
{0x018e07320602056c, "350301748e-309"}, //
|
||||
{0x17a14fe7daf8f3ae, "741111169e-203"}, //
|
||||
{0x0ff09355f8050c02, "667284113e-240"}, //
|
||||
{0x5abc569e968e0944, "1227701635e0120"}, //
|
||||
{0x1c38afe10a2a66aa, "9981396317e-182"}, //
|
||||
{0x041465b896c24520, "5232604057e-298"}, //
|
||||
{0x2fb0847822f765b2, "5572170023e-088"}, //
|
||||
{0x5b31b6231e18c5cb, "1964322616e0122"}, //
|
||||
{0x5b41b6231e18c5cb, "3928645232e0122"}, //
|
||||
{0x35f4614c3219891f, "8715380633e-058"}, //
|
||||
{0x279397d3c9745d2f, "4856063055e-127"}, //
|
||||
{0x223a06a1024b95e1, "8336960483e-153"}, //
|
||||
{0x21a01891fc4717fd, "1007046393e-155"}, //
|
||||
{0x1d695fd4c88d4b1b, "5378822089e-176"}, //
|
||||
{0x1a83db11ac608107, "5981342308e-190"}, //
|
||||
{0x3020b552d2edcdea, "7214782613e-086"}, //
|
||||
{0x5f70acde6a98eb4c, "5458466829e0142"}, //
|
||||
{0x2b5fc575867314ee, "9078555839e-109"}, //
|
||||
{0x526021f14ed7b3fa, "6418488827e0079"}, //
|
||||
{0x5081a151ddbd3c4a, "65325840981e0069"}, //
|
||||
{0x54a221bd871d2cf4, "49573485983e0089"}, //
|
||||
{0x51830e6c7d4e3480, "46275205733e0074"}, //
|
||||
{0x51930e6c7d4e3480, "92550411466e0074"}, //
|
||||
{0x1832c3e72d179607, "41129842097e-202"}, //
|
||||
{0x380960fe08d5847f, "93227267727e-049"}, //
|
||||
{0x688c49437fccfadb, "41297294357e0185"}, //
|
||||
{0x343a12666477886d, "41534892987e-067"}, //
|
||||
{0x6be0189a26df575f, "42333842451e0201"}, //
|
||||
{0x131155515fd37265, "78564021519e-227"}, //
|
||||
{0x35800a19a3ffd981, "53587107423e-061"}, //
|
||||
{0x18a32fa69a69bd6d, "53827010643e-200"}, //
|
||||
{0x6a4544e6daee2a18, "83356057653e0193"}, //
|
||||
{0x29a541ecdfd48694, "45256834646e-118"}, //
|
||||
{0x2b4fc575867314ee, "45392779195e-110"}, //
|
||||
{0x7e81deaf40ead9a0, "23934638219e0291"}, //
|
||||
{0x59e2d44edcc51304, "995779191233e0113"}, //
|
||||
{0x0b676688faee99bc, "997422852243e-265"}, //
|
||||
{0x28d925a0aabcdc68, "653532977297e-123"}, //
|
||||
{0x60f11894b202e9f4, "938885684947e0147"}, //
|
||||
{0x5c210c20303fe0f1, "619534293513e0124"}, //
|
||||
{0x39a5e66dc3d6bdb5, "539879452414e-042"}, //
|
||||
{0x782c1c352fc3c309, "742522891517e0259"}, //
|
||||
{0x3dbc06d366394441, "254901016865e-022"}, //
|
||||
{0x7c85fd7aa44d9477, "685763015669e0280"}, //
|
||||
{0x072aa65b58639e69, "384865004907e-285"}, //
|
||||
{0x5321958b36c5102b, "286556458711e0081"}, //
|
||||
{0x5331958b36c5102b, "573112917422e0081"}, //
|
||||
{0x234253ec0e161420, "769525178383e-150"}, //
|
||||
{0x6a3544e6daee2a18, "416780288265e0192"}, //
|
||||
{0x2b3fc575867314ee, "226963895975e-111"}, //
|
||||
{0x4f778b6516c2b478, "665592809339e0063"}, //
|
||||
{0x6f99ab8261990292, "3891901811465e0217"}, //
|
||||
{0x50e4177a9915fbf8, "4764593340755e0069"}, //
|
||||
{0x7a7173f76c63b792, "6336156586177e0269"}, //
|
||||
{0x56566fee05649a7a, "8233559360849e0095"}, //
|
||||
{0x2c538e6edd48f2a3, "3662265515198e-107"}, //
|
||||
{0x2c438e6edd48f2a3, "1831132757599e-107"}, //
|
||||
{0x1d726dae7bbeda75, "7812878489261e-179"}, //
|
||||
{0x60b28a61cf9483b7, "6363857920591e0145"}, //
|
||||
{0x53a51f508b287ae7, "8811915538555e0082"}, //
|
||||
{0x1a253db2fea1ea31, "9997878507563e-195"}, //
|
||||
{0x0634ee5d56b32957, "9224786422069e-291"}, //
|
||||
{0x058d3409dfbca26f, "6284426329974e-294"}, //
|
||||
{0x35c135972630774c, "9199302046091e-062"}, //
|
||||
{0x29423fa9e6fcf47e, "6070482281213e-122"}, //
|
||||
{0x0405acc2053064c2, "2780161250963e-301"}, //
|
||||
{0x5621f324d11d4862, "8233559360849e0094"}, //
|
||||
{0x6d94677812d3a606, "72027097041701e0206"}, //
|
||||
{0x6f79ab8261990292, "97297545286625e0215"}, //
|
||||
{0x3da5c6714def374c, "99021992302453e-025"}, //
|
||||
{0x3e373cdf8db7a7bc, "54104687080198e-022"}, //
|
||||
{0x5537f203339c9629, "33519685743233e0089"}, //
|
||||
{0x5547f203339c9629, "67039371486466e0089"}, //
|
||||
{0x1d626dae7bbeda75, "39064392446305e-180"}, //
|
||||
{0x78e072f3819c1321, "17796979903653e0261"}, //
|
||||
{0x4a9eebabe0957af3, "28921916763211e0038"}, //
|
||||
{0x6302920f96e7f9ef, "87605699161665e0155"}, //
|
||||
{0x34d9b2a5c4041e4b, "41921560615349e-067"}, //
|
||||
{0x4f7c7c5aea080a49, "80527976643809e0061"}, //
|
||||
{0x21cce77c2b3328fc, "72335858886654e-159"}, //
|
||||
{0x57f561def4a9ee32, "52656615219377e0102"}, //
|
||||
{0x33b8bf7e7fa6f02a, "15400733123779e-072"}, //
|
||||
{0x33a8bf7e7fa6f02a, "77003665618895e-073"}, //
|
||||
{0x3a42d73088f4050a, "475603213226859e-042"}, //
|
||||
{0x5b218a7f36172332, "972708181182949e0116"}, //
|
||||
{0x342eef5e1f90ac34, "246411729980464e-071"}, //
|
||||
{0x341eef5e1f90ac34, "123205864990232e-071"}, //
|
||||
{0x0e104273b18918b1, "609610927149051e-255"}, //
|
||||
{0x3a778cfcab31064d, "475603213226859e-041"}, //
|
||||
{0x508226c684c87261, "672574798934795e0065"}, //
|
||||
{0x509226c684c87261, "134514959786959e0066"}, //
|
||||
{0x2395f2df5e675a0f, "294897574603217e-151"}, //
|
||||
{0x4a7eebabe0957af3, "723047919080275e0036"}, //
|
||||
{0x30bddc7e975c5045, "660191429952702e-088"}, //
|
||||
{0x30addc7e975c5045, "330095714976351e-088"}, //
|
||||
{0x21fce77c2b3328fc, "578686871093232e-159"}, //
|
||||
{0x21dce77c2b3328fc, "144671717773308e-159"}, //
|
||||
{0x3398bf7e7fa6f02a, "385018328094475e-074"}, //
|
||||
{0x3077e3987916a69e, "330095714976351e-089"}, //
|
||||
{0x171a80a6e566428c, "2215901545757777e-212"}, //
|
||||
{0x09cacc46749dccfe, "1702061899637397e-276"}, //
|
||||
{0x6f53ae60753af6ca, "1864950924021923e0213"}, //
|
||||
{0x6f63ae60753af6ca, "3729901848043846e0213"}, //
|
||||
{0x20f8823a57adbef9, "7487252720986826e-165"}, //
|
||||
{0x20e8823a57adbef9, "3743626360493413e-165"}, //
|
||||
{0x5be5f6de9d5d6b5b, "4988915232824583e0119"}, //
|
||||
{0x7cae3c14d6916ce9, "3771476185376383e0277"}, //
|
||||
{0x2a81b96458445d07, "6182410494241627e-119"}, //
|
||||
{0x609dfc11fbf46087, "2572981889477453e0142"}, //
|
||||
{0x4dd280461b856ec5, "7793560217139653e0051"}, //
|
||||
{0x194fe601457dce4d, "9163942927285259e-202"}, //
|
||||
{0x63650aff653ffe8a, "6353227084707473e0155"}, //
|
||||
{0x176090684f5fe998, "4431803091515554e-211"}, //
|
||||
{0x6f0f7d6721f7f144, "9324754620109615e0211"}, //
|
||||
{0x79d90529a37b7e22, "8870461176410409e0263"}, //
|
||||
{0x612491daad0ba280, "90372559027740405e0143"}, //
|
||||
{0x61a011f2d73116f4, "18074511805548081e0146"}, //
|
||||
{0x496ec55666d8f9ec, "54897030182071313e0029"}, //
|
||||
{0x3ccb7738011e75fe, "76232626624829156e-032"}, //
|
||||
{0x2128823a57adbef9, "59898021767894608e-165"}, //
|
||||
{0x2118823a57adbef9, "29949010883947304e-165"}, //
|
||||
{0x4d83de005bd620df, "26153245263757307e0049"}, //
|
||||
{0x0d27c0747bd76fa1, "27176258005319167e-261"}, //
|
||||
{0x61d4166f8cfd5cb1, "18074511805548081e0147"}, //
|
||||
{0x2b759a2783ce70ab, "24691002732654881e-115"}, //
|
||||
{0x4f408ce499519ce3, "58483921078398283e0057"}, //
|
||||
{0x22692238f7987779, "64409240769861689e-159"}, //
|
||||
{0x11364981e39e66ca, "94080055902682397e-242"}, //
|
||||
{0x63550aff653ffe8a, "31766135423537365e0154"}, //
|
||||
{0x657a999ddec72aca, "68985865317742005e0164"}, //
|
||||
{0x658a999ddec72aca, "13797173063548401e0165"}, //
|
||||
{0x09522dc01ca1cb8c, "902042358290366539e-281"}, //
|
||||
{0x7c038fd93f1f5342, "238296178309629163e0272"}, //
|
||||
{0x72925ae62cb346d8, "783308178698887621e0226"}, //
|
||||
{0x499ec55666d8f9ec, "439176241456570504e0029"}, //
|
||||
{0x7e6adf51fa055e03, "899810892172646163e0283"}, //
|
||||
{0x14f307a67f1f69ff, "926145344610700019e-225"}, //
|
||||
{0x4d63de005bd620df, "653831131593932675e0047"}, //
|
||||
{0x4d73de005bd620df, "130766226318786535e0048"}, //
|
||||
{0x0693bfac6bc4767b, "557035730189854663e-294"}, //
|
||||
{0x0986b93023ca3e6f, "902042358290366539e-280"}, //
|
||||
{0x6d13bbb4bf05f087, "272104041512242479e0200"}, //
|
||||
{0x6d23bbb4bf05f087, "544208083024484958e0200"}, //
|
||||
{0x6b808ebc116f8a20, "680429695511221511e0192"}, //
|
||||
{0x7490db75cc001072, "308975121073410857e0236"}, //
|
||||
{0x53d7bff336d8ff06, "792644927852378159e0078"}, //
|
||||
{0x71f2cbac35f71140, "783308178698887621e0223"}, //
|
||||
{0x0f8ab223efcee35a, "8396094300569779681e-252"}, //
|
||||
{0x346b85c026a264e4, "3507665085003296281e-074"}, //
|
||||
{0x5336775b6caa5ae0, "7322325862592278999e0074"}, //
|
||||
{0x6f396397b06732a4, "6014546754280072926e0209"}, //
|
||||
{0x5cc3220dcd5899fd, "7120190517612959703e0120"}, //
|
||||
{0x34a1339818257f0f, "3507665085003296281e-073"}, //
|
||||
{0x168a9c42e5b6d89f, "4345544743100783551e-218"}, //
|
||||
{0x313146fe1075e1ef, "9778613303868468131e-090"}, //
|
||||
{0x32d3d969e3dbe723, "7539204280836061195e-082"}, //
|
||||
{0x19eaba3262ee707b, "7862637540082247119e-202"}, //
|
||||
{0x6d43bbb4bf05f087, "2176832332097939832e0200"}, //
|
||||
{0x5bbe71ec1ed0a4f9, "8643988913946659879e0115"}, //
|
||||
{0x6079c677be6f236e, "5529436763613147623e0138"}, //
|
||||
{0x1fed06692e6f5ef6, "6764958008109694533e-173"}, //
|
||||
{0x6cbf92bacb3cb40c, "6802601037806061975e0197"}, //
|
||||
{0x6ccf92bacb3cb40c, "1360520207561212395e0198"}, //
|
||||
{0x4dcd8f2cfc20d6e8, "62259110684423957791e0047"}, //
|
||||
{0x1526cec51a43f41a, "88800290202542652011e-226"}, //
|
||||
{0x162012954b6aabba, "41010852717673354694e-221"}, //
|
||||
{0x161012954b6aabba, "20505426358836677347e-221"}, //
|
||||
{0x4f7762068a24fd55, "66102447903809911604e0055"}, //
|
||||
{0x5cb3220dcd5899fd, "35600952588064798515e0119"}, //
|
||||
{0x6e78d92d2bcc7a81, "14371240869903838702e0205"}, //
|
||||
{0x4cf65d3e2acd616b, "57500690832492901689e0043"}, //
|
||||
{0x2dbdd54c40a2f25f, "23432630639573022093e-107"}, //
|
||||
{0x4e02797c1d948651, "62259110684423957791e0048"}, //
|
||||
{0x0475b22082529425, "35620497849450218807e-306"}, //
|
||||
{0x6d93bbb4bf05f087, "69658634627134074624e0200"}, //
|
||||
{0x37362d10462a26f4, "99440755792436956989e-062"}, //
|
||||
{0x54d945bfa911e32a, "55277197169490210673e0081"}, //
|
||||
{0x01f8c5f9551c2f9a, "36992084760177624177e-318"}, //
|
||||
{0x2cf01b8ef28251fc, "30888265282878466443e-111"}, //
|
||||
};
|
||||
|
||||
int oldround;
|
||||
|
||||
void SetUp(void) {
|
||||
|
@ -32,6 +365,13 @@ void TearDown(void) {
|
|||
fesetround(oldround);
|
||||
}
|
||||
|
||||
TEST(strtod, test) {
|
||||
int i;
|
||||
for (i = 0; i < ARRAYLEN(V); ++i) {
|
||||
EXPECT_EQ(V[i].i, HEX(strtod(V[i].s, 0)), "strtod(%`'s)", V[i].s);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(strtod, testNearest) {
|
||||
fesetround(FE_TONEAREST);
|
||||
EXPECT_STREQ("-1.79769313486231e+308",
|
||||
|
|
20
third_party/gdtoa/gdtoa.h
vendored
20
third_party/gdtoa/gdtoa.h
vendored
|
@ -3,6 +3,26 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
/**
|
||||
* Configures g_*fmt()
|
||||
*
|
||||
* @param ic
|
||||
* 0 ==> Infinity or NaN
|
||||
* 1 ==> infinity or nan
|
||||
* 2 ==> INFINITY or NAN
|
||||
* 3 ==> Inf or NaN
|
||||
* 4 ==> inf or nan
|
||||
* 5 ==> INF or NAN
|
||||
* @param ic determines if NaNs are rendered as NaN(...)
|
||||
* 0 ==> no
|
||||
* 1 ==> yes
|
||||
* 2 ==> no for default NaN values; yes otherwise
|
||||
* @param ns determines sign of NaN values reported
|
||||
* 0 ==> distinguish NaN and -NaN
|
||||
* 1 ==> report both as NaN
|
||||
*/
|
||||
#define NIK(ic, nb, ns) (ic + 6 * (nb + 3 * ns))
|
||||
|
||||
enum {
|
||||
/* return values from strtodg */
|
||||
STRTOG_Zero = 0,
|
||||
|
|
76
third_party/gdtoa/strtodnrp.c
vendored
76
third_party/gdtoa/strtodnrp.c
vendored
|
@ -1,76 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ The author of this software is David M. Gay. │
|
||||
│ Please send bug reports to David M. Gay <dmg@acm.org> │
|
||||
│ or Justine Tunney <jtunney@gmail.com> │
|
||||
│ │
|
||||
│ Copyright (C) 1998, 1999 by Lucent Technologies │
|
||||
│ All Rights Reserved │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and distribute this software and │
|
||||
│ its documentation for any purpose and without fee is hereby │
|
||||
│ granted, provided that the above copyright notice appear in all │
|
||||
│ copies and that both that the copyright notice and this │
|
||||
│ permission notice and warranty disclaimer appear in supporting │
|
||||
│ documentation, and that the name of Lucent or any of its entities │
|
||||
│ not be used in advertising or publicity pertaining to │
|
||||
│ distribution of the software without specific, written prior │
|
||||
│ permission. │
|
||||
│ │
|
||||
│ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, │
|
||||
│ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. │
|
||||
│ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY │
|
||||
│ SPECIAL, 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 "third_party/gdtoa/gdtoa.internal.h"
|
||||
/* clang-format off */
|
||||
|
||||
/* This is a variant of strtod that works on Intel ia32 systems */
|
||||
/* with the default extended-precision arithmetic -- it does not */
|
||||
/* require setting the precision control to 53 bits. */
|
||||
|
||||
double
|
||||
strtod(const char *s, char **sp)
|
||||
{
|
||||
static const FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI, 0 /*unused*/ };
|
||||
ULong bits[2];
|
||||
Long exp;
|
||||
int k;
|
||||
union { ULong L[2]; double d; } u;
|
||||
k = strtodg(s, sp, &fpi, &exp, bits);
|
||||
switch(k & STRTOG_Retmask) {
|
||||
case STRTOG_NoNumber:
|
||||
case STRTOG_Zero:
|
||||
u.L[0] = u.L[1] = 0;
|
||||
break;
|
||||
case STRTOG_Normal:
|
||||
u.L[0] = bits[0];
|
||||
u.L[1] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20);
|
||||
break;
|
||||
case STRTOG_Denormal:
|
||||
u.L[0] = bits[0];
|
||||
u.L[1] = bits[1];
|
||||
break;
|
||||
case STRTOG_Infinite:
|
||||
u.L[1] = 0x7ff00000;
|
||||
u.L[0] = 0;
|
||||
break;
|
||||
case STRTOG_NaN:
|
||||
u.L[0] = d_QNAN0;
|
||||
u.L[1] = d_QNAN1;
|
||||
break;
|
||||
case STRTOG_NaNbits:
|
||||
u.L[1] = 0x7ff00000 | bits[1];
|
||||
u.L[0] = bits[0];
|
||||
}
|
||||
if (k & STRTOG_Neg)
|
||||
u.L[1] |= 0x80000000L;
|
||||
return u.d;
|
||||
}
|
Loading…
Add table
Reference in a new issue