mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ruby.c (proc_options): should not alter origargv[].
* ruby.c (set_arg0): long strings for $0 dumped core. * ruby.c (set_arg0): use setprogtitle() if it's available. * io.c (rb_io_popen): accept integer flags as mode. * file.c (rb_find_file_ext): extension table can be supplied from outside. renamed. * eval.c (rb_f_require): replace rb_find_file_noext by rb_find_file_ext. * eval.c (rb_provided): should also check feature without extension. * numeric.c (flo_to_s): do not rely on decimal point to be '.' git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c9d1be6327
commit
0f35b58a2f
12 changed files with 133 additions and 157 deletions
35
numeric.c
35
numeric.c
|
@ -214,30 +214,31 @@ flo_to_s(flt)
|
|||
VALUE flt;
|
||||
{
|
||||
char buf[24];
|
||||
char *s;
|
||||
char *fmt = "%.10g";
|
||||
double value = RFLOAT(flt)->value;
|
||||
double d1, d2;
|
||||
|
||||
if (isinf(value))
|
||||
return rb_str_new2(value < 0 ? "-Infinity" : "Infinity");
|
||||
else if(isnan(value))
|
||||
return rb_str_new2("NaN");
|
||||
else
|
||||
sprintf(buf, "%-.10g", value);
|
||||
if (s = strchr(buf, ' ')) *s = '\0';
|
||||
s = buf; if (s[0] == '-') s++;
|
||||
if (strchr(s, '.') == 0) {
|
||||
int len = strlen(buf);
|
||||
char *ind = strchr(buf, 'e');
|
||||
|
||||
if (ind) {
|
||||
memmove(ind+2, ind, len-(ind-buf)+1);
|
||||
ind[0] = '.';
|
||||
ind[1] = '0';
|
||||
}
|
||||
else {
|
||||
strcat(buf, ".0");
|
||||
}
|
||||
|
||||
if (value < 1.0e-3) {
|
||||
d1 = value;
|
||||
while (d1 < 1.0) d1 *= 10.0;
|
||||
d1 = modf(d1, &d2);
|
||||
if (d1 == 0) fmt = "%.1e";
|
||||
}
|
||||
else if (value >= 1.0e10) {
|
||||
d1 = value;
|
||||
while (d1 > 10.0) d1 /= 10.0;
|
||||
d1 = modf(d1, &d2);
|
||||
if (d1 == 0) fmt = "%.1e";
|
||||
}
|
||||
else if ((d1 = modf(value, &d2)) == 0) {
|
||||
fmt = "%.1f";
|
||||
}
|
||||
sprintf(buf, fmt, value);
|
||||
|
||||
return rb_str_new2(buf);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue