source: WorldVistAEHR/trunk/r/KERNEL-XU-A4A7-USC-XG-XLF-XNOA-XPD-XQ-XVIR-ZI-ZOSF-ZOSV-ZT-ZU-%Z-XIP--XQAB--XUC--XUR--ZIN--ZTED/XLFMTH.m@ 632

Last change on this file since 632 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 3.8 KB
Line 
1XLFMTH ;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
3ABS(X) ;absolute value
4 Q $S(X<0:-X,1:X)
5LN(X,PR) ;log base e
6 N L,M,N,O,P,Y,LIM S PR=$$PR($G(PR),11) D A G Q
7LOG(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 ;
10A 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
13B 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 ;
16EXP(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 ;
19EX 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
21PWR(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 ;
24P S:X<0 X=X*-1,Y=1/Y S P=X,X=Y D A S X=Y*P D EX
25 Q
26LIM S LIM=$S((PR+3)'>11:PR+3,1:11),@("LIM=1E-"_LIM) Q
27 ;
28Q Q +$J(Y,0,$S((PR-$L(Y\1))'<0:PR-$L(Y\1),1:0))
29PR(PR,PL) Q $S('$L(PR):PL,PR>PL:PL,1:PR)
30E(PR) ;e
31 N Y S Y=2.71828182845905 S PR=$$PR($G(PR),12) G Q
32PI(PR) ;PI
33 N Y S Y=3.14159265358979 S PR=$$PR($G(PR),12) G Q
34 ;
35SQRT(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
37L F S T=Y,Y=X/T+T/2 Q:Y'<T
38 G Q
39SD(%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
42MIN(%1,%2) Q $S(%1<%2:%1,1:%2)
43MAX(%1,%2) Q $S(%1<%2:%2,1:%1)
44 ;
45DMSDEC(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
47DECDMS(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
49DTR(X,PR) ;degrees to radians
50 N Y S Y=X*3.14159265358979/180 S PR=$$PR($G(PR),12) G Q
51RTD(X,PR) ;radians to degrees
52 N Y S Y=X*180/3.14159265358979 S PR=$$PR($G(PR),12) G Q
53SINDEG(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)
55SIN(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
57S 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
59CSCDEG(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)
61CSC(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
63COSDEG(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)
65COS(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
67C 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
69SECDEG(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)
71SEC(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
73TANDEG(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)
75TAN(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
77COTDEG(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)
79COT(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
81ASINDEG(X,PR) ;arc-sine in degrees
82 G ASIND^XLFMTH1
83ASIN(X,PR) ;arc-sine in radians
84 G ASIN^XLFMTH1
85ACOSDEG(X,PR) ;arc-cosine in degrees
86 G ACOSD^XLFMTH1
87ACOS(X,PR) ;arc-cosine in radians
88 G ACOS^XLFMTH1
89ATANDEG(X,PR) ;arc-tangent in degrees
90 G ATAND^XLFMTH1
91ATAN(X,PR) ;arc-tangent in radians
92 G ATAN^XLFMTH1
93ACOTDEG(X,PR) ;arc-cotangent in degrees
94 G ACOTD^XLFMTH1
95ACOT(X,PR) ;arc-cotangent in radians
96 G ACOT^XLFMTH1
97ASECDEG(X,PR) ;arc-secant in degrees
98 G ASECD^XLFMTH1
99ASEC(X,PR) ;arc-secant in radians
100 G ASEC^XLFMTH1
101ACSCDEG(X,PR) ;arc-cosecant in degrees
102 G ACSCD^XLFMTH1
103ACSC(X,PR) ;arc-cosecant in radians
104 G ACSC^XLFMTH1
Note: See TracBrowser for help on using the repository browser.