ruby-dev summary 23690-23762

  • Thread starter Masayoshi Takahashi
  • Start date
M

Masayoshi Takahashi

Hello all,

This is a summary of ruby-dev ML in these days.


[ruby-dev:23704] [mswin32] representation of NaN, Inf in printf

Katonbo reported strange representations of NaN and Inf
in printf of mswin32 Ruby.

C:\tmp>ruby -ve "(0..6).each {|i| printf(\"%.*f\n\",i, 0.0/0.0)}"
ruby 1.8.1 (2003-12-25) [i386-mswin32]
-1
-1.$
-1.#J
-1.#IO
-1.#IND
-1.#IND0
-1.#IND00

According to Microsoft, It's a specification of Runtime library:
<http://msdn.microsoft.com/library/en-us/vclib/html/_crt_precision_specification.asp>

Katonbo made a patch for this. U.Nakamura brushed up
his patch and commited it with Matz's advice.

Nakamura pointed out that the string "nan" and "inf" are
used as NaN and Inf in some environments. His patch
forced to use "NaN" and "Inf". He needs comments
about this change.


[ruby-dev:23746] Anonymous CVS service restart

As reported in [ruby-talk:104312], Anonymous CVS service
was restarted.

Shugo Maeda and ruby-lang.org administrators' group have
made efforts to recovery the systems and the services of
ruby-lang.org. Now they are writing report of the trouble
and translating it into English.


[ruby-dev:23762] Ruby 1.8.2 to be released.

Matz announced that he wanted to release Ruby 1.8.2.
in near future.
If we have no trouble, he will in the middle of July.
Any comments and bug reports on current snapshot are welcome.


Regards,

TAKAHASHI 'Maki' Masayoshi E-mail: (e-mail address removed)
 
P

Paul Brannan

Nakamura pointed out that the string "nan" and "inf" are
used as NaN and Inf in some environments. His patch
forced to use "NaN" and "Inf". He needs comments
about this change.

I think it's a good idea to print NaN and Inf uniformly across all
platforms.

However, a thought occurred to me when I was considering this, that it
would be a shame if we print NaN to a string and then were unable to
read it back in, because to_f didn't handle the case change correctly.
It should work though, since #to_f is implemented in terms of strtod,
and strtod can handle "NAN" in any case.

However, it seems this doesn't work in the first place in 1.8 nor 1.9:

irb(main):001:0> (0.0/0).to_s.to_f
=> 0.0
irb(main):002:0> RUBY_VERSION
=> "1.9.0"
irb(main):004:0> RUBY_RELEASE_DATE
=> "2004-06-22"

But it does work on 1.6.8:

[pbrannan@zaphod images]$ irb
irb(main):001:0> (0.0/0).to_s.to_f
=> NaN
irb(main):002:0> "NAN".to_f
=> NaN
irb(main):003:0> "nan".to_f
=> NaN
irb(main):004:0> RUBY_VERSION
=> "1.6.8"

(Also, it looks to me like in rb_cstr_to_dbl, errno is being checked
incorrectly; errno is only set if +/- HUGE_VAL is returned, otherwise it
is left to the value it was set before strtod was called. The fix
should be to zero out errno before calling strtod).

Paul
 
H

H.Yamamoto

Hello.

I think this patch works...

(Also, it looks to me like in rb_cstr_to_dbl, errno is being checked
incorrectly; errno is only set if +/- HUGE_VAL is returned, otherwise it
is left to the value it was set before strtod was called. The fix
should be to zero out errno before calling strtod).

This is OK, because errno is set to zero in ruby_strtod which is used as
strtod by #define.

Index: numeric.c
===================================================================
RCS file: /var/cvs/src/ruby/numeric.c,v
retrieving revision 1.112
diff -u -w -b -p -r1.112 numeric.c
--- numeric.c 16 Jun 2004 14:21:33 -0000 1.112
+++ numeric.c 3 Jul 2004 02:07:37 -0000
@@ -495,7 +495,7 @@ flo_to_s(flt)
char *p, *e;

if (isinf(value))
- return rb_str_new2(value < 0 ? "-Infinity" : "Infinity");
+ return rb_str_new2(value < 0 ? "-Inf" : "Inf");
else if(isnan(value))
return rb_str_new2("NaN");

Index: util.c
===================================================================
RCS file: /var/cvs/src/ruby/util.c,v
retrieving revision 1.43
diff -u -w -b -p -r1.43 util.c
--- util.c 14 May 2004 03:17:29 -0000 1.43
+++ util.c 3 Jul 2004 02:11:15 -0000
@@ -750,6 +750,7 @@ ruby_strtod(string, endPtr)
* in string. */
const char *pExp; /* Temporarily holds location of exponent
* in string. */
+ int frac1, frac2;

/*
* Strip off leading blanks and check for a sign.
@@ -772,6 +773,22 @@ ruby_strtod(string, endPtr)
}

/*
+ * Check for NaN and Inf.
+ */
+
+ if (strncmpi(p, "NaN", 3) == 0) {
+ p += 3;
+ fraction = 0.0 / 0;
+ goto exit;
+ }
+
+ if (strncmpi(p, "Inf", 3) == 0) {
+ p += 3;
+ fraction = 1.0 / 0;
+ goto exit;
+ }
+
+ /*
* Count the number of digits in the mantissa
* and also locate the decimal point.
*/
@@ -812,8 +829,7 @@ ruby_strtod(string, endPtr)
fracExp += (mantSize - 18);
mantSize = 18;
}
- {
- int frac1, frac2;
+
frac1 = 0;
for ( ; mantSize > 9; mantSize -= 1) {
c = *p;
@@ -920,12 +936,11 @@ ruby_strtod(string, endPtr)
else {
fraction += frac2 * dblExp;
}
- }

+ exit:
if (endPtr != NULL) {
*endPtr = (char *) p;
}
-
if (sign) {
return -fraction;
}

Index: util.h
===================================================================
RCS file: /var/cvs/src/ruby/util.h,v
retrieving revision 1.14
diff -u -w -b -p -r1.14 util.h
--- util.h 4 Aug 2003 01:27:25 -0000 1.14
+++ util.h 3 Jul 2004 02:11:20 -0000
@@ -62,5 +62,6 @@ char *ruby_getcwd _((void));

double ruby_strtod _((const char*, char **));
#define strtod(s,e) ruby_strtod(s,e)
+#define atof(s) ruby_strtod(s,0)

#endif /* UTIL_H */
 
P

Paul Brannan

This is OK, because errno is set to zero in ruby_strtod which is used as
strtod by #define.

Right, I forgot strtod was a macro.

Have I ever mentioned how much I love and hate C macros?

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,226
Latest member
KristanTal

Latest Threads

Top