30 lines
1.5 KiB
Mathematica
30 lines
1.5 KiB
Mathematica
YSESLOG ;SLC/DCM-UTILITY ROUTINE TO CALCULATE LOGARITHMS TO BASE e OR BASE 10 ; 10/18/88 16:54 ;
|
|
;;5.01;MENTAL HEALTH;;Dec 30, 1994
|
|
;DECISION EXPERT SYSTEM (VERSION 1.0) FOR MENTAL HEALTH PACKAGE - DWIGHT MCDANIEL / REGION 5 ISC, SLC
|
|
;PASS NUMBER TO A5AESLOG IN VARIABLE ESLN; LOGARIGHM OF NUMBER RETURNED AS ESY
|
|
;DECIMAL ACCURACY IS 8 DECIMAL DIGITS
|
|
CALC S ESLU=ESL1-.707106781187/(ESL1+.70710681187),ESLV=ESLU*ESLU
|
|
S ESLU=.434259751292*ESLV+.576584342056*ESLV+.961800762286*ESLV+2.885390072738*ESLU
|
|
Q
|
|
EXIT S ESLS=0 S:ESY<0 ESLS=1,ESY=-ESY S ESY=$E(ESY+.000000005,1,ESY["."+8),ESY=$E("-",ESLS)_ESY D CONV:ESE S:$E(ESY,$L(ESY))["0" ESY=$E(ESY,1,$L(ESY)-1)
|
|
EXIT1 K ESLI,ESL1,ESLS,ESLU,ESLV,ESLZ Q
|
|
CONV I ESY>10 F ESLI=0:1 Q:ESY<10 S ESY=ESY/10
|
|
I ESY<1 F ESLI=0:-1 Q:ESY>1 S ESY=ESY*10
|
|
S ESY=$E("-",ESLS)_ESY_"E"_ESLI Q
|
|
;
|
|
LOG ; Called by routine YSEUT
|
|
D TEST G EXIT1:ESAB I ESLN=1 S (ESY,ESAB)=0 G EXIT1
|
|
D SCALE,CALC S ESY=ESY+ESLU/3.321928096+ESLZ G EXIT
|
|
;
|
|
LN ; Called by routine YSEUT
|
|
D TEST G EXIT1:ESAB I ESLN=1 S (ESY,ESAB)=0 G EXIT1
|
|
D SCALE,CALC S ESY=ESLZ*3.321928094887+ESY+ESLU/1.442695040889 G EXIT ;1.442695040889=1/Ln(2) 3.32192809489=Ln(10)/Ln(2)
|
|
TEST S ESAB=1 Q:'$D(ESLN) S:'$D(ESE) ESE=0 Q:'(ESLN?1N.N!(ESLN?1N.N1"."1N.N)!(ESLN?1"."1N.N))
|
|
Q:ESLN>1E24!(ESLN=0) S ESAB=0 Q
|
|
SCALE S ESLI=ESLN\1,ESL1=$E(ESLN#1,2,40) ;LI=INT,L1=FRACT PARTS OF LN
|
|
S:ESLI=0 ESLI="" S ESLZ=$L(ESLI) S:ESL1=0 ESL1="" S ESL1=ESLI_ESL1
|
|
F ESY=1:1 Q:$E(ESL1)>0 S ESLZ=ESLZ-1,ESL1=$E(ESL1,2,40)
|
|
F ESY=0:1:3 Q:$E(ESL1)>4 S ESL1=ESL1*2
|
|
S ESL1="."_ESL1,ESY=-.5-ESY
|
|
Q
|