From: Panayotis Skordos Date: Sun, 30 Jul 1989 23:59:02 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: 20090517-FFI~11914 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=6da489ba28b7e040126d9d7fa980fa861f6b471e;p=mit-scheme.git *** empty log message *** --- diff --git a/v7/src/microcode/array.c b/v7/src/microcode/array.c index 9ac401a54..27e797c26 100644 --- a/v7/src/microcode/array.c +++ b/v7/src/microcode/array.c @@ -30,7 +30,7 @@ Technology nor of any adaptation thereof in any advertising, promotional, or sales literature without prior written consent from MIT in each case. */ -/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/array.c,v 9.37 1989/06/23 03:47:49 pas Rel $ */ +/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/array.c,v 9.38 1989/07/30 23:59:02 pas Exp $ */ #include "scheme.h" @@ -54,6 +54,17 @@ MIT in each case. */ */ +/* mathematical constants */ +#ifdef PI +#undef PI +#endif +#define PI 3.141592653589793238462643 +#define TWOPI 6.283185307179586476925287 +#define SQRT_2 1.4142135623730950488 +#define ONE_OVER_SQRT_2 .7071067811865475244 +/* Abramowitz and Stegun */ + + /* first some utilities */ int Scheme_Number_To_REAL(Arg, Cell) Pointer Arg; REAL *Cell; @@ -517,6 +528,51 @@ DEFINE_PRIMITIVE ("COMPLEX-SUBARRAY-COMPLEX-SCALE!", } +/* Accumulate + using combinators * + corresponding type codes 1 + */ +DEFINE_PRIMITIVE ("COMPLEX-SUBARRAY-ACCUMULATE!", + Prim_complex_subarray_accumulate, 6,6, 0) +{ long at,m,mplus, tc, i; + REAL *a,*b; /* (a,b) = (real,imag) input arrays */ + REAL *c; /* result = output array of length 2, holds a complex number */ + double x, y, temp; + + PRIMITIVE_HEADER (6); + CHECK_ARG (1, ARRAY_P); /* a = input array (real) */ + CHECK_ARG (2, ARRAY_P); /* b = input array (imag) */ + a = Scheme_Array_To_C_Array(ARG_REF(1)); + b = Scheme_Array_To_C_Array(ARG_REF(2)); + if ((Array_Length(ARG_REF(1))) != (Array_Length(ARG_REF(2)))) error_bad_range_arg(2); + tc = arg_nonnegative_integer(3); /* tc = type code 0 or 1 */ + at = arg_nonnegative_integer(4); /* at = starting index */ + m = arg_nonnegative_integer(5); /* m = number of points to process */ + CHECK_ARG (6, ARRAY_P); /* c = output array of length 2 */ + c = Scheme_Array_To_C_Array(ARG_REF(6)); + if ((Array_Length(ARG_REF(6))) != 2) error_bad_range_arg(6); + + mplus = at + m; + if (mplus > (Array_Length(ARG_REF(1)))) error_bad_range_arg(5); + + if (tc==1) + { x = 1.0; /* real part of accumulator */ + y = 0.0; /* imag part of accumulator */ + for (i=at;i LN_MAXDOUBLE) - Primitive_Error(ERR_ARG_1_BAD_RANGE); /* gamma( non-positive integer ) */ - (*b) = ((REAL) (signgam * exp(y))); /* see HPUX Section 3 */ + error_bad_range_arg(1); /* gamma( non-positive integer ) */ + (*b) = ((REAL) (signgam * exp(y))); /* see HPUX Section 3 */ } void REALerf(a,b) REAL *a,*b; { (*b) = ( (REAL) erf((double) (*a)) ); @@ -747,8 +805,9 @@ void REALbessel1(order,a,b) long order; REAL *a,*b; /* Bessel of first kind */ (*b) = ( (REAL) jn(((int) order), ((double) (*a))) ); } void REALbessel2(order,a,b) long order; REAL *a,*b; /* Bessel of second kind */ -{ if ((*a) <= 0.0) - Primitive_Error(ERR_ARG_1_BAD_RANGE); /* Blows Up */ +{ + if ((*a) <= 0.0) + error_bad_range_arg(1); /* Blows Up */ if (order == 0) (*b) = ( (REAL) y0((double) (*a)) ); if (order == 1) @@ -789,29 +848,34 @@ struct array_func_table { #define MAX_ARRAY_FUNCTC 17 -DEFINE_PRIMITIVE ("ARRAY-UNARY-FUNCTION!", Prim_array_unary_function, 2, 2, 0) -{ long Length, i, allocated_cells; +/* array-unary-function! could be called array-operation-1! + following the naming convention for other similar procedures + but it is specialized to mappings only, so we have special name. + */ +DEFINE_PRIMITIVE ("ARRAY-UNARY-FUNCTION!", Prim_array_unary_function, 2,2, 0) +{ long n, i; REAL *a,*b; - SCHEME_ARRAY Result; - long functc; + long tc; void (*f)(); - Primitive_2_Args(); - Arg_1_Type(TC_ARRAY); - Arg_2_Type(TC_FIXNUM); - Length = Array_Length(Arg1); - Range_Check(functc, Arg2, 0, MAX_ARRAY_FUNCTC, ERR_ARG_2_BAD_RANGE); - f = ((Array_Function_Table[functc]).func); - if (1 != (Array_Function_Table[functc]).numofargs) /* check unary */ - Primitive_Error(ERR_ARG_2_WRONG_TYPE); - - Result = Arg1; - a = Scheme_Array_To_C_Array(Arg1); - b = Scheme_Array_To_C_Array(Result); + PRIMITIVE_HEADER (2); + CHECK_ARG (1, ARRAY_P); /* a = input (and output) array */ + CHECK_ARG (2, FIXNUM_P); /* tc = type code */ - for (i=0; i MAX_ARRAY_FUNCTC) error_bad_range_arg(2); + f = ((Array_Function_Table[tc]).func); + if (1 != (Array_Function_Table[tc]).numofargs) error_wrong_type_arg(2); + /* check it is a unary function */ + + a = Scheme_Array_To_C_Array(ARG_REF(1)); + b = a; + n = Array_Length(ARG_REF(1)); + + for (i=0; i0.0) + b[i] = sqrt((r-x)/2.0); /* choose principal root */ + else /* see Abramowitz (p.17 3.7.27) */ + b[i] = -sqrt((r-x)/2.0); + } +} + +void complex_array_sin(a,b,n) + REAL *a,*b; long n; +{ long i; + double x, ey,fy; + REAL temp; - n = Array_Length(ARG_REF(1)); - if (n != Array_Length(ARG_REF(2))) error_bad_range_arg(2); + for (i=0; i