aboutsummaryrefslogtreecommitdiffstats
path: root/libFDK/src/FDK_trigFcts.cpp
blob: a198dc61d77e437c904bd3028da84f085324d853 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
/***************************  Fraunhofer IIS FDK Tools  **********************

                        (C) Copyright Fraunhofer IIS (2005)
                               All Rights Reserved

    Please be advised that this software and/or program delivery is
    Confidential Information of Fraunhofer and subject to and covered by the

    Fraunhofer IIS Software Evaluation Agreement
    between Google Inc. and  Fraunhofer
    effective and in full force since March 1, 2012.

    You may use this software and/or program only under the terms and
    conditions described in the above mentioned Fraunhofer IIS Software
    Evaluation Agreement. Any other and/or further use requires a separate agreement.


   $Id$
   Author(s):   Haricharan Lakshman, Manuel Jander
   Description: Trigonometric functions fixed point fractional implementation.

   This software and/or program is protected by copyright law and international
   treaties. Any reproduction or distribution of this software and/or program,
   or any portion of it, may result in severe civil and criminal penalties, and
   will be prosecuted to the maximum extent possible under law.

******************************************************************************/

#include "FDK_trigFcts.h"

#include "fixpoint_math.h"


// #define CORDIC_SINCOS


#define IMPROVE_ATAN2_ACCURACY  1  // 0 --> 59 dB SNR     1 --> 65 dB SNR
#define MINSFTAB  7
#define MAXSFTAB 25

#if IMPROVE_ATAN2_ACCURACY
static const FIXP_DBL f_atan_expand_range[MAXSFTAB-(MINSFTAB-1)]  =
{
  /*****************************************************************************
   *
   *  Table holds fixp_atan() output values which are outside of input range
   *  of fixp_atan() to improve SNR of fixp_atan2().
   *
   *  This Table might also be used in fixp_atan() [todo] so there a wider input
   *  range can be covered, too.
   *
   *  Matlab (generate table):
   *    for scl = 7:25            % MINSFTAB .. MAXSFTAB
   *      at=atan(0.5 *(2^scl));  % 0.5 because get in 'middle' area of current scale level 'scl'
   *      at/2                    % div at by ATO_SCALE
   *    end
   *
   *  Table divided by 2=ATO_SCALE  <--  SF=ATO_SF
   *****************************************************************************/
   FL2FXCONST_DBL(7.775862990872099e-001), FL2FXCONST_DBL(7.814919928673978e-001), FL2FXCONST_DBL(7.834450483314648e-001),
   FL2FXCONST_DBL(7.844216021392089e-001), FL2FXCONST_DBL(7.849098823026687e-001), FL2FXCONST_DBL(7.851540227918509e-001),
   FL2FXCONST_DBL(7.852760930873737e-001), FL2FXCONST_DBL(7.853371282415015e-001), FL2FXCONST_DBL(7.853676458193612e-001),
   FL2FXCONST_DBL(7.853829046083906e-001), FL2FXCONST_DBL(7.853905340029177e-001), FL2FXCONST_DBL(7.853943487001828e-001),
   FL2FXCONST_DBL(7.853962560488155e-001), FL2FXCONST_DBL(7.853972097231319e-001), FL2FXCONST_DBL(7.853976865602901e-001),
   FL2FXCONST_DBL(7.853979249788692e-001), FL2FXCONST_DBL(7.853980441881587e-001), FL2FXCONST_DBL(7.853981037928035e-001),
   FL2FXCONST_DBL(7.853981335951259e-001)
   //     pi/4 = 0.785398163397448 = pi/2/ATO_SCALE
};
#endif

