This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: format ~F bug


Per,

> > I found a bug in the 'format' procedure. It is very easy to 
> reproduce:
> 
> Could you try to figure out what the problem is?
> The actual conversion is done by the format method of the 
> LispReadFormat non-public class in gnu/kawa/functions/LispFormat.java.

Here is a patch that seems to work (at least all the test cases pass). More
tests are welcome.

Index: ExponentialFormat.java
===================================================================
RCS file: /cvs/kawa/kawa/gnu/math/ExponentialFormat.java,v
retrieving revision 1.1
diff -c -r1.1 ExponentialFormat.java
*** ExponentialFormat.java      30 Jun 1999 18:23:34 -0000      1.1
--- ExponentialFormat.java      19 Jan 2005 21:24:16 -0000
***************
*** 44,54 ****
    {
      for (int j = digEnd ;  ; )
        {
!       if (--j == digStart)
!         {
!           sbuf.insert(j, '1');
!           return true;
!         }
        char ch = sbuf.charAt(j);
        if (ch != '9')
          {
--- 44,50 ----
    {
      for (int j = digEnd ;  ; )
        {
!         --j;
        char ch = sbuf.charAt(j);
        if (ch != '9')
          {
***************
*** 56,61 ****
--- 52,62 ----
            return false;
          }
        sbuf.setCharAt(j, '0');
+         if (j == digStart)
+         {
+           sbuf.insert(j, '1');
+           return true;
+         }
        }
    }


I also included a few more test cases in formatst.scm:

Index: formatst.scm
===================================================================
RCS file: /cvs/kawa/kawa/testsuite/formatst.scm,v
retrieving revision 1.5
diff -c -r1.5 formatst.scm
*** formatst.scm        3 Jan 2005 00:58:26 -0000       1.5
--- formatst.scm        19 Jan 2005 21:23:47 -0000
***************
*** 488,493 ****
--- 488,495 ----
    (test '("~1f" 3.141) "3.")
    (test '("~f" 123.56789) "123.56789")
    (test '("~f" -314.0) "-314.0")
+   (test '("~f" 0.6) "0.6")
+   (test '("~f" 0.7) "0.7")
    (test '("~f" 1e4) "10000.0")
    (test '("~f" -1.23e10) "-12300000000.0")
    (test '("~f" 1e-4) "0.0001")
***************
*** 504,509 ****
--- 506,513 ----
   (format:floats
    (test '("~e" 3.14159) "3.14159E+0")
    (test '("~e" 0.00001234) "1.234E-5")
+   (test '("~e" 0.6) "6.0E-1")
+   (test '("~e" 0.7) "7.0E-1")
    (test '("~,,,0e" 0.00001234) "0.1234E-4")
    (test '("~,3e" 3.14159) "3.142E+0")
    (test '("~,3@e" 3.14159) "+3.142E+0")


Dominique



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]