Home | History | Annotate | Download | only in b_BasicEm
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /* ---- includes ----------------------------------------------------------- */
     18 
     19 #include "b_BasicEm/Functions.h"
     20 #include "b_BasicEm/APh.h"
     21 #include "b_BasicEm/Complex.h"
     22 #include "b_BasicEm/Math.h"
     23 
     24 /* ------------------------------------------------------------------------- */
     25 
     26 /* ========================================================================= */
     27 /*                                                                           */
     28 /* ---- \ghd{ auxiliary functions } ---------------------------------------- */
     29 /*                                                                           */
     30 /* ========================================================================= */
     31 
     32 /* ------------------------------------------------------------------------- */
     33 
     34 /* ========================================================================= */
     35 /*                                                                           */
     36 /* ---- \ghd{ constructor / destructor } ----------------------------------- */
     37 /*                                                                           */
     38 /* ========================================================================= */
     39 
     40 /* ------------------------------------------------------------------------- */
     41 
     42 /* ========================================================================= */
     43 /*                                                                           */
     44 /* ---- \ghd{ operators } -------------------------------------------------- */
     45 /*                                                                           */
     46 /* ========================================================================= */
     47 
     48 flag bbs_APh_equal( struct bbs_APh aph1A,
     49 					struct bbs_APh aph2A )
     50 {
     51 	return ( aph1A.absE == aph2A.absE ) && ( aph1A.phaseE == aph2A.phaseE );
     52 }
     53 
     54 /* ------------------------------------------------------------------------- */
     55 
     56 /* ========================================================================= */
     57 /*                                                                           */
     58 /* ---- \ghd{ query functions } -------------------------------------------- */
     59 /*                                                                           */
     60 /* ========================================================================= */
     61 
     62 /* ------------------------------------------------------------------------- */
     63 
     64 /* ========================================================================= */
     65 /*                                                                           */
     66 /* ---- \ghd{ modify functions } ------------------------------------------- */
     67 /*                                                                           */
     68 /* ========================================================================= */
     69 
     70 /* ------------------------------------------------------------------------- */
     71 
     72 /* ========================================================================= */
     73 /*                                                                           */
     74 /* ---- \ghd{ I/O } -------------------------------------------------------- */
     75 /*                                                                           */
     76 /* ========================================================================= */
     77 
     78 /* ------------------------------------------------------------------------- */
     79 
     80 uint32 bbs_APh_memSize( struct bbs_Context* cpA,
     81 					    struct bbs_APh aPhA )
     82 {
     83 	return bbs_SIZEOF16( aPhA.absE ) + bbs_SIZEOF16( aPhA.phaseE );
     84 }
     85 
     86 /* ------------------------------------------------------------------------- */
     87 
     88 uint32 bbs_APh_memWrite( struct bbs_Context* cpA,
     89 						 const struct bbs_APh* ptrA,
     90 						 uint16* memPtrA )
     91 {
     92 	memPtrA += bbs_memWrite16( &ptrA->absE, memPtrA );
     93 	memPtrA += bbs_memWrite16( &ptrA->phaseE, memPtrA );
     94 	return bbs_APh_memSize( cpA, *ptrA );
     95 }
     96 
     97 /* ------------------------------------------------------------------------- */
     98 
     99 uint32 bbs_APh_memRead( struct bbs_Context* cpA,
    100 					    struct bbs_APh* ptrA,
    101 						const uint16* memPtrA )
    102 {
    103 	if( bbs_Context_error( cpA ) ) return 0;
    104 	memPtrA += bbs_memRead16( &ptrA->absE, memPtrA );
    105 	memPtrA += bbs_memRead16( &ptrA->phaseE, memPtrA );
    106 	return bbs_APh_memSize( cpA, *ptrA );
    107 }
    108 
    109 /* ------------------------------------------------------------------------- */
    110 
    111 /* ========================================================================= */
    112 /*                                                                           */
    113 /* ---- \ghd{ exec functions } --------------------------------------------- */
    114 /*                                                                           */
    115 /* ========================================================================= */
    116 
    117 struct bbs_APh bbs_APh_conj( const struct bbs_APh aPhA )
    118 {
    119 	struct bbs_APh aphL;
    120 	aphL.absE = aPhA.absE;
    121 	aphL.phaseE = - aPhA.phaseE;
    122 	return aphL;
    123 }
    124 
    125 /* ------------------------------------------------------------------------- */
    126 
    127 void bbs_APh_importComplex( struct bbs_APh* dstPtrA,
    128 							const struct bbs_Complex* srcPtrA )
    129 {
    130 	dstPtrA->absE = bbs_sqrt32( ( int32 ) srcPtrA->realE * srcPtrA->realE + ( int32 ) srcPtrA->imagE * srcPtrA->imagE );
    131 	dstPtrA->phaseE = bbs_phase16( srcPtrA->realE, srcPtrA->imagE );
    132 }
    133 
    134 /* ========================================================================= */
    135 
    136 
    137