[613] | 1 | XLFMTH ;SF-ISC/RWF,HINES/CFB,DW - MATH FUNCTIONS;07/16/93 10:21 ;03/03/95 15:29
|
---|
| 2 | ;;8.0;KERNEL;;Jul 10, 1995
|
---|
| 3 | ABS(X) ;absolute value
|
---|
| 4 | Q $S(X<0:-X,1:X)
|
---|
| 5 | LN(X,PR) ;log base e
|
---|
| 6 | N L,M,N,O,P,Y,LIM S PR=$$PR($G(PR),11) D A G Q
|
---|
| 7 | LOG(X,PR) ;log base 10
|
---|
| 8 | N L,M,N,O,P,Y,LIM S PR=$$PR($G(PR),11) D A S Y=Y/2.30258509298749 G Q
|
---|
| 9 | ;
|
---|
| 10 | A S M=1 I X>0 F N=0:1 Q:(X/M)<10 S M=M*10
|
---|
| 11 | I X<1 F N=0:-1 Q:(X/M)>.1 S M=M*.1
|
---|
| 12 | S X=X/M
|
---|
| 13 | B S X=(X-1)/(X+1),(Y,L)=X D LIM F O=3:2 S L=L*X*X,M=L/O,Y=M+Y S:M<0 M=-M Q:M<LIM
|
---|
| 14 | S Y=Y*2+(N*2.30258509298749) Q
|
---|
| 15 | ;
|
---|
| 16 | EXP(X,PR) ;e to the X power
|
---|
| 17 | N L,M,N,O,P,Y,LIM S PR=$$PR($G(PR),11) D EX G Q
|
---|
| 18 | ;
|
---|
| 19 | EX S (Y,L)=X,Y=Y+1 D LIM F O=2:1 S L=L*X/O,Y=Y+L Q:($TR(L,"-")<LIM)
|
---|
| 20 | Q
|
---|
| 21 | PWR(Y,X,PR) ;X to the Y power
|
---|
| 22 | N L,M,N,O,P,LIM S PR=$$PR($G(PR),11) D P G Q
|
---|
| 23 | ;
|
---|
| 24 | P S:X<0 X=X*-1,Y=1/Y S P=X,X=Y D A S X=Y*P D EX
|
---|
| 25 | Q
|
---|
| 26 | LIM S LIM=$S((PR+3)'>11:PR+3,1:11),@("LIM=1E-"_LIM) Q
|
---|
| 27 | ;
|
---|
| 28 | Q Q +$J(Y,0,$S((PR-$L(Y\1))'<0:PR-$L(Y\1),1:0))
|
---|
| 29 | PR(PR,PL) Q $S('$L(PR):PL,PR>PL:PL,1:PR)
|
---|
| 30 | E(PR) ;e
|
---|
| 31 | N Y S Y=2.71828182845905 S PR=$$PR($G(PR),12) G Q
|
---|
| 32 | PI(PR) ;PI
|
---|
| 33 | N Y S Y=3.14159265358979 S PR=$$PR($G(PR),12) G Q
|
---|
| 34 | ;
|
---|
| 35 | SQRT(X,PR) ;square root of X
|
---|
| 36 | N Y,T S Y=0,PR=$$PR($G(PR),12) Q:X'>0 Y S Y=X+.5
|
---|
| 37 | L F S T=Y,Y=X/T+T/2 Q:Y'<T
|
---|
| 38 | G Q
|
---|
| 39 | SD(%S1,%S2,%N) ;%S1=SUM, %S2=SUM OF SQUARES, %N=COUNT
|
---|
| 40 | N %X,%SD S %SD=-1,%X=-1 Q:%N<2 %SD
|
---|
| 41 | S %X=%N*%S2-(%S1*%S1)/(%N*(%N-1)),%SD=$$SQRT(%X),%X=%S1/%N Q %SD
|
---|
| 42 | MIN(%1,%2) Q $S(%1<%2:%1,1:%2)
|
---|
| 43 | MAX(%1,%2) Q $S(%1<%2:%2,1:%1)
|
---|
| 44 | ;
|
---|
| 45 | DMSDEC(X,PR) ;degrees:min:sec to decimal
|
---|
| 46 | N Y S PR=$$PR($G(PR),12),Y=$P(X,":")+($P(X,":",2)/60)+($P(X,":",3)/3600) G Q
|
---|
| 47 | DECDMS(X,PR) ;decimal to degrees:min:sec
|
---|
| 48 | N Y S PR=$$PR($G(PR),5),Y=X\1,X=X-(X\1)*60,Y=Y_":"_(X\1),X=X-(X\1)*60,X=+$J(X,0,$S((PR-$L(X\1))'<0:PR-$L(X\1),1:0)) Q Y_":"_X
|
---|
| 49 | DTR(X,PR) ;degrees to radians
|
---|
| 50 | N Y S Y=X*3.14159265358979/180 S PR=$$PR($G(PR),12) G Q
|
---|
| 51 | RTD(X,PR) ;radians to degrees
|
---|
| 52 | N Y S Y=X*180/3.14159265358979 S PR=$$PR($G(PR),12) G Q
|
---|
| 53 | SINDEG(X,PR) ;sine in degrees
|
---|
| 54 | S:X[":" X=$$DMSDEC(X,12) S PR=$$PR($G(PR),10),X=$$DTR(X) Q $$SIN(X,PR)
|
---|
| 55 | SIN(X,PR) ;sine in radians
|
---|
| 56 | N L,M,N,O,P,Y,LIM,SIGN S PR=$$PR($G(PR),10) D S G Q
|
---|
| 57 | S S X=X#(2*3.14159265358979),(Y,L)=X,SIGN=-1 D LIM F O=3:2 S L=L/(O-1)*X/O*X,Y=Y+(SIGN*L) Q:($TR(L,"-")<LIM) S SIGN=SIGN*-1
|
---|
| 58 | Q
|
---|
| 59 | CSCDEG(X,PR) ;cosecant in degrees
|
---|
| 60 | S:X[":" X=$$DMSDEC(X,12) S PR=$$PR($G(PR),10),X=$$DTR(X) Q $$CSC(X,PR)
|
---|
| 61 | CSC(X,PR) ;cosecant in radians
|
---|
| 62 | N L,M,N,O,P,Y,LIM,SIGN S PR=$$PR($G(PR),10) D S S Y=1/Y G Q
|
---|
| 63 | COSDEG(X,PR) ;cosine in degrees
|
---|
| 64 | S:X[":" X=$$DMSDEC(X,12) S PR=$$PR($G(PR),10),X=$$DTR(X) Q $$COS(X,PR)
|
---|
| 65 | COS(X,PR) ;cosine in radians
|
---|
| 66 | N L,M,N,O,P,Y,LIM,SIGN S PR=$$PR($G(PR),10) D C G Q
|
---|
| 67 | C S X=X#(2*3.14159265358979),(Y,L)=1,SIGN=-1 D LIM F O=2:2 S L=L*X*X/(O-1*O),Y=Y+(SIGN*L) Q:($TR(L,"-")<LIM) S SIGN=SIGN*-1
|
---|
| 68 | Q
|
---|
| 69 | SECDEG(X,PR) ;secant in degrees
|
---|
| 70 | S:X[":" X=$$DMSDEC(X,12) S PR=$$PR($G(PR),10),X=$$DTR(X) Q $$SEC(X,PR)
|
---|
| 71 | SEC(X,PR) ;secant in radians
|
---|
| 72 | N L,M,N,O,P,Y,LIM,SIGN S PR=$$PR($G(PR),10) D C S Y=1/Y G Q
|
---|
| 73 | TANDEG(X,PR) ;tangent in degrees
|
---|
| 74 | S:X[":" X=$$DMSDEC(X,12) S PR=$$PR($G(PR),10),X=$$DTR(X) Q $$TAN(X,PR)
|
---|
| 75 | TAN(X,PR) ;tangent in radians
|
---|
| 76 | N L,M,N,O,P,Y,LIM,S,SIGN S PR=$$PR($G(PR),10) D S S S=Y D C S Y=S/Y G Q
|
---|
| 77 | COTDEG(X,PR) ;cotangent in degrees
|
---|
| 78 | S:X[":" X=$$DMSDEC(X,12) S PR=$$PR($G(PR),10),X=$$DTR(X) Q $$COT(X,PR)
|
---|
| 79 | COT(X,PR) ;contangent in radians
|
---|
| 80 | N L,M,N,O,P,Y,LIM,C,SIGN S PR=$$PR($G(PR),10) D C S C=Y D S S Y=C/Y G Q
|
---|
| 81 | ASINDEG(X,PR) ;arc-sine in degrees
|
---|
| 82 | G ASIND^XLFMTH1
|
---|
| 83 | ASIN(X,PR) ;arc-sine in radians
|
---|
| 84 | G ASIN^XLFMTH1
|
---|
| 85 | ACOSDEG(X,PR) ;arc-cosine in degrees
|
---|
| 86 | G ACOSD^XLFMTH1
|
---|
| 87 | ACOS(X,PR) ;arc-cosine in radians
|
---|
| 88 | G ACOS^XLFMTH1
|
---|
| 89 | ATANDEG(X,PR) ;arc-tangent in degrees
|
---|
| 90 | G ATAND^XLFMTH1
|
---|
| 91 | ATAN(X,PR) ;arc-tangent in radians
|
---|
| 92 | G ATAN^XLFMTH1
|
---|
| 93 | ACOTDEG(X,PR) ;arc-cotangent in degrees
|
---|
| 94 | G ACOTD^XLFMTH1
|
---|
| 95 | ACOT(X,PR) ;arc-cotangent in radians
|
---|
| 96 | G ACOT^XLFMTH1
|
---|
| 97 | ASECDEG(X,PR) ;arc-secant in degrees
|
---|
| 98 | G ASECD^XLFMTH1
|
---|
| 99 | ASEC(X,PR) ;arc-secant in radians
|
---|
| 100 | G ASEC^XLFMTH1
|
---|
| 101 | ACSCDEG(X,PR) ;arc-cosecant in degrees
|
---|
| 102 | G ACSCD^XLFMTH1
|
---|
| 103 | ACSC(X,PR) ;arc-cosecant in radians
|
---|
| 104 | G ACSC^XLFMTH1
|
---|