Changeset 2995


Ignore:
Timestamp:
Jun 1, 2012, 8:31:33 PM (3 years ago)
Author:
wmb
Message:

isin.fth - before svn 2994, the calculation in set-period was using */, which is supposed to use a double-precision intermediate value to avoid overflow. However, */ is not a primitive FCode, so the FCode tokenizer was synthesizing it (incorrectly) using (overflowing) * and /. The correct fix, to retain precision, is to implement "u*/" using (double-precision) um* and um/mod .

File:
1 edited

Legend:

Unmodified
Added
Removed
  • forth/lib/isin.fth

    r2994 r2995  
    2828   2/              to #cycle/4 
    2929; 
     30: u*/  ( u1 unum udenom -- u2 )   >r um* r> um/mod  nip  ; 
    3031: set-period  ( cycle/4 -- ) 
    3132   dup to #cycle/4       ( cycle/4 ) 
     
    3334   2* dup to #cycle            ( cycle ) 
    3435   fs over / to freq           ( period ) 
    35    pi swap /  fs * to fstep   ( ) 
     36   pi fs rot u*/ to fstep   ( ) 
    3637; 
    3738 
    3839\ Multiply two fractional numbers where the scale factor is 2^15 
    39 \ : times  ( n1 n2 -- n3 )  d# 32767 */  ;   \ Insignificantly more accurate, but slower 
    40 : times  ( n1 n2 -- n3 )  *  d# 15 rshift   ; 
     40: times  ( n1 n2 -- n3 )  d# 32767 u*/  ; 
    4141 
    4242\ Computes  (1 - (theta^2 / divisor) * last) 
     
    4949 
    5050: icos  ( index -- frac ) 
    51    fstep fs 2/  */  to theta 
     51   fstep fs 2/  u*/  to theta 
    5252   theta dup times  to thetasq 
    5353   one  d# 90 cos-step  d# 56 cos-step d# 30 cos-step  d# 12 cos-step  2 cos-step  one min 
     
    6060\ This is good for the first quadrant only, i.e. 0 <= index <= fs / freq / 4 
    6161: calc-sin  ( index -- frac ) 
    62    fstep fs 2/  */  to theta 
     62   fstep fs 2/  u*/  to theta 
    6363   theta dup times to thetasq 
    6464   one  d# 72 sin-step d# 42 sin-step  d# 20 sin-step  6 sin-step  theta times  one min 
Note: See TracChangeset for help on using the changeset viewer.