home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / kmpl9803.zip / 0_ln.cmd < prev    next >
OS/2 REXX Batch file  |  1998-02-14  |  2KB  |  60 lines

  1. /* REXX-Programm 0_ln.cmd  */
  2.  
  3.    parse arg x,ND 
  4.    
  5.    /* Für Berechnung des Ln ist intern hohe Genauigkeit erforderlich. */ 
  6.    NUMERIC DIGITS ND+40
  7.    
  8.    /* lna1 = ln(1.69) */
  9.    lna1=0.||,
  10.    5247285289349821040709919737619087944083329122628682807714352193917||,
  11.    841152941153983271549167017823808545808161009529459962452580538075605143
  12.  
  13.    /* lna2 = ln(3.49) */
  14.    lna2=1.||,
  15.    2499017362143357951634986131299112939466823602028164371597327972818||,
  16.    379181900889747291289440245239282509867619774937415989840364673381082569
  17.  
  18.    /* lna3 = ln(7) */
  19.    lna3=1.||,
  20.    9459101490553133051053527434431797296370847295818611884593901499375||,
  21.    798627520692677876584985878715269930616942058511409117237522576777868431
  22.  
  23.    /* ln10 = ln(10) */
  24.    ln10=2.||,
  25.    3025850929940456840179914546843642076011014886287729760333279009675||,
  26.    726096773524802359972050895982983419677840422862486334095254650828067566
  27.  
  28.    if x<1.0E-10000 | x>1.0E+10000 | x<0 then signal VW 
  29.    if x  = 1    then do y=0;    return(y);   EXIT; end
  30.    if x >= 1    then do z=x;    sgn=+1;  SIGNAL A; end
  31.    if x <= 1    then do z=1/x;  sgn=-1;  SIGNAL A; end
  32.    
  33. A: p=10; n=0; do while (z>9.5); z=z/p; n=n+1; end
  34.  
  35.    if (5.0   <  z) then if (z <= 9.50 ) then
  36.            do aa=7.00; aln=lna3; SIGNAL B; end
  37.    if (2.430 <  z) then if (z <= 5.00 ) then
  38.            do aa=3.49; aln=lna2; SIGNAL B; end
  39.    if (1.05  <  z) then if (z <= 2.430) then
  40.            do aa=1.69; aln=lna1; SIGNAL B; end
  41.    if (0.95  <  z) then if (z <= 1.05 ) then SIGNAL C
  42.  
  43. B: tt=(z-aa)/(z+aa); t=tt*tt; u=1; m=1; v=1
  44.    do while ((u/v) > 10**(-ND-30))
  45.        g=t*(2*m-1)/(2*m+1); u=u*g; v=v+u; m=m+1; end
  46.    y=sgn*(n*ln10 + aln+2*tt*v); SIGNAL E
  47.  
  48. C: tt=(z-1)/(z+1); t=tt*tt; u=1; m=1; v=1
  49.    do while ((u/v) > 10**(-ND-30))
  50.        g=t*(2*m-1)/(2*m+1); u=u*g; v=v+u; m=m+1; end
  51.    y=sgn*(n*ln10 + 2*tt*v)
  52.  
  53. E: NUMERIC DIGITS ND+5
  54.    return(Format(y))
  55. EXIT
  56.  
  57. vW:
  58.    return(NULL)
  59.    EXIT
  60.