FIXP_DBL fixp_atan2(FIXP_DBL y, FIXP_DBL x)
{
    FIXP_DBL q;
    FIXP_DBL at;  // atan  out
    FIXP_DBL at2; // atan2 out
    FIXP_DBL ret = FL2FXCONST_DBL(-1.0f);
    INT sf,sfo,stf;

    // --- division

    if      (y > FL2FXCONST_DBL(0.0f))
    {
        if      (x > FL2FXCONST_DBL(0.0f)) {
                                           q =  fDivNormHighPrec( y, x, &sf); // both pos.
        }
        else if (x < FL2FXCONST_DBL(0.0f)) {
                                           q = -fDivNormHighPrec( y,-x, &sf); // x neg.
        }
        else {//(x ==FL2FXCONST_DBL(0.0f))
                                           q =  FL2FXCONST_DBL(+1.0f);  // y/x = pos/zero = +Inf
                                           sf = 0;
        }
    }
    else if (y < FL2FXCONST_DBL(0.0f))
    {
        if      (x > FL2FXCONST_DBL(0.0f)) {
                                           q = -fDivNormHighPrec(-y, x, &sf); // y neg.
        }
        else if (x < FL2FXCONST_DBL(0.0f)) {
                                           q =  fDivNormHighPrec(-y,-x, &sf); // both neg.
        }
        else {//(x ==FL2FXCONST_DBL(0.0f))
                                           q =  FL2FXCONST_DBL(-1.0f);  // y/x = neg/zero = -Inf
                                           sf = 0;
        }
    }
    else { // (y ==FL2FXCONST_DBL(0.0f))
        q = FL2FXCONST_DBL(0.0f);
        sf = 0;
    }
    sfo = sf;
    //write2file(fpF__h,(float)y/(float)x);
    //write2file(fpC__h,(float) q * (float)FDKpow(2,sfo));  // SNR 86 dB  But range not limited to [-64..64] which is the input range of fixp_atan()

    // --- atan()

    if  ( sfo > ATI_SF ) {
        // --- could not calc fixp_atan() here bec of input data out of range
        //     ==> therefore give back boundary values

        #if IMPROVE_ATAN2_ACCURACY
        if (sfo > MAXSFTAB) sfo = MAXSFTAB;
        #endif

        if      (  q > FL2FXCONST_DBL(0.0f) ) {
           #if IMPROVE_ATAN2_ACCURACY
            at = +f_atan_expand_range[sfo-ATI_SF-1];
           #else
            at = FL2FXCONST_DBL( +M_PI/2 / ATO_SCALE);
           #endif
        }
        else if (  q < FL2FXCONST_DBL(0.0f) ) {
           #if IMPROVE_ATAN2_ACCURACY
            at = -f_atan_expand_range[sfo-ATI_SF-1];
           #else
            at = FL2FXCONST_DBL( -M_PI/2 / ATO_SCALE);
           #endif
        }
        else {  // q== FL2FXCONST_DBL(0.0f)
            at = FL2FXCONST_DBL( 0.0f );
        }
    }else{
        // --- calc of fixp_atan() is possible; input data within range
        //     ==> set q on fixed scale level as desired from fixp_atan()
        stf = sfo - ATI_SF;
        if (stf > 0)  q = q << (INT)fMin( stf,DFRACT_BITS-1);
        else          q = q >> (INT)fMin(-stf,DFRACT_BITS-1);
        //write2file(fpF__e,(float)y/(float)x);
        //write2file(fpC__e,(float)q * (float)FDKpow(2,ATI_SF)); // 88.9 dB
        at = fixp_atan(q);  // ATO_SF
    }
    //write2file(fpF__g,(float)FDKatan( (float)y/(float)x ));
    //write2file(fpC__g,(float)   at * (float)FDKpow(2,ATO_SF) ); // todo dB

    // --- atan2()

    at2 = at >> (AT2O_SF - ATO_SF); // now AT2O_SF for atan2
    if      (  x > FL2FXCONST_DBL(0.0f) ) {
        ret = at2;
    }
    else if (  x < FL2FXCONST_DBL(0.0f) ) {
        if (  y >= FL2FXCONST_DBL(0.0f) ) {
            ret = at2 + FL2FXCONST_DBL( M_PI / AT2O_SCALE);
        } else {
            ret = at2 - FL2FXCONST_DBL( M_PI / AT2O_SCALE);
        }
    }
    else {
        // x == 0
        if      ( y >  FL2FXCONST_DBL(0.0f) ) {
            ret = FL2FXCONST_DBL( +M_PI/2 / AT2O_SCALE);
        }
        else if ( y <  FL2FXCONST_DBL(0.0f) ) {
            ret = FL2FXCONST_DBL( -M_PI/2 / AT2O_SCALE);
        }
        else if ( y == FL2FXCONST_DBL(0.0f) ) {
            ret = FL2FXCONST_DBL(0.0f);
        }
    }
    //write2file(fpC__f,(float)ret * (float)FDKpow(2,AT2O_SF));  // 65 dB
    //write2file(fpF__f,(float)FDKatan2(y,x));
    return ret;
}


