From 076f93581b113331d02dd186486b6c80504661c7 Mon Sep 17 00:00:00 2001
From: "Liam M. Healy" <lnp@healy.washington.dc.us>
Date: Wed, 26 May 2010 10:09:49 -0400
Subject: [PATCH] Better C floating point parsing; add dependency in gsll.asd

---
 gsll.asd               |  4 ++--
 test-unit/convert.lisp | 32 ++++++++++++++------------------
 2 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/gsll.asd b/gsll.asd
index 13c0a37c..c0ec10fd 100644
--- a/gsll.asd
+++ b/gsll.asd
@@ -1,6 +1,6 @@
 ;; Definition of GSLL system 
 ;; Liam Healy
-;; Time-stamp: <2010-04-17 18:47:14EDT gsll.asd>
+;; Time-stamp: <2010-05-25 11:54:09EDT gsll.asd>
 ;;
 ;; Copyright 2006, 2007, 2008, 2009 Liam M. Healy
 ;; Distributed under the terms of the GNU General Public License
@@ -160,7 +160,7 @@
 	    ((:file "rng-types")
 	     (:file "generators" :depends-on ("rng-types"))
 	     (:file "quasi" :depends-on ("rng-types" "generators"))
-	     (:file "tests")
+	     (:file "tests" :depends-on ("rng-types"))
 	     (:file "gaussian" :depends-on ("rng-types"))
 	     (:file "gaussian-tail" :depends-on ("rng-types"))
 	     (:file "gaussian-bivariate" :depends-on ("rng-types"))
diff --git a/test-unit/convert.lisp b/test-unit/convert.lisp
index c71a0bb6..3f2715db 100644
--- a/test-unit/convert.lisp
+++ b/test-unit/convert.lisp
@@ -1,6 +1,6 @@
 ;; Convert the GSL tests
 ;; Liam Healy 2010-05-22 13:03:53EDT convert.lisp
-;; Time-stamp: <2010-05-25 23:15:21EDT convert.lisp>
+;; Time-stamp: <2010-05-26 10:05:26EDT convert.lisp>
 
 ;;; This file is not normally loaded; it is only used to convert the
 ;;; GSL tests in C to CL tests.  It requires cl-ppcre, lisp-util, and iterate.
@@ -59,25 +59,21 @@
       (second registers)))
    :simple-calls t))
 
+(defvar *float-parse-regex*
+  ;; Based on advice given in
+  ;; http://www.regular-expressions.info/floatingpoint.html
+  (cl-ppcre:parse-string "([-+]?[0-9]*\\.?[0-9]+)([eE][-+]?[0-9]+)?")
+  "A ppcre regular expression that matches a C floating point number.")
+
 (defun translate-c-numbers (string)
   "Translate the literal numbers in the string to CL double-float."
-  (cl-ppcre:regex-replace-all ; Floats without exponents become double-floats
-   ;;"(\\.\\d*)\\s*(,|\\))"
-   "(\\+|\\-*\\d*\\.\\d*)($|[^0-9de.])"
-   (cl-ppcre:regex-replace-all ; Floats with "e" exponent become double-floats
-    "(\\+|\\-*\\d*\\.*\\d*)e(\\d*(\\+|\\-)*\\d*)"
-    string
-    "\"\\{1}d\\{2}\"")
-   "\"\\{1}d0\"\\{2}"))
-
-#|
-;; http://www.regular-expressions.info/floatingpoint.html
-;; need to exempt d from the first case 
-(cl-ppcre:regex-replace-all "([-+]?[0-9]*\\.?[0-9]+)" "-4.2134" "\\{1}d0")
-(cl-ppcre:regex-replace-all "([-+]?[0-9]*\\.?[0-9]+)[eE](([-+]?[0-9]+)?)"
-			    "1.213e4"
-			    "\\{1}d\\{2}")
-|#
+  (cl-ppcre:regex-replace-all
+   *float-parse-regex*
+   string
+   (lambda (match mant expon)
+     (declare (ignore match))
+     (format nil "~ad~:[0~;~a~]" mant expon (when expon (subseq expon 1))))
+   :simple-calls t))
 
 (defun replace-tolerance (string)
   (cl-ppcre:regex-replace "TEST_(\\w*)" string "+TEST-\\{1}+"))
-- 
GitLab