summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-07 08:44:24 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-07 08:44:24 +0000
commit1b0f90ca333ddbf7ed57eba28465fbb922daa957 (patch)
tree47b47a035bcad5c857f1d90b41e9c14bf2e9bbf8 /numeric.c
parentc4216a26e2c9b3754abc3225de1732c50803433b (diff)
downloadruby-1b0f90ca333ddbf7ed57eba28465fbb922daa957.tar.gz
* parse.y (string_content): turn off NODE_NEWLINE flag to avoid
unnecessary line trace for inlined expression. (ruby-bugs PR#1320) * numeric.c (flo_to_s): tweak output string based to preserve decimal point and to remove trailing zeros. [ruby-talk:97891] * string.c (rb_str_index_m): use unsigned comparison for T_FIXNUM search. [ruby-talk:97342] * hash.c (rb_hash_equal): returns true if two hashes have same set of key-value set. [ruby-talk:97559] * hash.c (rb_hash_eql): returns true if two hashes are equal and have same default values. * string.c (rb_str_equal): always returns true or false, never returns nil. [ruby-dev:23404] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c34
1 files changed, 13 insertions, 21 deletions
diff --git a/numeric.c b/numeric.c
index bcd6599a86..f7439ec34b 100644
--- a/numeric.c
+++ b/numeric.c
@@ -490,37 +490,29 @@ flo_to_s(flt)
VALUE flt;
{
char buf[32];
- char *fmt = "%.15g";
+ char *fmt = "%.15f";
double value = RFLOAT(flt)->value;
double avalue, d1, d2;
+ char *p, *e;
if (isinf(value))
return rb_str_new2(value < 0 ? "-Infinity" : "Infinity");
else if(isnan(value))
return rb_str_new2("NaN");
-
+
avalue = fabs(value);
- if (avalue == 0.0) {
- fmt = "%.1f";
- }
- else if (avalue < 1.0e-3) {
- d1 = avalue;
- while (d1 < 1.0) d1 *= 10.0;
- d1 = modf(d1, &d2);
- if (d1 == 0) fmt = "%.1e";
- }
- else if (avalue >= 1.0e15) {
- d1 = avalue;
- while (d1 > 10.0) d1 /= 10.0;
- d1 = modf(d1, &d2);
- if (d1 == 0) fmt = "%.1e";
- else fmt = "%.16e";
+ if (avalue < 1.0e-7 || avalue >= 1.0e15) {
+ fmt = "%.16e";
}
- else if ((d1 = modf(value, &d2)) == 0) {
- fmt = "%.1f";
- }
sprintf(buf, fmt, value);
-
+ if (!(e = strchr(buf, 'e'))) {
+ e = buf + strlen(buf);
+ }
+ p = e;
+ while (*--p=='0')
+ ;
+ if (*p == '.') *p++;
+ memmove(p+1, e, strlen(e)+1);
return rb_str_new2(buf);
}