第七十七章 Caché 函数大全 $ZARCCOS 函数

256 阅读1分钟

第七十七章 Caché 函数大全 $ZARCCOS函数

反(弧)余弦函数。

大纲

$ZARCCOS(n)

参数

  • n 有符号的十进制数字。

描述

$ZARCCOS返回n的三角逆余弦值。结果以弧度给出(小数点后18位)。

参数

n

带符号的十进制数字,范围从1到-1(含)。可以将其指定为值,变量或表达式。超出范围的数字会产生<ILLEGAL VALUE>错误。非数字字符串的值为0。

以下是$ZARCCOS返回的反余弦值:

  • 1 返回 0
  • 0 返回 1.570796326794896619
  • -1 返回 pi (3.141592653589793238)

示例

下面的示例允许比较数字的反余弦和反正弦:

/// d ##class(PHA.TEST.Function).ZARCCOS()
ClassMethod ZARCCOS()
{
	READ "Input a number: ",num
	IF num>1 { 
		WRITE !,"ILLEGAL VALUE: number too big" 
	} ELSEIF num<-1 { 
		WRITE !,"ILLEGAL VALUE: number too small" 
	} ELSE { 
		WRITE !,"the arc cosine is: ",$ZARCCOS(num)
		WRITE !,"the arc sine is: ",$ZARCSIN(num)
	}
	QUIT
}

DHC-APP>d ##class(PHA.TEST.Function).ZARCCOS()
Input a number: 1
the arc cosine is: 0
the arc sine is: 1.570796326794896619
DHC-APP>d ##class(PHA.TEST.Function).ZARCCOS()
Input a number: 0
the arc cosine is: 1.570796326794896619
the arc sine is: 0
DHC-APP>d ##class(PHA.TEST.Function).ZARCCOS()
Input a number: -1
the arc cosine is: 3.141592653589793238
the arc sine is: -1.570796326794896619
DHC-APP>d ##class(PHA.TEST.Function).ZARCCOS()
Input a number: 0.5
the arc cosine is: 1.047197551196597746
the arc sine is: .523598775598298873

以下示例比较了Caché分数数字($DECIMAL数字)和$DOUBLE数字的结果。在这两种情况下,1的反余弦正好为0:

/// d ##class(PHA.TEST.Function).ZARCCOS1()
ClassMethod ZARCCOS1()
{
	WRITE !,"the arc cosine is: ",$ZARCCOS(0.0)
	WRITE !,"the arc cosine is: ",$ZARCCOS($DOUBLE(0.0))
	WRITE !,"the arc cosine is: ",$ZARCCOS(1.0)
	WRITE !,"the arc cosine is: ",$ZARCCOS($DOUBLE(1.0))
	WRITE !,"the arc cosine is: ",$ZARCCOS(-1.0)
	WRITE !,"the arc cosine is: ",$ZARCCOS($DOUBLE(-1.0))
}

DHC-APP> d ##class(PHA.TEST.Function).ZARCCOS1()
 
the arc cosine is: 1.570796326794896619
the arc cosine is: 1.5707963267948965579
the arc cosine is: 0
the arc cosine is: 0
the arc cosine is: 3.141592653589793238
the arc cosine is: 3.1415926535897931159