summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-04-26 09:42:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-04-26 09:42:44 +0000
commite67e5adf4e33b79c3bc2f2c8a8b4a790a88adcf2 (patch)
tree6ef7eae93ed8a768a02dee1baa8ba80a4425b5e0 /sprintf.c
parentf6e04e38cd1f121111d388865e8b201ea3402452 (diff)
aix shlib link
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/sprintf.c b/sprintf.c
index 0370453f09f..c3a2772e67f 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -12,6 +12,9 @@
#include "ruby.h"
#include <ctype.h>
+#include <math.h>
+
+#define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */
#ifndef atof
double strtod();
@@ -562,6 +565,7 @@ rb_f_sprintf(argc, argv)
{
VALUE val = GETARG();
double fval;
+ int i, need = 6;
char fbuf[32];
switch (TYPE(val)) {
@@ -583,8 +587,19 @@ rb_f_sprintf(argc, argv)
}
fmt_setup(fbuf, *p, flags, width, prec);
+ need = 0;
+ if (*p != 'e' && *p != 'E') {
+ i = INT_MIN;
+ frexp(fval, &i);
+ if (i > 0)
+ need = BIT_DIGITS(i);
+ }
+ need += (flags&FPREC) ? prec : 6;
+ if ((flags&FWIDTH) && need < width)
+ need = width;
+ need += 20;
- CHECK(22);
+ CHECK(need);
sprintf(&buf[blen], fbuf, fval);
blen += strlen(&buf[blen]);
}