This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


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

patch to unif.c...


Hello,

I keep running into this problem over and over again when I'm working
with uniform vectors; There isn't a good clean way to generate a
vector of floats vs doubles.  The current interface depends on the
internal representation chosen by scm_makdbl which is a little
obtuse.  Right now, 

  (make-uniform-vector 3 0.5) -> array of 3 floats
  (make-uniform-vector 3 0.4) -> array of 3 doubles

That is a bit counterintuitive and it's a big problem when I'm trying
to interface with C.

In the patch below I've extended the mechanism used to
distinguish short and long to include float, double and complex.
Specifically, 

  (make-uniform-vector 3 's) -> array of 3 shorts 
  (make-uniform-vector 3 'l) -> array of 3 longs
  (make-uniform-vector 3 'f) -> array of 3 floats
  (make-uniform-vector 3 'd) -> array of 3 doubles
  (make-uniform-vector 3 'c) -> array of 3 longs

This is all cut and pasted as a big block from about 10 lines down and
I only used about 30 keystrokes (ie. it doesn't trigger the "big
patch, need papers" clause for contributions.).

I'd appreciate it if this could be added to unif.c.

Thanks,

Clark

************************************************************
--- unif.c      Thu Nov 25 16:25:26 1999
+++ unif.new.c  Thu Nov 25 16:48:12 1999
@@ -193,6 +193,25 @@
          type = scm_tc7_llvect;
        }
 #endif
+#ifdef SCM_FLOATS
+#ifdef SCM_SINGLES
+      else if (s = 'f')
+        {
+          i = sizeof (float) * k;
+          type = scm_tc7_fvect;
+        }
+#endif
+      else if (s == 'c')
+        {
+          i = 2 * sizeof (double) * k;
+          type = scm_tc7_cvect;
+        }
+      else if (s == 'd')
+        {
+          i = sizeof (double) * k;
+          type = scm_tc7_dvect;
+        }
+#endif
       else
        {
          return scm_make_vector (SCM_MAKINUM (k), SCM_UNDEFINED);

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