FIXP_DBL fixp_atan(FIXP_DBL x)
{
    INT sign;
    FIXP_DBL result, temp;

    // SNR of fixp_atan() = 56 dB
    FIXP_DBL ONEBY3P56  = (FIXP_DBL)0x26800000; // 1.0/3.56 in q31
    FIXP_DBL P281       = (FIXP_DBL)0x00013000; // 0.281 in q18
    FIXP_DBL ONEP571    = (FIXP_DBL)0x6487ef00; // 1.571 in q30

    if (x < FIXP_DBL(0)) {
      sign = 1;
      x = - x ;
    } else {
      sign = 0;
    }

    /* calc of arctan */
    if(x < ( Q(Q_ATANINP)-FL2FXCONST_DBL(0.00395)) )
    {
        INT res_e;

        temp = fPow2(x);            // q25 * q25 - (DFRACT_BITS-1) = q19
        temp = fMult(temp, ONEBY3P56);      // q19 * q31 - (DFRACT_BITS-1) = q19
        temp = temp + Q(19);                // q19 + q19 = q19
        result = fDivNorm(x, temp, &res_e);
        result = scaleValue(result, (Q_ATANOUT-Q_ATANINP+19-DFRACT_BITS+1) + res_e  );
    }
    else if( x < FL2FXCONST_DBL(1.28/64.0) )
    {
        FIXP_DBL delta_fix;
        FIXP_DBL PI_BY_4 = FL2FXCONST_DBL(3.1415926/4.0) >> 1; /* pi/4 in q30 */

        delta_fix = (x - FL2FXCONST_DBL(1.0/64.0)) << 5; /* q30 */
        result = PI_BY_4 + (delta_fix >> 1) - (fPow2Div2(delta_fix));
    }
    else
    {
        INT res_e;

        temp = fPow2Div2(x);        // q25 * q25 - (DFRACT_BITS-1) - 1 = q18
        temp = temp + P281;                 // q18 + q18 = q18
        result = fDivNorm(x, temp, &res_e);
        result = scaleValue(result, (Q_ATANOUT-Q_ATANINP+18-DFRACT_BITS+1) + res_e );
        result = ONEP571 - result;          // q30 + q30 = q30
    }
    if (sign) {
      result = -result;
    }

    return(result);
}


#ifndef CORDIC_SINCOS

#include "FDK_tools_rom.h"

FIXP_DBL fixp_cos(FIXP_DBL x, int scale)
{
    FIXP_DBL residual, error, sine, cosine;
    
    residual = fixp_sin_cos_residual_inline(x, scale, &sine, &cosine);
    error = fMult(sine, residual);

    return cosine - error;
}

FIXP_DBL fixp_sin(FIXP_DBL x, int scale)
{
    FIXP_DBL residual, error, sine, cosine;
    
    residual = fixp_sin_cos_residual_inline(x, scale, &sine, &cosine);
    error = fMult(cosine, residual);

    return sine + error;
}

