1 /* srfi-4.c --- Homogeneous numeric vector datatypes.
3 * Copyright (C) 2001 Free Software Foundation, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software; see the file COPYING. If not, write to
17 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307 USA
20 * As a special exception, the Free Software Foundation gives
21 * permission for additional uses of the text contained in its release
24 * The exception is that, if you link the GUILE library with other
25 * files to produce an executable, this does not by itself cause the
26 * resulting executable to be covered by the GNU General Public
27 * License. Your use of that executable is in no way restricted on
28 * account of linking the GUILE library code into it.
30 * This exception does not however invalidate any other reasons why
31 * the executable file might be covered by the GNU General Public
34 * This exception applies only to the code released by the Free
35 * Software Foundation under the name GUILE. If you copy code from
36 * other Free Software Foundation releases into a copy of GUILE, as
37 * the General Public License permits, the exception does not apply to
38 * the code that you add in this way. To avoid misleading anyone as
39 * to the status of such modified files, you must delete this
40 * exception notice from them.
42 * If you write modifications of your own for GUILE, it is your choice
43 * whether to permit this exception to apply to your modifications.
44 * If you do not wish that, delete this exception notice. */
51 /* For brevity and maintainability, we define our own types for the
52 various integer and floating point types. */
53 typedef unsigned char int_u8
;
54 typedef signed char int_s8
;
55 typedef unsigned short int_u16
;
56 typedef signed short int_s16
;
57 typedef unsigned int int_u32
;
58 typedef signed int int_s32
;
61 typedef unsigned long int_u64
;
62 typedef signed long int_s64
;
64 typedef unsigned long long int_u64
;
65 typedef signed long long int_s64
;
66 #endif /* SIZEOF_LONG */
67 #endif /* HAVE_LONG_LONG */
68 typedef float float_f32
;
69 typedef double float_f64
;
72 /* Smob type code for homogeneous numeric vectors. */
73 int scm_tc16_uvec
= 0;
76 /* Accessor macros for the three components of a homogeneous numeric
78 - The type tag (one of the symbolic constants below).
79 - The vector's length (counted in elements).
80 - The address of the data area (holding the elements of the
82 #define SCM_UVEC_TYPE(u) (SCM_CELL_WORD_1(u))
83 #define SCM_UVEC_LENGTH(u) (SCM_CELL_WORD_2(u))
84 #define SCM_UVEC_BASE(u) (SCM_CELL_OBJECT_3(u))
87 /* Symbolic constants encoding the various types of homogeneous
91 #define SCM_UVEC_U16 2
92 #define SCM_UVEC_S16 3
93 #define SCM_UVEC_U32 4
94 #define SCM_UVEC_S32 5
95 #define SCM_UVEC_U64 6
96 #define SCM_UVEC_S64 7
97 #define SCM_UVEC_F32 8
98 #define SCM_UVEC_F64 9
101 /* This array maps type tags to the size of the elements. */
102 static int uvec_sizes
[10] = {1, 1, 2, 2, 4, 4, 8, 8, 4, 8};
105 /* ================================================================ */
106 /* SMOB procedures. */
107 /* ================================================================ */
110 /* Smob print hook for homogeneous vectors. */
112 uvec_print (SCM uvec
, SCM port
, scm_print_state
*pstate SCM_UNUSED
)
114 switch (SCM_UVEC_TYPE (uvec
))
118 int_u8
* p
= (int_u8
*) SCM_UVEC_BASE (uvec
);
121 scm_puts ("#u8(", port
);
122 if (SCM_UVEC_LENGTH (uvec
) > 0)
124 scm_intprint (*p
, 10, port
);
127 for (; i
< SCM_UVEC_LENGTH (uvec
); i
++)
129 scm_puts (" ", port
);
130 scm_intprint (*p
, 10, port
);
134 scm_puts (")", port
);
140 int_s8
* p
= (int_s8
*) SCM_UVEC_BASE (uvec
);
143 scm_puts ("#s8(", port
);
144 if (SCM_UVEC_LENGTH (uvec
) > 0)
146 scm_intprint (*p
, 10, port
);
149 for (; i
< SCM_UVEC_LENGTH (uvec
); i
++)
151 scm_puts (" ", port
);
152 scm_intprint (*p
, 10, port
);
156 scm_puts (")", port
);
162 int_u16
* p
= (int_u16
*) SCM_UVEC_BASE (uvec
);
165 scm_puts ("#u16(", port
);
166 if (SCM_UVEC_LENGTH (uvec
) > 0)
168 scm_intprint (*p
, 10, port
);
171 for (; i
< SCM_UVEC_LENGTH (uvec
); i
++)
173 scm_puts (" ", port
);
174 scm_intprint (*p
, 10, port
);
178 scm_puts (")", port
);
184 int_s16
* p
= (int_s16
*) SCM_UVEC_BASE (uvec
);
187 scm_puts ("#s16(", port
);
188 if (SCM_UVEC_LENGTH (uvec
) > 0)
190 scm_intprint (*p
, 10, port
);
193 for (; i
< SCM_UVEC_LENGTH (uvec
); i
++)
195 scm_puts (" ", port
);
196 scm_intprint (*p
, 10, port
);
200 scm_puts (")", port
);
206 int_u32
* p
= (int_u32
*) SCM_UVEC_BASE (uvec
);
209 scm_puts ("#u32(", port
);
210 if (SCM_UVEC_LENGTH (uvec
) > 0)
212 scm_intprint (*p
, 10, port
);
215 for (; i
< SCM_UVEC_LENGTH (uvec
); i
++)
217 scm_puts (" ", port
);
218 scm_intprint (*p
, 10, port
);
222 scm_puts (")", port
);
228 int_s32
* p
= (int_s32
*) SCM_UVEC_BASE (uvec
);
231 scm_puts ("#s32(", port
);
232 if (SCM_UVEC_LENGTH (uvec
) > 0)
234 scm_intprint (*p
, 10, port
);
237 for (; i
< SCM_UVEC_LENGTH (uvec
); i
++)
239 scm_puts (" ", port
);
240 scm_intprint (*p
, 10, port
);
244 scm_puts (")", port
);
248 #ifdef HAVE_LONG_LONG
251 int_u64
* p
= (int_u64
*) SCM_UVEC_BASE (uvec
);
254 scm_puts ("#u64(", port
);
255 if (SCM_UVEC_LENGTH (uvec
) > 0)
257 scm_intprint (*p
, 10, port
);
260 for (; i
< SCM_UVEC_LENGTH (uvec
); i
++)
262 scm_puts (" ", port
);
263 scm_intprint (*p
, 10, port
);
267 scm_puts (")", port
);
273 int_s64
* p
= (int_s64
*) SCM_UVEC_BASE (uvec
);
276 scm_puts ("#s64(", port
);
277 if (SCM_UVEC_LENGTH (uvec
) > 0)
279 scm_intprint (*p
, 10, port
);
282 for (; i
< SCM_UVEC_LENGTH (uvec
); i
++)
284 scm_puts (" ", port
);
285 scm_intprint (*p
, 10, port
);
289 scm_puts (")", port
);
296 float_f32
* p
= (float_f32
*) SCM_UVEC_BASE (uvec
);
299 scm_puts ("#f32(", port
);
300 if (SCM_UVEC_LENGTH (uvec
) > 0)
302 scm_iprin1 (scm_make_real (*p
), port
, pstate
);
305 for (; i
< SCM_UVEC_LENGTH (uvec
); i
++)
307 scm_puts (" ", port
);
308 scm_iprin1 (scm_make_real (*p
), port
, pstate
);
312 scm_puts (")", port
);
318 float_f64
* p
= (float_f64
*) SCM_UVEC_BASE (uvec
);
321 scm_puts ("#f64(", port
);
322 if (SCM_UVEC_LENGTH (uvec
) > 0)
324 scm_iprin1 (scm_make_real (*p
), port
, pstate
);
327 for (; i
< SCM_UVEC_LENGTH (uvec
); i
++)
329 scm_puts (" ", port
);
330 scm_iprin1 (scm_make_real (*p
), port
, pstate
);
334 scm_puts (")", port
);
339 abort (); /* Sanity check. */
345 /* Smob free hook for homogeneous numeric vectors. */
349 scm_gc_free (SCM_UVEC_BASE (uvec
),
350 SCM_UVEC_LENGTH (uvec
) * uvec_sizes
[SCM_UVEC_TYPE (uvec
)],
356 /* ================================================================ */
357 /* Utility procedures. */
358 /* ================================================================ */
361 /* Create a new, uninitialized homogeneous numeric vector of type TYPE
362 with space for LEN elements. */
364 make_uvec (const char * func_name
, int type
, int len
)
368 p
= scm_gc_malloc (len
* uvec_sizes
[type
], "uvec");
369 SCM_RETURN_NEWSMOB3 (scm_tc16_uvec
, type
, len
, p
);
373 /* ================================================================ */
375 /* ================================================================ */
378 SCM_DEFINE (scm_u8vector_p
, "u8vector?", 1, 0, 0,
380 "Return @code{#t} if @var{obj} is a vector of type u8,\n"
381 "@code{#f} otherwise.")
382 #define FUNC_NAME s_scm_u8vector_p
384 return SCM_BOOL (SCM_SMOB_PREDICATE (scm_tc16_uvec
, obj
) &&
385 SCM_UVEC_TYPE (obj
) == SCM_UVEC_U8
);
390 SCM_DEFINE (scm_make_u8vector
, "make-u8vector", 1, 1, 0,
392 "Create a newly allocated homogeneous numeric vector which can\n"
393 "hold @var{len} elements. If @var{fill} is given, it is used to\n"
394 "initialize the elements, otherwise the contents of the vector\n"
396 #define FUNC_NAME s_scm_make_u8vector
403 SCM_VALIDATE_INUM (1, n
);
404 count
= SCM_INUM (n
);
405 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_U8
, count
);
406 if (SCM_UNBNDP (fill
))
410 unsigned int s
= scm_num2uint (fill
, 2, FUNC_NAME
);
412 if ((unsigned int) f
!= s
)
413 scm_out_of_range_pos (FUNC_NAME
, fill
, SCM_MAKINUM (2));
415 p
= (int_u8
*) SCM_UVEC_BASE (uvec
);
423 SCM_DEFINE (scm_u8vector
, "u8vector", 0, 0, 1,
425 "Create a newly allocated homogeneous numeric vector containing\n"
426 "all argument values.")
427 #define FUNC_NAME s_scm_u8vector
429 SCM_VALIDATE_REST_ARGUMENT (l
);
430 return scm_list_to_u8vector (l
);
435 SCM_DEFINE (scm_u8vector_length
, "u8vector-length", 1, 0, 0,
437 "Return the number of elements in the homogeneous numeric vector\n"
439 #define FUNC_NAME s_scm_u8vector_length
441 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
442 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U8
)
443 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
444 return scm_int2num (SCM_UVEC_LENGTH (uvec
));
449 SCM_DEFINE (scm_u8vector_ref
, "u8vector-ref", 2, 0, 0,
450 (SCM uvec
, SCM index
),
451 "Return the element at @var{index} in the homogeneous numeric\n"
452 "vector @var{uvec}.")
453 #define FUNC_NAME s_scm_u8vector_ref
457 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
458 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U8
)
459 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
461 idx
= scm_num2int (index
, 2, FUNC_NAME
);
462 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
463 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
465 return scm_short2num (((int_u8
*) SCM_UVEC_BASE (uvec
))[idx
]);
470 SCM_DEFINE (scm_u8vector_set_x
, "u8vector-set!", 3, 0, 0,
471 (SCM uvec
, SCM index
, SCM value
),
472 "Set the element at @var{index} in the homogeneous numeric\n"
473 "vector @var{uvec} to @var{value}. The return value is not\n"
475 #define FUNC_NAME s_scm_u8vector_ref
481 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
482 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U8
)
483 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
485 idx
= scm_num2int (index
, 2, FUNC_NAME
);
486 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
487 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
489 s
= scm_num2uint (value
, 3, FUNC_NAME
);
491 if ((unsigned int) f
!= s
)
492 scm_out_of_range_pos (FUNC_NAME
, value
, SCM_MAKINUM (3));
494 ((int_u8
*) SCM_UVEC_BASE (uvec
))[idx
] = f
;
495 return SCM_UNSPECIFIED
;
500 SCM_DEFINE (scm_u8vector_to_list
, "u8vector->list", 1, 0, 0,
502 "Convert the homogeneous numeric vector @var{uvec} to a list.")
503 #define FUNC_NAME s_scm_u8vector_to_list
509 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
510 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U8
)
511 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
513 idx
= SCM_UVEC_LENGTH (uvec
);
514 p
= (int_u8
*) SCM_UVEC_BASE (uvec
) + idx
;
518 res
= scm_cons (SCM_MAKINUM (*p
), res
);
525 SCM_DEFINE (scm_list_to_u8vector
, "list->u8vector", 1, 0, 0,
527 "Convert the list @var{l}, which must only contain unsigned\n"
528 "8-bit values, to a numeric homogeneous vector.")
529 #define FUNC_NAME s_scm_list_to_u8vector
537 SCM_VALIDATE_LIST_COPYLEN (1, l
, n
);
539 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_U8
, n
);
540 p
= (int_u8
*) SCM_UVEC_BASE (uvec
);
542 while (SCM_CONSP (tmp
))
545 unsigned int s
= scm_num2uint (SCM_CAR (tmp
), 2, FUNC_NAME
);
547 if ((unsigned int) f
!= s
)
548 scm_out_of_range (FUNC_NAME
, SCM_CAR (tmp
));
553 scm_remember_upto_here_1 (l
);
559 /* ================================================================ */
561 /* ================================================================ */
564 SCM_DEFINE (scm_s8vector_p
, "s8vector?", 1, 0, 0,
566 "Return @code{#t} if @var{obj} is a vector of type s8,\n"
567 "@code{#f} otherwise.")
568 #define FUNC_NAME s_scm_s8vector_p
570 return SCM_BOOL (SCM_SMOB_PREDICATE (scm_tc16_uvec
, obj
) &&
571 SCM_UVEC_TYPE (obj
) == SCM_UVEC_S8
);
576 SCM_DEFINE (scm_make_s8vector
, "make-s8vector", 1, 1, 0,
578 "Create a newly allocated homogeneous numeric vector which can\n"
579 "hold @var{len} elements. If @var{fill} is given, it is used to\n"
580 "initialize the elements, otherwise the contents of the vector\n"
582 #define FUNC_NAME s_scm_make_s8vector
589 SCM_VALIDATE_INUM (1, n
);
590 count
= SCM_INUM (n
);
591 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_S8
, count
);
592 if (SCM_UNBNDP (fill
))
596 signed int s
= scm_num2int (fill
, 2, FUNC_NAME
);
598 if ((signed int) f
!= s
)
599 scm_out_of_range_pos (FUNC_NAME
, fill
, SCM_MAKINUM (2));
601 p
= (int_s8
*) SCM_UVEC_BASE (uvec
);
609 SCM_DEFINE (scm_s8vector
, "s8vector", 0, 0, 1,
611 "Create a newly allocated homogeneous numeric vector containing\n"
612 "all argument values.")
613 #define FUNC_NAME s_scm_s8vector
615 SCM_VALIDATE_REST_ARGUMENT (l
);
616 return scm_list_to_s8vector (l
);
621 SCM_DEFINE (scm_s8vector_length
, "s8vector-length", 1, 0, 0,
623 "Return the number of elements in the homogeneous numeric vector\n"
625 #define FUNC_NAME s_scm_s8vector_length
627 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
628 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S8
)
629 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
630 return scm_int2num (SCM_UVEC_LENGTH (uvec
));
635 SCM_DEFINE (scm_s8vector_ref
, "s8vector-ref", 2, 0, 0,
636 (SCM uvec
, SCM index
),
637 "Return the element at @var{index} in the homogeneous numeric\n"
638 "vector @var{uvec}.")
639 #define FUNC_NAME s_scm_s8vector_ref
643 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
644 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S8
)
645 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
647 idx
= scm_num2int (index
, 2, FUNC_NAME
);
648 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
649 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
651 return scm_short2num (((int_s8
*) SCM_UVEC_BASE (uvec
))[idx
]);
656 SCM_DEFINE (scm_s8vector_set_x
, "s8vector-set!", 3, 0, 0,
657 (SCM uvec
, SCM index
, SCM value
),
658 "Set the element at @var{index} in the homogeneous numeric\n"
659 "vector @var{uvec} to @var{value}. The return value is not\n"
661 #define FUNC_NAME s_scm_s8vector_ref
667 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
668 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S8
)
669 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
671 idx
= scm_num2int (index
, 2, FUNC_NAME
);
672 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
673 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
675 s
= scm_num2int (value
, 3, FUNC_NAME
);
677 if ((signed int) f
!= s
)
678 scm_out_of_range_pos (FUNC_NAME
, value
, SCM_MAKINUM (3));
680 ((int_s8
*) SCM_UVEC_BASE (uvec
))[idx
] = f
;
681 return SCM_UNSPECIFIED
;
686 SCM_DEFINE (scm_s8vector_to_list
, "s8vector->list", 1, 0, 0,
688 "Convert the homogeneous numeric vector @var{uvec} to a list.")
689 #define FUNC_NAME s_scm_s8vector_to_list
695 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
696 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S8
)
697 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
699 idx
= SCM_UVEC_LENGTH (uvec
);
700 p
= (int_s8
*) SCM_UVEC_BASE (uvec
) + idx
;
704 res
= scm_cons (SCM_MAKINUM (*p
), res
);
711 SCM_DEFINE (scm_list_to_s8vector
, "list->s8vector", 1, 0, 0,
713 "Convert the list @var{l}, which must only contain signed\n"
714 "8-bit values, to a numeric homogeneous vector.")
715 #define FUNC_NAME s_scm_list_to_s8vector
723 SCM_VALIDATE_LIST_COPYLEN (1, l
, n
);
725 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_S8
, n
);
726 p
= (int_s8
*) SCM_UVEC_BASE (uvec
);
728 while (SCM_CONSP (tmp
))
733 s
= scm_num2int (SCM_CAR (tmp
), 2, FUNC_NAME
);
735 if ((signed int) f
!= s
)
736 scm_out_of_range (FUNC_NAME
, SCM_CAR (tmp
));
741 scm_remember_upto_here_1 (l
);
747 /* ================================================================ */
748 /* U16 procedures. */
749 /* ================================================================ */
752 SCM_DEFINE (scm_u16vector_p
, "u16vector?", 1, 0, 0,
754 "Return @code{#t} if @var{obj} is a vector of type u16,\n"
755 "@code{#f} otherwise.")
756 #define FUNC_NAME s_scm_u16vector_p
758 return SCM_BOOL (SCM_SMOB_PREDICATE (scm_tc16_uvec
, obj
) &&
759 SCM_UVEC_TYPE (obj
) == SCM_UVEC_U16
);
764 SCM_DEFINE (scm_make_u16vector
, "make-u16vector", 1, 1, 0,
766 "Create a newly allocated homogeneous numeric vector which can\n"
767 "hold @var{len} elements. If @var{fill} is given, it is used to\n"
768 "initialize the elements, otherwise the contents of the vector\n"
770 #define FUNC_NAME s_scm_make_u16vector
777 SCM_VALIDATE_INUM (1, n
);
778 count
= SCM_INUM (n
);
779 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_U16
, count
);
780 if (SCM_UNBNDP (fill
))
783 f
= scm_num2ushort (fill
, 2, FUNC_NAME
);
784 p
= (int_u16
*) SCM_UVEC_BASE (uvec
);
792 SCM_DEFINE (scm_u16vector
, "u16vector", 0, 0, 1,
794 "Create a newly allocated homogeneous numeric vector containing\n"
795 "all argument values.")
796 #define FUNC_NAME s_scm_u16vector
798 SCM_VALIDATE_REST_ARGUMENT (l
);
799 return scm_list_to_u16vector (l
);
804 SCM_DEFINE (scm_u16vector_length
, "u16vector-length", 1, 0, 0,
806 "Return the number of elements in the homogeneous numeric vector\n"
808 #define FUNC_NAME s_scm_u16vector_length
810 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
811 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U16
)
812 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
813 return scm_int2num (SCM_UVEC_LENGTH (uvec
));
818 SCM_DEFINE (scm_u16vector_ref
, "u16vector-ref", 2, 0, 0,
819 (SCM uvec
, SCM index
),
820 "Return the element at @var{index} in the homogeneous numeric\n"
821 "vector @var{uvec}.")
822 #define FUNC_NAME s_scm_u16vector_ref
826 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
827 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U16
)
828 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
830 idx
= scm_num2int (index
, 2, FUNC_NAME
);
831 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
832 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
834 return scm_ushort2num (((int_u16
*) SCM_UVEC_BASE (uvec
))[idx
]);
839 SCM_DEFINE (scm_u16vector_set_x
, "u16vector-set!", 3, 0, 0,
840 (SCM uvec
, SCM index
, SCM value
),
841 "Set the element at @var{index} in the homogeneous numeric\n"
842 "vector @var{uvec} to @var{value}. The return value is not\n"
844 #define FUNC_NAME s_scm_u16vector_ref
849 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
850 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U16
)
851 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
853 idx
= scm_num2int (index
, 2, FUNC_NAME
);
854 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
855 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
857 f
= scm_num2ushort (value
, 3, FUNC_NAME
);
859 ((int_u16
*) SCM_UVEC_BASE (uvec
))[idx
] = f
;
860 return SCM_UNSPECIFIED
;
865 SCM_DEFINE (scm_u16vector_to_list
, "u16vector->list", 1, 0, 0,
867 "Convert the homogeneous numeric vector @var{uvec} to a list.")
868 #define FUNC_NAME s_scm_u16vector_to_list
874 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
875 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U16
)
876 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
878 idx
= SCM_UVEC_LENGTH (uvec
);
879 p
= (int_u16
*) SCM_UVEC_BASE (uvec
) + idx
;
883 res
= scm_cons (SCM_MAKINUM (*p
), res
);
890 SCM_DEFINE (scm_list_to_u16vector
, "list->u16vector", 1, 0, 0,
892 "Convert the list @var{l}, which must only contain unsigned\n"
893 "16-bit values, to a numeric homogeneous vector.")
894 #define FUNC_NAME s_scm_list_to_u16vector
901 SCM_VALIDATE_LIST_COPYLEN (1, l
, n
);
903 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_U16
, n
);
904 p
= (int_u16
*) SCM_UVEC_BASE (uvec
);
905 while (SCM_CONSP (l
))
907 int_u16 f
= scm_num2ushort (SCM_CAR (l
), 2, FUNC_NAME
);
917 /* ================================================================ */
918 /* S16 procedures. */
919 /* ================================================================ */
922 SCM_DEFINE (scm_s16vector_p
, "s16vector?", 1, 0, 0,
924 "Return @code{#t} if @var{obj} is a vector of type s16,\n"
925 "@code{#f} otherwise.")
926 #define FUNC_NAME s_scm_s16vector_p
928 return SCM_BOOL (SCM_SMOB_PREDICATE (scm_tc16_uvec
, obj
) &&
929 SCM_UVEC_TYPE (obj
) == SCM_UVEC_S16
);
934 SCM_DEFINE (scm_make_s16vector
, "make-s16vector", 1, 1, 0,
936 "Create a newly allocated homogeneous numeric vector which can\n"
937 "hold @var{len} elements. If @var{fill} is given, it is used to\n"
938 "initialize the elements, otherwise the contents of the vector\n"
940 #define FUNC_NAME s_scm_make_s16vector
947 SCM_VALIDATE_INUM (1, n
);
948 count
= SCM_INUM (n
);
949 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_S16
, count
);
950 if (SCM_UNBNDP (fill
))
953 f
= scm_num2short (fill
, 2, FUNC_NAME
);
954 p
= (int_s16
*) SCM_UVEC_BASE (uvec
);
962 SCM_DEFINE (scm_s16vector
, "s16vector", 0, 0, 1,
964 "Create a newly allocated homogeneous numeric vector containing\n"
965 "all argument values.")
966 #define FUNC_NAME s_scm_s16vector
968 SCM_VALIDATE_REST_ARGUMENT (l
);
969 return scm_list_to_s16vector (l
);
974 SCM_DEFINE (scm_s16vector_length
, "s16vector-length", 1, 0, 0,
976 "Return the number of elements in the homogeneous numeric vector\n"
978 #define FUNC_NAME s_scm_s16vector_length
980 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
981 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S16
)
982 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
983 return scm_int2num (SCM_UVEC_LENGTH (uvec
));
988 SCM_DEFINE (scm_s16vector_ref
, "s16vector-ref", 2, 0, 0,
989 (SCM uvec
, SCM index
),
990 "Return the element at @var{index} in the homogeneous numeric\n"
991 "vector @var{uvec}.")
992 #define FUNC_NAME s_scm_s16vector_ref
996 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
997 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S16
)
998 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1000 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1001 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1002 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1004 return scm_short2num (((int_s16
*) SCM_UVEC_BASE (uvec
))[idx
]);
1009 SCM_DEFINE (scm_s16vector_set_x
, "s16vector-set!", 3, 0, 0,
1010 (SCM uvec
, SCM index
, SCM value
),
1011 "Set the element at @var{index} in the homogeneous numeric\n"
1012 "vector @var{uvec} to @var{value}. The return value is not\n"
1014 #define FUNC_NAME s_scm_s16vector_ref
1019 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1020 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S16
)
1021 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1023 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1024 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1025 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1027 f
= scm_num2short (value
, 3, FUNC_NAME
);
1029 ((int_s16
*) SCM_UVEC_BASE (uvec
))[idx
] = f
;
1030 return SCM_UNSPECIFIED
;
1035 SCM_DEFINE (scm_s16vector_to_list
, "s16vector->list", 1, 0, 0,
1037 "Convert the homogeneous numeric vector @var{uvec} to a list.")
1038 #define FUNC_NAME s_scm_s16vector_to_list
1044 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1045 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S16
)
1046 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1048 idx
= SCM_UVEC_LENGTH (uvec
);
1049 p
= (int_s16
*) SCM_UVEC_BASE (uvec
) + idx
;
1053 res
= scm_cons (SCM_MAKINUM (*p
), res
);
1060 SCM_DEFINE (scm_list_to_s16vector
, "list->s16vector", 1, 0, 0,
1062 "Convert the list @var{l}, which must only contain signed\n"
1063 "16-bit values, to a numeric homogeneous vector.")
1064 #define FUNC_NAME s_scm_list_to_s16vector
1072 SCM_VALIDATE_LIST_COPYLEN (1, l
, n
);
1074 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_S16
, n
);
1075 p
= (int_s16
*) SCM_UVEC_BASE (uvec
);
1077 while (SCM_CONSP (tmp
))
1079 int_s16 f
= scm_num2short (SCM_CAR (tmp
), 2, FUNC_NAME
);
1081 tmp
= SCM_CDR (tmp
);
1084 scm_remember_upto_here_1 (l
);
1090 /* ================================================================ */
1091 /* U32 procedures. */
1092 /* ================================================================ */
1095 SCM_DEFINE (scm_u32vector_p
, "u32vector?", 1, 0, 0,
1097 "Return @code{#t} if @var{obj} is a vector of type u32,\n"
1098 "@code{#f} otherwise.")
1099 #define FUNC_NAME s_scm_u32vector_p
1101 return SCM_BOOL (SCM_SMOB_PREDICATE (scm_tc16_uvec
, obj
) &&
1102 SCM_UVEC_TYPE (obj
) == SCM_UVEC_U32
);
1107 SCM_DEFINE (scm_make_u32vector
, "make-u32vector", 1, 1, 0,
1109 "Create a newly allocated homogeneous numeric vector which can\n"
1110 "hold @var{len} elements. If @var{fill} is given, it is used to\n"
1111 "initialize the elements, otherwise the contents of the vector\n"
1113 #define FUNC_NAME s_scm_make_u32vector
1120 SCM_VALIDATE_INUM (1, n
);
1121 count
= SCM_INUM (n
);
1122 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_U32
, count
);
1123 if (SCM_UNBNDP (fill
))
1126 f
= scm_num2uint (fill
, 2, FUNC_NAME
);
1127 p
= (int_u32
*) SCM_UVEC_BASE (uvec
);
1135 SCM_DEFINE (scm_u32vector
, "u32vector", 0, 0, 1,
1137 "Create a newly allocated homogeneous numeric vector containing\n"
1138 "all argument values.")
1139 #define FUNC_NAME s_scm_u32vector
1141 SCM_VALIDATE_REST_ARGUMENT (l
);
1142 return scm_list_to_u32vector (l
);
1147 SCM_DEFINE (scm_u32vector_length
, "u32vector-length", 1, 0, 0,
1149 "Return the number of elements in the homogeneous numeric vector\n"
1151 #define FUNC_NAME s_scm_u32vector_length
1153 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1154 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U32
)
1155 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1156 return scm_int2num (SCM_UVEC_LENGTH (uvec
));
1161 SCM_DEFINE (scm_u32vector_ref
, "u32vector-ref", 2, 0, 0,
1162 (SCM uvec
, SCM index
),
1163 "Return the element at @var{index} in the homogeneous numeric\n"
1164 "vector @var{uvec}.")
1165 #define FUNC_NAME s_scm_u32vector_ref
1169 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1170 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U32
)
1171 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1173 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1174 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1175 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1177 return scm_uint2num (((int_u32
*) SCM_UVEC_BASE (uvec
))[idx
]);
1182 SCM_DEFINE (scm_u32vector_set_x
, "u32vector-set!", 3, 0, 0,
1183 (SCM uvec
, SCM index
, SCM value
),
1184 "Set the element at @var{index} in the homogeneous numeric\n"
1185 "vector @var{uvec} to @var{value}. The return value is not\n"
1187 #define FUNC_NAME s_scm_u32vector_ref
1192 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1193 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U32
)
1194 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1196 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1197 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1198 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1200 f
= scm_num2uint (value
, 3, FUNC_NAME
);
1202 ((int_u32
*) SCM_UVEC_BASE (uvec
))[idx
] = f
;
1203 return SCM_UNSPECIFIED
;
1208 SCM_DEFINE (scm_u32vector_to_list
, "u32vector->list", 1, 0, 0,
1210 "Convert the homogeneous numeric vector @var{uvec} to a list.")
1211 #define FUNC_NAME s_scm_u32vector_to_list
1217 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1218 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U32
)
1219 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1221 idx
= SCM_UVEC_LENGTH (uvec
);
1222 p
= (int_u32
*) SCM_UVEC_BASE (uvec
) + idx
;
1226 res
= scm_cons (scm_uint2num (*p
), res
);
1233 SCM_DEFINE (scm_list_to_u32vector
, "list->u32vector", 1, 0, 0,
1235 "Convert the list @var{l}, which must only contain unsigned\n"
1236 "32-bit values, to a numeric homogeneous vector.")
1237 #define FUNC_NAME s_scm_list_to_u32vector
1244 SCM_VALIDATE_LIST_COPYLEN (1, l
, n
);
1246 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_U32
, n
);
1247 p
= (int_u32
*) SCM_UVEC_BASE (uvec
);
1248 while (SCM_CONSP (l
))
1251 f
= scm_num2uint (SCM_CAR (l
), 2, FUNC_NAME
);
1261 /* ================================================================ */
1262 /* S32 procedures. */
1263 /* ================================================================ */
1266 SCM_DEFINE (scm_s32vector_p
, "s32vector?", 1, 0, 0,
1268 "Return @code{#t} if @var{obj} is a vector of type s32,\n"
1269 "@code{#f} otherwise.")
1270 #define FUNC_NAME s_scm_s32vector_p
1272 return SCM_BOOL (SCM_SMOB_PREDICATE (scm_tc16_uvec
, obj
) &&
1273 SCM_UVEC_TYPE (obj
) == SCM_UVEC_S32
);
1278 SCM_DEFINE (scm_make_s32vector
, "make-s32vector", 1, 1, 0,
1280 "Create a newly allocated homogeneous numeric vector which can\n"
1281 "hold @var{len} elements. If @var{fill} is given, it is used to\n"
1282 "initialize the elements, otherwise the contents of the vector\n"
1284 #define FUNC_NAME s_scm_make_s32vector
1291 SCM_VALIDATE_INUM (1, n
);
1292 count
= SCM_INUM (n
);
1293 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_S32
, count
);
1294 if (SCM_UNBNDP (fill
))
1297 f
= scm_num2int (fill
, 2, FUNC_NAME
);
1298 p
= (int_s32
*) SCM_UVEC_BASE (uvec
);
1306 SCM_DEFINE (scm_s32vector
, "s32vector", 0, 0, 1,
1308 "Create a newly allocated homogeneous numeric vector containing\n"
1309 "all argument values.")
1310 #define FUNC_NAME s_scm_s32vector
1312 SCM_VALIDATE_REST_ARGUMENT (l
);
1313 return scm_list_to_s32vector (l
);
1318 SCM_DEFINE (scm_s32vector_length
, "s32vector-length", 1, 0, 0,
1320 "Return the number of elements in the homogeneous numeric vector\n"
1322 #define FUNC_NAME s_scm_s32vector_length
1324 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1325 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S32
)
1326 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1327 return scm_int2num (SCM_UVEC_LENGTH (uvec
));
1332 SCM_DEFINE (scm_s32vector_ref
, "s32vector-ref", 2, 0, 0,
1333 (SCM uvec
, SCM index
),
1334 "Return the element at @var{index} in the homogeneous numeric\n"
1335 "vector @var{uvec}.")
1336 #define FUNC_NAME s_scm_s32vector_ref
1340 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1341 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S32
)
1342 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1344 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1345 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1346 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1348 return scm_int2num (((int_s32
*) SCM_UVEC_BASE (uvec
))[idx
]);
1353 SCM_DEFINE (scm_s32vector_set_x
, "s32vector-set!", 3, 0, 0,
1354 (SCM uvec
, SCM index
, SCM value
),
1355 "Set the element at @var{index} in the homogeneous numeric\n"
1356 "vector @var{uvec} to @var{value}. The return value is not\n"
1358 #define FUNC_NAME s_scm_s32vector_ref
1363 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1364 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S32
)
1365 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1367 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1368 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1369 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1371 f
= scm_num2int (value
, 3, FUNC_NAME
);
1373 ((int_s32
*) SCM_UVEC_BASE (uvec
))[idx
] = f
;
1374 return SCM_UNSPECIFIED
;
1379 SCM_DEFINE (scm_s32vector_to_list
, "s32vector->list", 1, 0, 0,
1381 "Convert the homogeneous numeric vector @var{uvec} to a list.")
1382 #define FUNC_NAME s_scm_s32vector_to_list
1388 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1389 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S32
)
1390 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1392 idx
= SCM_UVEC_LENGTH (uvec
);
1393 p
= (int_s32
*) SCM_UVEC_BASE (uvec
) + idx
;
1397 res
= scm_cons (scm_int2num (*p
), res
);
1404 SCM_DEFINE (scm_list_to_s32vector
, "list->s32vector", 1, 0, 0,
1406 "Convert the list @var{l}, which must only contain signed\n"
1407 "32-bit values, to a numeric homogeneous vector.")
1408 #define FUNC_NAME s_scm_list_to_s32vector
1415 SCM_VALIDATE_LIST_COPYLEN (1, l
, n
);
1417 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_S32
, n
);
1418 p
= (int_s32
*) SCM_UVEC_BASE (uvec
);
1419 while (SCM_CONSP (l
))
1422 f
= scm_num2int (SCM_CAR (l
), 2, FUNC_NAME
);
1432 #ifdef HAVE_LONG_LONG
1434 /* ================================================================ */
1435 /* U64 procedures. */
1436 /* ================================================================ */
1439 SCM_DEFINE (scm_u64vector_p
, "u64vector?", 1, 0, 0,
1441 "Return @code{#t} if @var{obj} is a vector of type u64,\n"
1442 "@code{#f} otherwise.")
1443 #define FUNC_NAME s_scm_u64vector_p
1445 return SCM_BOOL (SCM_SMOB_PREDICATE (scm_tc16_uvec
, obj
) &&
1446 SCM_UVEC_TYPE (obj
) == SCM_UVEC_U64
);
1451 SCM_DEFINE (scm_make_u64vector
, "make-u64vector", 1, 1, 0,
1453 "Create a newly allocated homogeneous numeric vector which can\n"
1454 "hold @var{len} elements. If @var{fill} is given, it is used to\n"
1455 "initialize the elements, otherwise the contents of the vector\n"
1457 #define FUNC_NAME s_scm_make_u64vector
1464 SCM_VALIDATE_INUM (1, n
);
1465 count
= SCM_INUM (n
);
1466 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_U64
, count
);
1467 if (SCM_UNBNDP (fill
))
1470 f
= scm_num2ulong_long (fill
, 2, FUNC_NAME
);
1471 p
= (int_u64
*) SCM_UVEC_BASE (uvec
);
1479 SCM_DEFINE (scm_u64vector
, "u64vector", 0, 0, 1,
1481 "Create a newly allocated homogeneous numeric vector containing\n"
1482 "all argument values.")
1483 #define FUNC_NAME s_scm_u64vector
1485 SCM_VALIDATE_REST_ARGUMENT (l
);
1486 return scm_list_to_u64vector (l
);
1491 SCM_DEFINE (scm_u64vector_length
, "u64vector-length", 1, 0, 0,
1493 "Return the number of elements in the homogeneous numeric vector\n"
1495 #define FUNC_NAME s_scm_u64vector_length
1497 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1498 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U64
)
1499 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1500 return scm_int2num (SCM_UVEC_LENGTH (uvec
));
1505 SCM_DEFINE (scm_u64vector_ref
, "u64vector-ref", 2, 0, 0,
1506 (SCM uvec
, SCM index
),
1507 "Return the element at @var{index} in the homogeneous numeric\n"
1508 "vector @var{uvec}.")
1509 #define FUNC_NAME s_scm_u64vector_ref
1513 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1514 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U64
)
1515 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1517 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1518 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1519 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1521 return scm_ulong_long2num (((int_u64
*) SCM_UVEC_BASE (uvec
))[idx
]);
1526 SCM_DEFINE (scm_u64vector_set_x
, "u64vector-set!", 3, 0, 0,
1527 (SCM uvec
, SCM index
, SCM value
),
1528 "Set the element at @var{index} in the homogeneous numeric\n"
1529 "vector @var{uvec} to @var{value}. The return value is not\n"
1531 #define FUNC_NAME s_scm_u64vector_ref
1536 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1537 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U64
)
1538 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1540 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1541 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1542 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1544 f
= scm_num2ulong_long (value
, 3, FUNC_NAME
);
1546 ((int_u64
*) SCM_UVEC_BASE (uvec
))[idx
] = f
;
1547 return SCM_UNSPECIFIED
;
1552 SCM_DEFINE (scm_u64vector_to_list
, "u64vector->list", 1, 0, 0,
1554 "Convert the homogeneous numeric vector @var{uvec} to a list.")
1555 #define FUNC_NAME s_scm_u64vector_to_list
1561 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1562 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_U64
)
1563 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1565 idx
= SCM_UVEC_LENGTH (uvec
);
1566 p
= (int_u64
*) SCM_UVEC_BASE (uvec
) + idx
;
1570 res
= scm_cons (scm_long_long2num (*p
), res
);
1577 SCM_DEFINE (scm_list_to_u64vector
, "list->u64vector", 1, 0, 0,
1579 "Convert the list @var{l}, which must only contain unsigned\n"
1580 "64-bit values, to a numeric homogeneous vector.")
1581 #define FUNC_NAME s_scm_list_to_u64vector
1588 SCM_VALIDATE_LIST_COPYLEN (1, l
, n
);
1590 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_U64
, n
);
1591 p
= (int_u64
*) SCM_UVEC_BASE (uvec
);
1592 while (SCM_CONSP (l
))
1595 f
= scm_num2ulong_long (SCM_CAR (l
), 2, FUNC_NAME
);
1605 /* ================================================================ */
1606 /* S64 procedures. */
1607 /* ================================================================ */
1610 SCM_DEFINE (scm_s64vector_p
, "s64vector?", 1, 0, 0,
1612 "Return @code{#t} if @var{obj} is a vector of type s64,\n"
1613 "@code{#f} otherwise.")
1614 #define FUNC_NAME s_scm_s64vector_p
1616 return SCM_BOOL (SCM_SMOB_PREDICATE (scm_tc16_uvec
, obj
) &&
1617 SCM_UVEC_TYPE (obj
) == SCM_UVEC_S64
);
1622 SCM_DEFINE (scm_make_s64vector
, "make-s64vector", 1, 1, 0,
1624 "Create a newly allocated homogeneous numeric vector which can\n"
1625 "hold @var{len} elements. If @var{fill} is given, it is used to\n"
1626 "initialize the elements, otherwise the contents of the vector\n"
1628 #define FUNC_NAME s_scm_make_s64vector
1635 SCM_VALIDATE_INUM (1, n
);
1636 count
= SCM_INUM (n
);
1637 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_S64
, count
);
1638 if (SCM_UNBNDP (fill
))
1641 f
= scm_num2long_long (fill
, 2, FUNC_NAME
);
1642 p
= (int_s64
*) SCM_UVEC_BASE (uvec
);
1650 SCM_DEFINE (scm_s64vector
, "s64vector", 0, 0, 1,
1652 "Create a newly allocated homogeneous numeric vector containing\n"
1653 "all argument values.")
1654 #define FUNC_NAME s_scm_s64vector
1656 SCM_VALIDATE_REST_ARGUMENT (l
);
1657 return scm_list_to_s64vector (l
);
1662 SCM_DEFINE (scm_s64vector_length
, "s64vector-length", 1, 0, 0,
1664 "Return the number of elements in the homogeneous numeric vector\n"
1666 #define FUNC_NAME s_scm_s64vector_length
1668 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1669 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S64
)
1670 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1671 return scm_int2num (SCM_UVEC_LENGTH (uvec
));
1676 SCM_DEFINE (scm_s64vector_ref
, "s64vector-ref", 2, 0, 0,
1677 (SCM uvec
, SCM index
),
1678 "Return the element at @var{index} in the homogeneous numeric\n"
1679 "vector @var{uvec}.")
1680 #define FUNC_NAME s_scm_s64vector_ref
1684 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1685 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S64
)
1686 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1688 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1689 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1690 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1692 return scm_long_long2num (((int_s64
*) SCM_UVEC_BASE (uvec
))[idx
]);
1697 SCM_DEFINE (scm_s64vector_set_x
, "s64vector-set!", 3, 0, 0,
1698 (SCM uvec
, SCM index
, SCM value
),
1699 "Set the element at @var{index} in the homogeneous numeric\n"
1700 "vector @var{uvec} to @var{value}. The return value is not\n"
1702 #define FUNC_NAME s_scm_s64vector_ref
1707 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1708 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S64
)
1709 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1711 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1712 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1713 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1715 f
= scm_num2long_long (value
, 3, FUNC_NAME
);
1717 ((int_s64
*) SCM_UVEC_BASE (uvec
))[idx
] = f
;
1718 return SCM_UNSPECIFIED
;
1723 SCM_DEFINE (scm_s64vector_to_list
, "s64vector->list", 1, 0, 0,
1725 "Convert the homogeneous numeric vector @var{uvec} to a list.")
1726 #define FUNC_NAME s_scm_s64vector_to_list
1732 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1733 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_S64
)
1734 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1736 idx
= SCM_UVEC_LENGTH (uvec
);
1737 p
= (int_s64
*) SCM_UVEC_BASE (uvec
) + idx
;
1741 res
= scm_cons (scm_long_long2num (*p
), res
);
1748 SCM_DEFINE (scm_list_to_s64vector
, "list->s64vector", 1, 0, 0,
1750 "Convert the list @var{l}, which must only contain signed\n"
1751 "64-bit values, to a numeric homogeneous vector.")
1752 #define FUNC_NAME s_scm_list_to_s64vector
1759 SCM_VALIDATE_LIST_COPYLEN (1, l
, n
);
1761 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_S64
, n
);
1762 p
= (int_s64
*) SCM_UVEC_BASE (uvec
);
1763 while (SCM_CONSP (l
))
1766 f
= scm_num2long_long (SCM_CAR (l
), 2, FUNC_NAME
);
1775 #endif /* HAVE_LONG_LONG */
1778 /* ================================================================ */
1779 /* F32 procedures. */
1780 /* ================================================================ */
1783 SCM_DEFINE (scm_f32vector_p
, "f32vector?", 1, 0, 0,
1785 "Return @code{#t} if @var{obj} is a vector of type f32,\n"
1786 "@code{#f} otherwise.")
1787 #define FUNC_NAME s_scm_f32vector_p
1789 return SCM_BOOL (SCM_SMOB_PREDICATE (scm_tc16_uvec
, obj
) &&
1790 SCM_UVEC_TYPE (obj
) == SCM_UVEC_F32
);
1795 SCM_DEFINE (scm_make_f32vector
, "make-f32vector", 1, 1, 0,
1797 "Create a newly allocated homogeneous numeric vector which can\n"
1798 "hold @var{len} elements. If @var{fill} is given, it is used to\n"
1799 "initialize the elements, otherwise the contents of the vector\n"
1801 #define FUNC_NAME s_scm_make_f32vector
1808 SCM_VALIDATE_INUM (1, n
);
1809 count
= SCM_INUM (n
);
1810 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_F32
, count
);
1811 if (SCM_UNBNDP (fill
))
1815 double d
= scm_num2dbl (fill
, FUNC_NAME
);
1818 /* This test somehow fails for even the simplest inexact
1819 numbers, like 3.1. Must find out how to check properly. */
1821 scm_out_of_range_pos (FUNC_NAME
, fill
, SCM_MAKINUM (2));
1824 p
= (float_f32
*) SCM_UVEC_BASE (uvec
);
1832 SCM_DEFINE (scm_f32vector
, "f32vector", 0, 0, 1,
1834 "Create a newly allocated homogeneous numeric vector containing\n"
1835 "all argument values.")
1836 #define FUNC_NAME s_scm_f32vector
1838 SCM_VALIDATE_REST_ARGUMENT (l
);
1839 return scm_list_to_f32vector (l
);
1844 SCM_DEFINE (scm_f32vector_length
, "f32vector-length", 1, 0, 0,
1846 "Return the number of elements in the homogeneous numeric vector\n"
1848 #define FUNC_NAME s_scm_f32vector_length
1850 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1851 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_F32
)
1852 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1853 return scm_int2num (SCM_UVEC_LENGTH (uvec
));
1858 SCM_DEFINE (scm_f32vector_ref
, "f32vector-ref", 2, 0, 0,
1859 (SCM uvec
, SCM index
),
1860 "Return the element at @var{index} in the homogeneous numeric\n"
1861 "vector @var{uvec}.")
1862 #define FUNC_NAME s_scm_f32vector_ref
1866 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1867 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_F32
)
1868 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1870 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1871 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1872 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1874 return scm_make_real (((float_f32
*) SCM_UVEC_BASE (uvec
))[idx
]);
1879 SCM_DEFINE (scm_f32vector_set_x
, "f32vector-set!", 3, 0, 0,
1880 (SCM uvec
, SCM index
, SCM value
),
1881 "Set the element at @var{index} in the homogeneous numeric\n"
1882 "vector @var{uvec} to @var{value}. The return value is not\n"
1884 #define FUNC_NAME s_scm_f32vector_ref
1890 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1891 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_F32
)
1892 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1894 idx
= scm_num2int (index
, 2, FUNC_NAME
);
1895 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
1896 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
1898 d
= scm_num2dbl (value
, FUNC_NAME
);
1901 /* This test somehow fails for even the simplest inexact
1902 numbers, like 3.1. Must find out how to check properly. */
1904 scm_out_of_range_pos (FUNC_NAME
, value
, SCM_MAKINUM (3));
1907 ((float_f32
*) SCM_UVEC_BASE (uvec
))[idx
] = f
;
1908 return SCM_UNSPECIFIED
;
1913 SCM_DEFINE (scm_f32vector_to_list
, "f32vector->list", 1, 0, 0,
1915 "Convert the homogeneous numeric vector @var{uvec} to a list.")
1916 #define FUNC_NAME s_scm_f32vector_to_list
1922 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
1923 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_F32
)
1924 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
1926 idx
= SCM_UVEC_LENGTH (uvec
);
1927 p
= (float_f32
*) SCM_UVEC_BASE (uvec
) + idx
;
1931 res
= scm_cons (scm_make_real (*p
), res
);
1938 SCM_DEFINE (scm_list_to_f32vector
, "list->f32vector", 1, 0, 0,
1940 "Convert the list @var{l}, which must only contain unsigned\n"
1941 "8-bit values, to a numeric homogeneous vector.")
1942 #define FUNC_NAME s_scm_list_to_f32vector
1949 SCM_VALIDATE_LIST_COPYLEN (1, l
, n
);
1951 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_F32
, n
);
1952 p
= (float_f32
*) SCM_UVEC_BASE (uvec
);
1953 while (SCM_CONSP (l
))
1957 d
= scm_num2dbl (SCM_CAR (l
), FUNC_NAME
);
1960 /* This test somehow fails for even the simplest inexact
1961 numbers, like 3.1. Must find out how to check properly. */
1963 scm_out_of_range_pos (FUNC_NAME
, l
, SCM_MAKINUM (1));
1974 /* ================================================================ */
1975 /* F64 procedures. */
1976 /* ================================================================ */
1979 SCM_DEFINE (scm_f64vector_p
, "f64vector?", 1, 0, 0,
1981 "Return @code{#t} if @var{obj} is a vector of type f64,\n"
1982 "@code{#f} otherwise.")
1983 #define FUNC_NAME s_scm_f64vector_p
1985 return SCM_BOOL (SCM_SMOB_PREDICATE (scm_tc16_uvec
, obj
) &&
1986 SCM_UVEC_TYPE (obj
) == SCM_UVEC_F64
);
1991 SCM_DEFINE (scm_make_f64vector
, "make-f64vector", 1, 1, 0,
1993 "Create a newly allocated homogeneous numeric vector which can\n"
1994 "hold @var{len} elements. If @var{fill} is given, it is used to\n"
1995 "initialize the elements, otherwise the contents of the vector\n"
1997 #define FUNC_NAME s_scm_make_f64vector
2004 SCM_VALIDATE_INUM (1, n
);
2005 count
= SCM_INUM (n
);
2006 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_F64
, count
);
2007 if (SCM_UNBNDP (fill
))
2010 f
= scm_num2dbl (fill
, FUNC_NAME
);
2011 p
= (float_f64
*) SCM_UVEC_BASE (uvec
);
2019 SCM_DEFINE (scm_f64vector
, "f64vector", 0, 0, 1,
2021 "Create a newly allocated homogeneous numeric vector containing\n"
2022 "all argument values.")
2023 #define FUNC_NAME s_scm_f64vector
2025 SCM_VALIDATE_REST_ARGUMENT (l
);
2026 return scm_list_to_f64vector (l
);
2031 SCM_DEFINE (scm_f64vector_length
, "f64vector-length", 1, 0, 0,
2033 "Return the number of elements in the homogeneous numeric vector\n"
2035 #define FUNC_NAME s_scm_f64vector_length
2037 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
2038 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_F64
)
2039 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
2040 return scm_int2num (SCM_UVEC_LENGTH (uvec
));
2045 SCM_DEFINE (scm_f64vector_ref
, "f64vector-ref", 2, 0, 0,
2046 (SCM uvec
, SCM index
),
2047 "Return the element at @var{index} in the homogeneous numeric\n"
2048 "vector @var{uvec}.")
2049 #define FUNC_NAME s_scm_f64vector_ref
2053 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
2054 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_F64
)
2055 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
2057 idx
= scm_num2int (index
, 2, FUNC_NAME
);
2058 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
2059 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
2061 return scm_make_real (((float_f64
*) SCM_UVEC_BASE (uvec
))[idx
]);
2066 SCM_DEFINE (scm_f64vector_set_x
, "f64vector-set!", 3, 0, 0,
2067 (SCM uvec
, SCM index
, SCM value
),
2068 "Set the element at @var{index} in the homogeneous numeric\n"
2069 "vector @var{uvec} to @var{value}. The return value is not\n"
2071 #define FUNC_NAME s_scm_f64vector_ref
2076 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
2077 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_F64
)
2078 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
2080 idx
= scm_num2int (index
, 2, FUNC_NAME
);
2081 if (idx
< 0 || idx
>= SCM_UVEC_LENGTH (uvec
))
2082 scm_out_of_range_pos (FUNC_NAME
, index
, SCM_MAKINUM (2));
2084 f
= scm_num2dbl (value
, FUNC_NAME
);
2086 ((float_f64
*) SCM_UVEC_BASE (uvec
))[idx
] = f
;
2087 return SCM_UNSPECIFIED
;
2092 SCM_DEFINE (scm_f64vector_to_list
, "f64vector->list", 1, 0, 0,
2094 "Convert the homogeneous numeric vector @var{uvec} to a list.")
2095 #define FUNC_NAME s_scm_f64vector_to_list
2101 SCM_VALIDATE_SMOB (1, uvec
, uvec
);
2102 if (SCM_UVEC_TYPE (uvec
) != SCM_UVEC_F64
)
2103 scm_wrong_type_arg (FUNC_NAME
, 1, uvec
);
2105 idx
= SCM_UVEC_LENGTH (uvec
);
2106 p
= (float_f64
*) SCM_UVEC_BASE (uvec
) + idx
;
2110 res
= scm_cons (scm_make_real (*p
), res
);
2117 SCM_DEFINE (scm_list_to_f64vector
, "list->f64vector", 1, 0, 0,
2119 "Convert the list @var{l}, which must only contain signed\n"
2120 "8-bit values, to a numeric homogeneous vector.")
2121 #define FUNC_NAME s_scm_list_to_f64vector
2128 SCM_VALIDATE_LIST_COPYLEN (1, l
, n
);
2130 uvec
= make_uvec (FUNC_NAME
, SCM_UVEC_F64
, n
);
2131 p
= (float_f64
*) SCM_UVEC_BASE (uvec
);
2132 while (SCM_CONSP (l
))
2134 float_f64 f
= scm_num2dbl (SCM_CAR (l
), FUNC_NAME
);
2144 /* Create the smob type for homogeneous numeric vectors and install
2147 scm_init_srfi_4 (void)
2149 scm_tc16_uvec
= scm_make_smob_type ("uvec", 0);
2150 scm_set_smob_free (scm_tc16_uvec
, uvec_free
);
2151 scm_set_smob_print (scm_tc16_uvec
, uvec_print
);
2152 #include "srfi/srfi-4.x"
2155 /* End of srfi-4.c. */