>>>>> "Vijayendra" == Vijayendra Munikoti writes:
Vijayendra> I have a huge expression containing numbers, which I intend exporting to
Vijayendra> FORTRAN. Is there a way to change all the numbers in the expression to
Vijayendra> double precision fortran format eg. D0,D1 etc.?
Vijayendra> BFLOAT(expression) does this with a difference -- it adds B0, B1 ...
Vijayendra> Is it possible to change this behaviour?
I don't think that's currently possible.
First, fortran eventually calls EXPLODEN to print out numbers. But
EXPLODEN goes out of it's way to print "small" numbers using ~F format
instead of ~E. (It should probably use ~G and forget about the
special cases). But with the ~F format, no exponent is printed. But
even if it were, I think the exponent marker would be E, not D, which
isn't what you want.
This issue could be fixed, but EXPLODEN by using ~E for printing, but
it doesn't know when to use that. It seems, however, that there's a
variable FORTRANP that could be used to tell EXPLODEN about it.
So, here is a patch that implements this. Now, instead of
fortran(3.14159*x) producing "3.14159*x", you get "3.14159d+2*x",
which is what you want, I think.
Ray
Index: src/commac.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/commac.lisp,v
retrieving revision 1.24
diff -u -r1.24 commac.lisp
--- src/commac.lisp 9 Mar 2005 16:07:09 -0000 1.24
+++ src/commac.lisp 21 Jun 2005 15:00:37 -0000
@@ -472,12 +472,16 @@
(setq string (print-invert-case symb)))
((floatp symb)
(let ((a (abs symb)))
+ #+nil
(cond ((or (eql a 0.0)
(and (>= a .001)
(<= a 10000000.0)))
(setq string (format nil "~vf" (+ 1 $fpprec) symb)))
- (t (setq string (format nil "~ve" (+ 4 $fpprec) symb)))))
- (setq string (string-left-trim " " string)))
+ (t (setq string (format nil "~ve" (+ 4 $fpprec) symb))))
+ (setq string (if fortranp
+ (format nil "~ve" (+ 4 $fpprec) symb)
+ (format nil "~vg" (+ 4 $fpprec) symb)))
+ (setq string (string-trim " " string))))
#+(and gcl (not gmp))
((bignump symb)
(let* ((big symb)
Index: src/fortra.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/fortra.lisp,v
retrieving revision 1.3
diff -u -r1.3 fortra.lisp
--- src/fortra.lisp 25 Nov 2004 02:36:02 -0000 1.3
+++ src/fortra.lisp 21 Jun 2005 15:00:37 -0000
@@ -70,8 +70,10 @@
(defprop mexpt msize-infix grind)
(defprop mminus 100. lbp)
- (defprop msetq (#\:) strsym)
- (setq x (mstring x))
+ (defprop msetq (#\:) strsym)
+ (let ((fortranp t)
+ (*read-default-float-format* 'single-float))
+ (setq x (mstring x)))
;; Make sure this gets done before exiting this frame.
(defprop mexpt msz-mexpt grind)
(remprop 'mminus 'lbp)