void fixp_cos_sin (FIXP_DBL x, int scale, FIXP_DBL *cos, FIXP_DBL *sin)
{
    FIXP_DBL residual, error0, error1, sine, cosine;
    
    residual = fixp_sin_cos_residual_inline(x, scale, &sine, &cosine);
    error0 = fMult(sine, residual);
    error1 = fMult(cosine, residual);
    *cos  = cosine - error0;
    *sin  = sine + error1;
}

#else /* #ifndef CORDIC_SINCOS */

/*
  // Matlab
  function v = cordic(beta,n)
  % This function computes v = [cos(beta), sin(beta)] (beta in radians)
  % using n iterations. Increasing n will increase the precision.

  if beta < -pi/2 | beta > pi/2
      if beta < 0
          v = cordic(beta + pi, n);
      else
          v = cordic(beta - pi, n);
      end
      v = -v; % flip the sign for second or third quadrant
      return
  end

  % Initialization of tables of constants used by CORDIC
  % need a table of arctangents of negative powers of two, in radians:
  % angles = atan(2.^-(0:27));
  angles =  [  ...
      0.78539816339745   0.46364760900081   0.24497866312686   0.12435499454676 ...
      0.06241880999596   0.03123983343027   0.01562372862048   0.00781234106010 ...
      0.00390623013197   0.00195312251648   0.00097656218956   0.00048828121119 ...
      0.00024414062015   0.00012207031189   0.00006103515617   0.00003051757812 ...
      0.00001525878906   0.00000762939453   0.00000381469727   0.00000190734863 ...
      0.00000095367432   0.00000047683716   0.00000023841858   0.00000011920929 ...
      0.00000005960464   0.00000002980232   0.00000001490116   0.00000000745058 ];
  % and a table of products of reciprocal lengths of vectors [1, 2^-j]:
  Kvalues = [ ...
      0.70710678118655   0.63245553203368   0.61357199107790   0.60883391251775 ...
      0.60764825625617   0.60735177014130   0.60727764409353   0.60725911229889 ...
      0.60725447933256   0.60725332108988   0.60725303152913   0.60725295913894 ...
      0.60725294104140   0.60725293651701   0.60725293538591   0.60725293510314 ...
      0.60725293503245   0.60725293501477   0.60725293501035   0.60725293500925 ...
      0.60725293500897   0.60725293500890   0.60725293500889   0.60725293500888 ];
  Kn = Kvalues(min(n, length(Kvalues)));

  % Initialize loop variables:
  v = [1;0]; % start with 2-vector cosine and sine of zero
  poweroftwo = 1;
  angle = angles(1);

  % Iterations
  for j = 0:n-1;
      if beta < 0
          sigma = -1;
      else
          sigma = 1;
      end
      factor = sigma * poweroftwo;
      R = [1, -factor; factor, 1];
      v = R * v; % 2-by-2 matrix multiply
      beta = beta - sigma * angle; % update the remaining angle
      poweroftwo = poweroftwo / 2;
      % update the angle from table, or eventually by just dividing by two
      if j+2 > length(angles)
          angle = angle / 2;
      else
          angle = angles(j+2);
      end
  end

  % Adjust length of output vector to be [cos(beta), sin(beta)]:
  v = v * Kn;
  return

  // C++
  #define C1
  #define C2
  #define TYPE double

  TYPE fixp_cordic(TYPE in, 
                   int n, 
                   int type)
  {
    int i;
    TYPE c,s,a;
    TYPE x,y,v;
    TYPE b;

    c = 0.5;
    s = 0.0;
    b = 1.0;

    for (i=0; i<n; i++) { 
      a = angleValues[i];
      x =  b * s;
      y =  b * c;

      if (in < 0.0) {
        c = c + x; 
        s = s - y; 
        in = in + a;
      }                        
      else {
        c = c - x; 
        s = s + y; 
        in = in - a; 
      }           
      b = b / 2;
    }

    if (type == 0)
      v = c * kValues[n-1]*2;        
    else
      v = s * kValues[n-1]*2;        

    return (v);
  }

  TYPE fixp_cos(TYPE in, 
                int n,
                int scale)
  {
    TYPE v;
    INT sign = 0;

    while ( (in < -M_PI/2) || (in > M_PI/2) ) {
      if (in < 0)
        in = in + M_PI;
      else
        in = in - M_PI;

      if (sign == 0)
        sign = 1;
      else
        sign = 0;
    }

    v = fixp_cordic(in,n,0);

    if (sign)
      v = -v;

    return (v);
  }

  TYPE fixp_sin(TYPE in, 
                int n,
                int scale)
  {
    TYPE v;
    INT sign = 0;

    while ( (in < -M_PI/2) || (in > M_PI/2) ) {
      if (in < 0)
        in = in + M_PI;
      else
        in = in - M_PI;

      if (sign == 0)
        sign = 1;
      else
        sign = 0;
    }

    v = fixp_cordic(in,n,1);

    if (sign)
      v = -v;

    return (v);
  }
*/


