I have a trivial problem for which I can think of many solutions but I
do not like any of them.
I have some Lisp code that does a lot of computations and generates
files in csv format which are later read by R for plotting and simple
analysis. Unfortunately, it looks like some of my functions (actually
those that read data from database) produce double-float results
and when they are saved they have 'd' as sign of exponent. R just does
not believe that if you can have 'd' in exponent.
So to make these files readable I have few possibilities:
1) coerce return value of each function to single-float (it's ok, I do
not really need all those digits). It is a bother.
2) write some new function instead of format, say eformat which will
coerce all double-floats to single-floats before calling format
3) use sed after I saved the file
4) somehow tell format to use 'e' instead of 'd' for exponent. I have
no Idea how to do it.
If it helps -- I use sbcl 1.0.9
Any simple way of doing it I missed?
Thanks!
On Sep 28, 4:26 pm, ··············@gmail.com"
<·············@gmail.com> wrote:
> I have a trivial problem for which I can think of many solutions but I
> do not like any of them.
>
> I have some Lisp code that does a lot of computations and generates
> files in csv format which are later read by R for plotting and simple
> analysis. Unfortunately, it looks like some of my functions (actually
> those that read data from database) produce double-float results
> and when they are saved they have 'd' as sign of exponent. R just does
> not believe that if you can have 'd' in exponent.
>
> So to make these files readable I have few possibilities:
> 1) coerce return value of each function to single-float (it's ok, I do
> not really need all those digits). It is a bother.
> 2) write some new function instead of format, say eformat which will
> coerce all double-floats to single-floats before calling format
> 3) use sed after I saved the file
> 4) somehow tell format to use 'e' instead of 'd' for exponent. I have
> no Idea how to do it.
>
> If it helps -- I use sbcl 1.0.9
>
> Any simple way of doing it I missed?
>
> Thanks!
(setq s (format nil "~18,6,2E" pi))
" 3.141593L+00"
(setf (char s 14) #\E)
#\E
s
" 3.141593E+00"
L is kind of a weird exponent anyway.
--S
On Sep 28, 4:26 pm, ··············@gmail.com"
<·············@gmail.com> wrote:
> I have a trivial problem for which I can think of many solutions but I
> do not like any of them.
>
> I have some Lisp code that does a lot of computations and generates
> files in csv format which are later read by R for plotting and simple
> analysis. Unfortunately, it looks like some of my functions (actually
> those that read data from database) produce double-float results
> and when they are saved they have 'd' as sign of exponent. R just does
> not believe that if you can have 'd' in exponent.
Well, does changing the value of *read-default-float-format* to
'double-float fix the problem for you?
[snip]
> If it helps -- I use sbcl 1.0.9
(let ((*read-default-float-format* 'double-float))
(print 4.5d50))
This seems to work on both ACL and SBCL.
--
Thomas A. Russ, USC/Information Sciences Institute
·············@gmail.com <·············@gmail.com> wrote:
> I have a trivial problem for which I can think of many solutions but I
> do not like any of them.
>
> I have some Lisp code that does a lot of computations and generates
> files in csv format which are later read by R for plotting and simple
> analysis. Unfortunately, it looks like some of my functions (actually
> those that read data from database) produce double-float results
> and when they are saved they have 'd' as sign of exponent. R just does
> not believe that if you can have 'd' in exponent.
>
> So to make these files readable I have few possibilities:
> 1) coerce return value of each function to single-float (it's ok, I do
> not really need all those digits). It is a bother.
> 2) write some new function instead of format, say eformat which will
> coerce all double-floats to single-floats before calling format
> 3) use sed after I saved the file
> 4) somehow tell format to use 'e' instead of 'd' for exponent. I have
> no Idea how to do it.
>
> If it helps -- I use sbcl 1.0.9
>
> Any simple way of doing it I missed?
>
You may look at *read-default-float-format*:
* (defparameter a 2.78d0)
A
* a
2.78d0
* (setf *read-default-float-format* 'double-float)
DOUBLE-FLOAT
* a
2.78
* (setf a 2.78d30)
2.78e30
*
--
Waldek Hebisch
·······@math.uni.wroc.pl
>>>>> "alexey" == alexey <·············@gmail.com> writes:
alexey> I have a trivial problem for which I can think of many solutions but I
alexey> do not like any of them.
alexey> I have some Lisp code that does a lot of computations and generates
alexey> files in csv format which are later read by R for plotting and simple
alexey> analysis. Unfortunately, it looks like some of my functions (actually
alexey> those that read data from database) produce double-float results
alexey> and when they are saved they have 'd' as sign of exponent. R just does
alexey> not believe that if you can have 'd' in exponent.
alexey> So to make these files readable I have few possibilities:
alexey> 1) coerce return value of each function to single-float (it's ok, I do
alexey> not really need all those digits). It is a bother.
alexey> 2) write some new function instead of format, say eformat which will
alexey> coerce all double-floats to single-floats before calling format
alexey> 3) use sed after I saved the file
alexey> 4) somehow tell format to use 'e' instead of 'd' for exponent. I have
alexey> no Idea how to do it.
Look in the spec, and you will see you can change the exponent marker:
(format t "~,,,,,,'EE" 42d0) -> "4.2E+1"
Ray
Thanks, this is really useful. I do not understand this format
specification. Well, back to hyperspec....
On Oct 1, 10:42 am, ···········@ericsson.com (Raymond Toy (RT/EUS))
wrote:
> >>>>> "alexey" == alexey <·············@gmail.com> writes:
>
> alexey> I have a trivial problem for which I can think of many solutions but I
> alexey> do not like any of them.
>
> Look in the spec, and you will see you can change the exponent marker:
>
> (format t "~,,,,,,'EE" 42d0) -> "4.2E+1"
>
> Ray