Help save net neutrality! Learn more.
Close

#27 atom2str() no decimal point for inexact

closed-fixed
nobody
None
5
2011-08-29
2011-08-21
Doug Currie
No

Aubrey Jaffer's r4rstest.scm has several failures due to atom2str() not putting a '.' on the end of some inexact numbers that happen to print as integers.

Here is a quick fix:

@@ -1932,6 +1926,13 @@
snprintf(p, STRBUFFSIZE, "%ld", ivalue_unchecked(l));
} else {
snprintf(p, STRBUFFSIZE, "%.10g", rvalue_unchecked(l));
+ /* r5rs says there must be a '.' (unless 'e'?) */
+ /* snprintf(p, STRBUFFSIZE, "%.15g", rvalue_unchecked(l)); */
+ size_t x = strcspn(p, ".e");
+ if (p[x] == 0) {
+ p[x] = '.'; // not found, so add a '.' on the end
+ p[x+1] = 0;
+ }
}
} else if (is_string(l)) {
if (!f) {

Discussion

  • Kevin Cozens

    Kevin Cozens - 2011-08-26
    • summary: atom2str() no decimat point for inexact --> atom2str() no decimal point for inexact
     
  • Kevin Cozens

    Kevin Cozens - 2011-08-29

    The declaration of x will cause some compilers to complain about variables declared after code. It might be better to use strstr() instead of strcspn() as the code is looking for the string ".e" rather than a bunch of characters that are either "." or "e"?

     
  • Doug Currie

    Doug Currie - 2011-08-29

    No, I really am looking for either a '.' or an 'e' -- if the number has either one that it will be read back in as a double, as required, so no need to add a '.'

    Yes, the declaration of x should be moved up in front of the snprintf() for compatibility.

     
  • Kevin Cozens

    Kevin Cozens - 2011-08-29
    • status: open --> closed-fixed
     
  • Kevin Cozens

    Kevin Cozens - 2011-08-29

    Applied slightly modified version of suggested code (revision 80).

     

Log in to post a comment.