#define SF_C1   1
#define C1(x)   FL2FXCONST_DBL(x/(1<<SF_C1))
#define C2(x)   FL2FXCONST_DBL(x)
#define M_PI_4  FL2FXCONST_DBL(M_PI/4)
#define ITER    (DFRACT_BITS-1)

/*
  for (i=0; i<DFRACT_BITS; i++) {
    angleValues[i] = FDKatan(FDKpow(2.0,-i));
  }
*/
const FIXP_DBL angleValues[DFRACT_BITS] = {
  C1(7.853981633974483e-001), C1(4.636476090008061e-001), C1(2.449786631268641e-001), C1(1.243549945467614e-001), 
  C1(6.241880999595735e-002), C1(3.123983343026828e-002), C1(1.562372862047683e-002), C1(7.812341060101111e-003), 
  C1(3.906230131966972e-003), C1(1.953122516478819e-003), C1(9.765621895593195e-004), C1(4.882812111948983e-004), 
  C1(2.441406201493618e-004), C1(1.220703118936702e-004), C1(6.103515617420877e-005), C1(3.051757811552610e-005), 
  C1(1.525878906131576e-005), C1(7.629394531101970e-006), C1(3.814697265606496e-006), C1(1.907348632810187e-006), 
  C1(9.536743164059608e-007), C1(4.768371582030888e-007), C1(2.384185791015580e-007), C1(1.192092895507807e-007), 
  C1(5.960464477539055e-008), C1(2.980232238769530e-008), C1(1.490116119384766e-008), C1(7.450580596923828e-009), 
  C1(3.725290298461914e-009), C1(1.862645149230957e-009), C1(9.313225746154785e-010), C1(4.656612873077393e-010)
};

/*
  for (i=0; i<DFRACT_BITS; i++) {
    kValues[i] = 1.0;
    for (j=0; j<=i; j++) {
      val = FDKcos(FDKatan(FDKpow(2.0,-j)));
      kValues[i] *= val;
    }
  }
*/
const FIXP_DBL kValues[DFRACT_BITS] = {
  C2(7.071067811865476e-001), C2(6.324555320336759e-001), C2(6.135719910778964e-001), C2(6.088339125177524e-001), 
  C2(6.076482562561683e-001), C2(6.073517701412960e-001), C2(6.072776440935261e-001), C2(6.072591122988928e-001), 
  C2(6.072544793325625e-001), C2(6.072533210898753e-001), C2(6.072530315291345e-001), C2(6.072529591389450e-001), 
  C2(6.072529410413973e-001), C2(6.072529365170104e-001), C2(6.072529353859136e-001), C2(6.072529351031395e-001), 
  C2(6.072529350324459e-001), C2(6.072529350147725e-001), C2(6.072529350103542e-001), C2(6.072529350092496e-001), 
  C2(6.072529350089735e-001), C2(6.072529350089044e-001), C2(6.072529350088872e-001), C2(6.072529350088829e-001), 
  C2(6.072529350088818e-001), C2(6.072529350088816e-001), C2(6.072529350088814e-001), C2(6.072529350088814e-001), 
  C2(6.072529350088814e-001), C2(6.072529350088814e-001), C2(6.072529350088814e-001), C2(6.072529350088814e-001)
};

