Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

$%ARCCOS

Draft MDC Standard

2 MATH Library
2.2 ARCCOS

Option 1, optimized for speed, not precision.

ARCCOS(X) ;
	; This version of the function is
	; optimized for speed, not for precision.
	; The ‘precision’ parameter is not supported,
	; and the precision is at best 2 in 10**–8.
	;
	New A,N,R,SIGN,XX
	If X<–1 Set $Ecode=",M28,"
	If X>1 Set $Ecode=",M28,"
	Set SIGN=1 Set:X<0 X=-X,SIGN=–1
	Set A(0)=1.5707963050,A(1)=–0.2145988016,A(2)=0.0889789874
	Set A(3)=–0.0501743046,A(4)=0.0308918810,A(5)=–0.0170881256
	Set A(6)=0.0066700901,A(7)=–0.0012624911
	Set R=A(0),XX=1 For N=1:1:7 Set XX=XX*X,R=A(N)*XX+R
	Set R=$%SQRT^MATH(1-X,11)*R
	;
	Quit R*SIGN

Option 2, optimized for precision, not speed.

ARCCOS(X,PREC) ;
	;
	New L,LIM,K,SIG,SIGS,VALUE
	;
	If X<–1 Set $Ecode=",M28,"
	If X>1 Set $Ecode=",M28,"
	Set PREC=$Get(PREC,11)
	If $Translate(X,"-")=1 Quit 0
	;
	Set SIG=$Select(X<0:–1,1:1),VALUE=1-(X*X)
	Set X=$%SQRT^MATH(VALUE,PREC)
	If $Translate(X,"-")=1 Do  Quit VALUE
	. Set VALUE=$%PI^MATH()/2*X
	. Quit
	;
	If X>0.9 Do  Quit VALUE
	. Set SIGS=$Select(X<0:–1,1:1)
	. Set VALUE=1/(1/X/X–1)
	. Set X=$%SQRT^MATH(VALUE,PREC)
	. Set VALUE=$%ARCTAN^MATH(X,PREC)*SIGS
	. Quit
	Set (VALUE,L)=X
	Set LIM=$Select((PREC+3)'>11:PREC+3,1:11),@("LIM=1E-"_LIM)
	For K=3:2 Do  Quit:($Translate(L,"-")<LIM)
	. Set L=L*X*X*(K–2)/(K–1)*(K–2)/K,VALUE=VALUE+L
	. Quit
	Quit $Select(SIG<0:$%PI^MATH()-VALUE,1:VALUE)
Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

Copyright © Standard Documents; 1977-2024 MUMPS Development Committee;
Copyright © Examples: 1995-2024 Ed de Moel;
Copyright © Annotations: 2003-2008 Jacquard Systems Research
Copyright © Annotations: 2008-2024 Ed de Moel.

Some specifications are "approved for inclusion in a future standard". Note that the MUMPS Development Committee cannot guarantee that such future standards will indeed be published.

This page most recently updated on 16-Nov-2023, 14:54:20.

For comments, contact Ed de Moel (demoel@jacquardsystems.com)