(2010/03/27 23:49), Tanaka A. wrote:
2010e$BG/e(B3e$B7ne(B27e$BF|e(B19:14 NARUSE, Yui[email protected]:
ML e$B>e$G$N:GBg$Ne(B use case e$B$OIbF0>.?tE@?t$rM}2r$7$F$$$J$$%f!<%6$X$N@bL@MQ$G$7$g$&$M!#e(B
e$B$=$NMQES$KI,MW$J$N$O!“e(BString#to_f e$B$h$j!”$^$:e(B Float#to_s e$B$J$s$8$c$J$$$G$9$+$M!#e(B
printf e$B$G$b$$$$$G$9$,!#e(B
e$BM}2r$7$F$$$J$$%f!<%6$N$?$a$K!“DL>o$NMxJX@-$rMn$H$9$3$H$O9M$($^$;$s$G$7$?!#e(B
e$B$J$N$G!“e(Bprintf e$B$G$$$$$s$8$c$J$$$+$J$!$H;W$$$^$9!#e(B
Float#to_s(16)
e$B$G4|BT$9$k$N$,$3$N7A<0$+$H$$$&$H!”$^$?>/$7G:$`$H$3$m$,$”$j$^$9$7!#e(B
e$B$J$*!"!Ve(BML e$B>e$G$N!W$H$D$1$?$N$O4QB,2DG=$@$+$i$G$7$?!#e(B
e$B8D?ME*$JMxMQ$G$$$&$H!"e(BMath.atanh e$B$de(B Math.log
e$B<~$j$N%P%0$r=$@5$7$F$$$k$H$-$K!"e(B
e$B$=$l$>$l$N4D6-$Ne(B Ruby e$B$K%Q%C%A$rEv$F$D$D!"e(B%a
e$B$N=PNO$r$K$i$a$C$3$7$F$$$^$7$?!#e(B
10 e$B?J$@$He(B 10 e$B?JJQ49$,F~$k$N$G2?$,5/$-$F$$$k$+$o$+$i$J$$$7!“e(B
pack
e$B$@$H$I$3$^$G$,;X?tIt$+0lL$G$o$+$i$J$$$N$G!”$3$N7A<0$OM-MQ$G$7$?!#e(B
e$B$D$$$G$Ke(B missing/vsnprint.f e$B$b4^$a$?e(B printf(“%a”)
e$B$N%Q%C%A!#e(B
diff --git a/LEGAL b/LEGAL
index 991bb4d…c28a0b5 100644
— a/LEGAL
+++ b/LEGAL
@@ -123,6 +123,32 @@ win32/win32.[ch]:
You may distribute under the terms of either the GNU General Public
License or the Artistic License, as specified in the perl README
file.
+util.c (partly):
+
- Copyright (c) 2004-2008 David S. [email protected]
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
-
- Redistributions of source code must retain the above copyright
-
notice, this list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright
-
notice, this list of conditions and the following disclaimer in
the
distribution.
+
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
random.c
This file is under the new-style BSD license.
diff --git a/missing/vsnprintf.c b/missing/vsnprintf.c
index 4e19651…acb09c9 100644
— a/missing/vsnprintf.c
+++ b/missing/vsnprintf.c
@@ -559,7 +559,7 @@ BSD_vfprintf(FILE *fp, const char fmt0, va_list ap)
struct __suio uio; / output information: summary /
struct __siov iov[NIOV];/ … and individual io vectors /
char buf[BUF]; / space for %c, %[diouxX], %[eEfgG] */
- char ox[2]; /* space for 0x hex-prefix */
- char ox[4]; /* space for 0x hex-prefix, hexadecimal’s 1. */
char *const ebuf = buf + sizeof(buf);
#if SIZEOF_LONG > SIZEOF_INT
long ln;
@@ -784,6 +784,11 @@ reswitch: switch (ch) {
base = 10;
goto number;
#ifdef FLOATING_POINT
- case ‘a’:
- case ‘A’:
-
if (prec >= 0)
-
prec++;
-
goto fp_begin;
case ‘e’: /* anomalous precision */
case ‘E’:
if (prec != 0)
@@ -822,7 +827,12 @@ fp_begin: _double = va_arg(ap, double);
else
ch = ‘g’;
}
-
if (ch == 'a' || ch == 'A') {
-
--expt;
-
expsize = exponent(expstr, expt, ch + 'p' - 'a');
-
size = expsize + ndig;
-
}
-
else if (ch <= 'e') { /* 'e' or 'E' fmt */
--expt;
expsize = exponent(expstr, expt, ch);
size = expsize + ndig;
@@ -1048,7 +1058,20 @@ long_len:
if ((flags & FPT) == 0) {
PRINT(cp, fieldsz);
} else { /* glue together f_p fragments */
-
if (ch == 'a' || ch == 'A') {
-
ox[0] = '0';
-
ox[1] = ch + ('x' - 'a');
-
PRINT(ox, 2);
-
if (ndig > 1 || flags & ALT) {
-
ox[2] = *cp++;
-
ox[3] = '.';
-
PRINT(ox+2, 2);
-
PRINT(cp, ndig-1);
-
} else /* XpYYY */
-
PRINT(cp, 1);
-
PRINT(expstr, expsize);
-
}
-
else if (ch >= 'f') { /* 'f' or 'g' */
if (_double == 0) {
/* kludge for __dtoa irregularity */
if (ndig <= 1 &&
@@ -1112,6 +1135,7 @@ error:
#ifdef FLOATING_POINT
extern char *BSD__dtoa __P((double, int, int, int *, int *, char **));
+extern char *BSD__hdtoa(double, const char *, int, int *, int *, char
**);
static char *
cvt(value, ndigits, flags, sign, decpt, ch, length, buf)
@@ -1135,7 +1159,14 @@ cvt(value, ndigits, flags, sign, decpt, ch,
length, buf)
} else {
*sign = ‘\000’;
}
- digits = BSD__dtoa(value, mode, ndigits, decpt, &dsgn, &rve);
- if (ch == ‘a’ || ch ==‘A’) {
-
digits = BSD__hdtoa(value,
-
ch == 'a' ? "0123456789abcdef" : "0123456789ABCDEF",
-
ndigits, decpt, &dsgn, &rve);
- }
- else {
-
digits = BSD__dtoa(value, mode, ndigits, decpt, &dsgn, &rve);
- }
memcpy(buf, digits, rve - digits);
xfree(digits);
rve = buf + (rve - digits);
@@ -1181,7 +1212,7 @@ exponent(p0, exp, fmtch)
for (; t < expbuf + MAXEXP; *p++ = *t++);
}
else {
- if (fmtch & 15) p++ = ‘0’; / other than p or P */
*p++ = to_char(exp);
}
return (int)(p - p0);
diff --git a/sprintf.c b/sprintf.c
index bec0569…e26b833 100644
— a/sprintf.c
+++ b/sprintf.c
@@ -227,6 +227,10 @@ get_hash(volatile VALUE *hash, int argc, const
VALUE *argv)
-
| equal to the precision, or in dd.dddd form otherwise.
-
| The precision specifies the number of significant
digits.
form.
part
------±-------------------------------------------------------------
@@ -244,7 +248,7 @@ get_hash(volatile VALUE *hash, int argc, const VALUE
*argv)
- Flag | Applies to | Meaning
-
---------±--------------±----------------------------------------
- space | bBdiouxX | Leave a space at the start of
-
-
| aAeEfgG | non-negative numbers.
-
| (numeric fmt) | For `o', `x', `X', `b' and `B', use
-
| | a minus sign with absolute value for
-
| | negative values.
@@ -255,19 +259,19 @@ get_hash(volatile VALUE *hash, int argc, const
VALUE *argv)
---------±--------------±----------------------------------------
precision
precision
-
| | until the first digit will be `0' if
-
| | it is not formatted as complements.
-
| | For the conversions `x', `X', `b' and
`B’
``0x’',
respectively.
-
-
| | For `e', `E', `f', `g', and 'G',
-
-
| | For `a', `A', `e', `E', `f', `g', and
‘G’,
-
| | force a decimal point to be added,
-
| | even if no digits follow.
-
| | For `g' and 'G', do not remove
trailing zeros.
*
---------±--------------±----------------------------------------
non-negative
-
-
| aAeEfgG | numbers.
-
| (numeric fmt) | For `o', `x', `X', `b' and `B', use
-
| | a minus sign with absolute value for
-
| | negative values.
@@ -275,7 +279,7 @@ get_hash(volatile VALUE *hash, int argc, const VALUE
*argv)
conversion.
*
---------±--------------±----------------------------------------
- 0 (zero) | bBdiouxX | Pad with zeros, not spaces.
-
-
| eEfgG | For `o', `x', `X', `b' and `B',
radix-1
-
-
| aAeEfgG | For `o', `x', `X', `b' and `B',
radix-1
as
---------±--------------±----------------------------------------
@@ -983,6 +987,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE
fmt)
case ‘G’:
case ‘e’:
case ‘E’:
-
case ‘a’:
-
case ‘A’:
{
VALUE val = GETARG();
double fval;
diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb
index 15424d9…f8dbbd5 100644
— a/test/ruby/test_sprintf.rb
+++ b/test/ruby/test_sprintf.rb
@@ -191,6 +191,19 @@ class TestSprintf < Test::Unit::TestCase
assert_equal(" Inf", sprintf(“% 0e”, 1.0/0.0), “moved from
btest/knownbug”)
end
-
def test_float_hex
-
assert_equal(“-0x0p+0”, sprintf(“%a”, -0.0))
-
assert_equal(“0x0p+0”, sprintf(“%a”, 0.0))
-
assert_equal(“0x1p-1”, sprintf(“%a”, 0.5))
-
assert_equal(“0x1p+0”, sprintf(“%a”, 1.0))
-
assert_equal(“0x1p+1”, sprintf(“%a”, 2.0))
-
assert_equal(“0x1.193ea7aad030ap+0”, sprintf(“%a”, Math.log(3)))
-
assert_equal(“0X1.193EA7AAD030AP+0”, sprintf(“%A”, Math.log(3)))
-
assert_equal(“0x1p+10”, sprintf(“%a”, 1024))
-
assert_equal(“0x1.23456p+789”, sprintf(“%a”,
3.704450999893983e+237))
-
assert_equal(“0x1p-1074”, sprintf(“%a”, 4.9e-324))
-
end
-
BSIZ = 120
def test_skip
diff --git a/util.c b/util.c
index 9cdb563…88914be 100644
— a/util.c
+++ b/util.c
@@ -3860,6 +3857,149 @@ ruby_each_words(const char str, void
(func)(const char, int, void), void *ar
}
}
+/*-
-
-
-
-
- Redistribution and use in source and binary forms, with or without
-
- modification, are permitted provided that the following conditions
-
-
-
- Redistributions of source code must retain the above copyright
-
- notice, this list of conditions and the following disclaimer.
-
-
- 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.
-
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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
-
- */
-
+#define DBL_MANH_SIZE 20
+#define DBL_MANL_SIZE 32
+#define INFSTR “Infinity”
+#define NANSTR “NaN”
+#define DBL_ADJ (DBL_MAX_EXP - 2)
+#define SIGFIGS ((DBL_MANT_DIG + 3) / 4 + 1)
+#define dexp_get(u) ((int)(word0(u) >> Exp_shift) & ~Exp_msk1)
+#define dexp_set(u,v) (word0(u) = (((int)(word0(u)) & ~Exp_mask) | (v
<< Exp_shift)))
+#define dmanh_get(u) ((int)(word0(u) & Frac_mask))
+#define dmanl_get(u) ((int)word1(u))
+
+
+/*
#ifdef __cplusplus
#if 0
{