inline
static FIXP_DBL fixp_cordic(FIXP_DBL in, 
                            INT type)
{
  int i;
  FIXP_DBL c,s,a;
  FIXP_DBL x,y;
  int n = ITER;

  in = fMult(in,M_PI_4);
  c  = kValues[n-1] >> 1;
  s  = FL2FXCONST_DBL(0.0f);

  for (i=0; i<n; i++) { 
    a = angleValues[i];
    x = s >> i;
    y = c >> i;

    if (in < FL2FXCONST_DBL(0.0)) {
      c = c + x; 
      s = s - y; 
      in = in + a;
    }                        
    else {
      c = c - x; 
      s = s + y; 
      in = in - a; 
    }           
  }

  /* 1 headroom bit */
  if (type == 0)
    return (c);  
  else
    return (s);  
}

/*
   in:    argument
   scale: scalefactor of argument has to be in the range of 0, ... ,DFRACT_BITS-1
   type: calculate cosine 0
         calculate sine   1 
*/
static FIXP_DBL fixp_sincos(FIXP_DBL in, 
                            INT scale,
                            INT type)
{
  FIXP_DBL v;
  INT sign = 0;
  FIXP_DBL pi,pi_2;

  if (scale < 2) {
    in = in >> (2-scale);
    scale = 2;
  }

  pi   = M_PI_4 >> (scale-2);
  pi_2 = M_PI_4 >> (scale-1);
   
  /* move signal into the range of -pi/2 to +pi/2 */
  while ( (in < (-pi_2)) || (in > (pi_2)) ) {
    if (in < FL2FXCONST_DBL(0.0))
      in = in + pi;
    else
      in = in - pi;

    sign = ~sign;
  }

  /* scale signal with 2/pi => unscaled signal is in the range of [-1.0,...,+1.0[ */
  in = fMult(in,FL2FXCONST_DBL(2/M_PI)) << scale;

  v = fixp_cordic(in,type);

  if (sign)
    v = -v;

  /* compensate 1 headroom bit */
  if ( v <= FL2FXCONST_DBL(-0.5f) )
    v = (FIXP_DBL) (MINVAL_DBL+1); 
  else 
    v = SATURATE_LEFT_SHIFT(v,1,DFRACT_BITS);

  return (v);
}

/*
   in:    argument
   scale: scalefactor of argument has to be in the range of 0, ... ,DFRACT_BITS-1
*/
FIXP_DBL fixp_cos(FIXP_DBL in, 
                  INT scale)
                   
{
  FDK_ASSERT ((scale >= 0) && (scale < DFRACT_BITS));

  if (in == FL2FXCONST_DBL(0.0f))
    return /*FL2FXCONST_DBL(1.0)*/ (FIXP_DBL)MAXVAL_DBL;

  return (fixp_sincos(in,scale,0));
}

/*
   in:    argument
   scale: scalefactor of argument has to be in the range of 0, ... ,DFRACT_BITS-1
*/
FIXP_DBL fixp_sin(FIXP_DBL in, 
                  INT scale)
                   
{
  FDK_ASSERT ((scale >= 0) && (scale < DFRACT_BITS));

  if (in == FL2FXCONST_DBL(0.0f))
    return FL2FXCONST_DBL(0.0f);

  return (fixp_sincos(in,scale,1));
}

#endif /* #ifndef CORDIC_SINCOS */