veccpx.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand        --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------


partial class VECCPX_LENGTH_MIXIN{

partial class VECCPX_LENGTH_MIXIN{ CT < $REAL{CT}, ET < $COMPLEX{CT,ET}, VT < $VEC{ET,VT}, } is -- This partial class produces those routines which are common to both complex number vector classes. -- Version 1.1 Sep 97. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 13 Jul 96 mbk Original for Sather 1.1 Dist -- 4 Sep 97 kh Modified for style. include VEC{ET} ; private element_one : ET is -- This routine returns the element whose numeric value is one. return ET::one end ; private element_zero:ET is -- This routine returns the element whose numeric value is zero. return ET::zero end ; length_zero : CT is -- This routine returns the value of the component type which is zero. return CT::zero end ; length_one : CT is -- This routine returns the value of the component type which is one. return CT::one end ; inplace_normalized is -- This routine normalises the vector in place. inplace_scaled_by(ET::create_real(length_one / length)) end ; length_squared : CT is -- This routine returns the square of the vector length, obtained by -- summing the squares of the individual components. res : CT := length_zero ; loop index : CARD := asize.times! ; temp : ET := [index] ; res := res + temp.re * temp.re + temp.im * temp.im end ; return res end ; length : CT is -- This routine returns the length of the vector. return length_squared.sqrt end ; dot( other : SAME ) : ET pre same_size(other) is -- This routine returns the dot product of self and other. res : ET := element_zero ; loop index : CARD := asize.times! ; res := res + [index] * other[index].conjugate end ; return res end ; distance_to_squared( other : SAME ) : CT pre same_size(other) is -- This routine returns the square of the distance between the vectors -- self and other. res : CT := length_zero ; loop index : CARD := asize.times! ; temp : ET := [index] - other[index] ; res := res + temp.re * temp.re + temp.im * temp.im end ; return res end ; distance_to( other : SAME ) : CT is -- This ruine returns the distance betwwen the vectors self and other. return distance_to_squared(other).sqrt end ; bounded_distance_to_squared( other : SAME, sbnd : CT ) : CT pre same_size(other) is -- This routine returns either the squared distance between self and -- other or, if the given bound is exceeded, void. res : CT := length_zero ; loop index : CARD := asize.times! ; temp : ET := [index] - other[index] ; res := res + temp.re * temp.re + temp.im * temp.im ; if res > sbnd then return void end end ; return res end ; cosine_angle_with( other : SAME ) : CT pre same_size(other) is -- This routine returns the cosine of the angle between the two vectors -- self and other, calculated from the suj of the parts divided by a -- normalising figure derived from the length. res : CT := length_zero ; loop index : CARD := asize.times! ; cos_val : CT := [index] ; other_cos_val : CT := other[index] ; res := res + cos_val.re * other_cos_val.re - cos_val.im * other_cos_val.im end ; return res / (length * other.length) end ; angle_with( other : SAME ) : ANGLE is -- This routine returns the angle between self and other. return ANGLE::acos(cosine_angle_with(other)) end ; end ; -- VECCPX_LENGTH_MIXIN

class VECCPX < $VEC{CPX,VECCPX,FLT}

class VECCPX < $VEC{CPX,VECCPX,FLT} is -- This class implements complex vectors. -- Version 1.1 Sep 97. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 13 Jul 96 mbk Original for Sather 1.1 Dist -- 4 Sep 97 kh Modified for style. include VECCPX_LENGTH_MIXIN{FLT,CPX,SAME} ; const length_zero : FLT := 0.0 ; const length_one : FLT := 1.0 ; -- The following two routines implement 'constant' values zero & one. element_one : CPX is return CPX::create(1.0,0.0) end ; element_zero : CPX is return CPX::create(0.0,0.0) end ; end ; -- VECCPX

class VECCPXD < $VEC{CPXD,VECCPXD,FLTD}

class VECCPXD < $VEC{CPXD,VECCPXD,FLTD} is -- This class implements double length complex vectors. -- Version 1.1 Sep 97. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 13 Jul 96 mbk Original for Sather 1.1 Dist -- 4 Sep 97 kh Modified for style. include VECCPX_LENGTH_MIXIN{FLTD,CPXD,SAME} ; const length_zero : FLTD := 0.0d ; const length_one : FLTD := 1.0d ; -- The following two routines implement 'constant' values zero & one. element_one : CPXD is return CPXD::create(1.0d,0.0d) end ; element_zero : CPXD is return CPXD::create(0.0d,0.0d) end ; end ; -- VECCPXD