[MLton-commit] r4192

Matthew Fluet MLton@mlton.org
Thu, 10 Nov 2005 12:04:46 -0800


Fixed two bugs in Time.scan.
 * An Overflow exception (manifesting as a Time exception) in the
   calculation of nanoseconds from fractional seconds.  Reported by
   varming@itu.dk.
 * Noticed a latent bug whereby "~.417" was not scanned.


----------------------------------------------------------------------

U   mlton/trunk/basis-library/system/time.sml
A   mlton/trunk/regression/time4.ok
A   mlton/trunk/regression/time4.sml

----------------------------------------------------------------------

Modified: mlton/trunk/basis-library/system/time.sml
===================================================================
--- mlton/trunk/basis-library/system/time.sml	2005-11-10 17:53:04 UTC (rev 4191)
+++ mlton/trunk/basis-library/system/time.sml	2005-11-10 20:04:43 UTC (rev 4192)
@@ -92,6 +92,7 @@
 val toString = fmt 3
 
 (* Adapted from the ML Kit 4.1.4; basislib/Time.sml
+ * by mfluet@acm.org on 2005-11-10 based on
  * by mfluet@acm.org on 2005-8-10 based on
  *  adaptations from the ML Kit 3 Version; basislib/Time.sml
  *  by sweeks@research.nj.nec.com on 1999-1-3.
@@ -103,10 +104,14 @@
         | pow10 n = 10 * pow10 (n-1)
       fun mkTime sign intv fracv decs =
          let
-            val nsec = (pow10 (10-decs) * fracv + 5) div 10
+            val nsec = 
+               LargeInt.div (LargeInt.+ (LargeInt.* (Int.toLarge (pow10 (10 - decs)), 
+                                                     Int.toLarge fracv),
+                                         5), 
+                             10)
             val t =
                LargeInt.+ (LargeInt.* (Int.toLarge intv, ticksPerSecond),
-                           Int.toLarge nsec)
+                           nsec)
             val t = if sign then t else LargeInt.~ t 
          in
             T t
@@ -139,6 +144,7 @@
       fun int sign src =
          case getc src of
             NONE           => NONE
+          | SOME (#".", rest) => frac sign 0 rest
           | SOME (c, rest) => 
                (case charToDigit c of
                    NONE   => NONE

Added: mlton/trunk/regression/time4.ok
===================================================================
--- mlton/trunk/regression/time4.ok	2005-11-10 17:53:04 UTC (rev 4191)
+++ mlton/trunk/regression/time4.ok	2005-11-10 20:04:43 UTC (rev 4192)
@@ -0,0 +1,8 @@
+0.417
+0.999
+0.417
+0.999
+~0.417
+~0.999
+~0.417
+~0.999

Added: mlton/trunk/regression/time4.sml
===================================================================
--- mlton/trunk/regression/time4.sml	2005-11-10 17:53:04 UTC (rev 4191)
+++ mlton/trunk/regression/time4.sml	2005-11-10 20:04:43 UTC (rev 4192)
@@ -0,0 +1,24 @@
+
+val t = valOf (Time.fromString "0.417")
+val () = print (concat [Time.toString t, "\n"])
+
+val t = valOf (Time.fromString "0.999")
+val () = print (concat [Time.toString t, "\n"])
+
+val t = valOf (Time.fromString ".417")
+val () = print (concat [Time.toString t, "\n"])
+
+val t = valOf (Time.fromString ".999")
+val () = print (concat [Time.toString t, "\n"])
+
+val t = valOf (Time.fromString "~0.417")
+val () = print (concat [Time.toString t, "\n"])
+
+val t = valOf (Time.fromString "~0.999")
+val () = print (concat [Time.toString t, "\n"])
+
+val t = valOf (Time.fromString "~.417")
+val () = print (concat [Time.toString t, "\n"])
+
+val t = valOf (Time.fromString "~.999")
+val () = print (concat [Time.toString t, "\n"])