X++ 数学运行时函数

注释

社区兴趣团体现已从 Yammer 迁移到Microsoft Viva Engage。 若要加入 Viva Engage 社区并参与最新讨论,请填写 “请求访问财务和运营 Viva Engage 社区 ”表单,然后选择要加入的社区。

本文介绍数学运行时函数。

这些函数执行数学计算。

腹肌

检索实数的绝对值。 示例:

  • abs(-100.0) 返回值 100.0
  • abs(30.56) 返回值 30.56

Syntax

real abs(real arg)

参数

参数 Description
参数 要获取其绝对值的数字。

返回值

arg 的绝对值。

Example

static void absExample(Args _args)
{
    real r1;
    real r2;
    ;
    r1 = abs(-3.14);
    r2 = abs(3.14);
    if (r1 == r2)
    {
        print "abs of values are the same";
        pause;
    }
}

acos

检索实数的反余弦值。

注释

-1 范围之外的参数值会导致以下运行时错误:“三角函数的参数超出范围。

Syntax

real acos(real arg)

参数

参数 Description
参数 要检索其余弦值的数字。

返回值

参数的弧余弦值。

Example

static void acosExample(Args _args)
{
    real r;
    str  s;
    ;
    r = acos(0.0);
    s = strFmt("The arc cosine of 0.0 is %1 ", r);
    print s;
    pause;
}

asin

检索实数的反正弦值。

注释

-1 范围之外的参数值会导致以下运行时错误:“三角函数的参数超出范围。

Syntax

real asin(real arg)

参数

参数 Description
参数 要计算其正弦值的数字。

返回值

指定数字的反正弦值。

注解

aSin(0.36) 返回 0.37

atan

检索实数的反正切值。

Syntax

real atan(real arg)

参数

参数 Description
参数 要计算其反正切数的数字。

返回值

指定数字的反正切值。

注解

aTan(0.36) 返回 0.35

Example

static void atanExample(Args _args)
{
    real r;
    ;
    r = atan(1.0);
    print strFmt("The Arc Tangent of 1.0 is %1", r);
    pause;
}

corrFlagGet

检索实数的更正标志的状态。

Syntax

int corrFlagGet(real arg)

参数

参数 Description
参数 要检索其状态的标志。

返回值

如果设置了标志,则为非零值;如果清除标志,则为 0 (零)。

Example

以下示例显示 1

static void corrFlagGetExample(Args _args)
{
    real rr;
    rr = corrFlagSet(0.36,2);
    print(corrFlagGet(rr));
}

corrFlagSet

控制实数的更正标志。

Syntax

real corrFlagSet(real real, int arg)

参数

参数 Description
real 打开或关闭更正标志的数字。
参数 0 关闭标志;一个非零值,用于打开标志。

返回值

如果标志现已关闭,则为 0;如果标志现已打开,则为非零值。

因为

检索实数的余弦值。

Syntax

real cos(real arg)

参数

参数 Description
参数 要查找余弦值的数字。

返回值

指定数字的余弦值。

注解

arg 参数的值必须以弧度为单位。

Example

下面的代码示例显示 0.76

static void cosExample(Args _arg)
{
    real r;
    ;
    r = cos(15);
    print strFmt("Cos of 15 is %1", r);
    pause;
}

cosh

检索实数的双曲余弦值。

注释

-250 到 250 范围内的参数值会导致以下运行时错误:“三角函数的参数超出范围。

Syntax

real cosh(real arg)

参数

参数 Description
参数 要计算余弦值的双曲数。

返回值

指定数字的双曲余弦值。

注解

arg 参数的值必须以弧度为单位。

Example

static void coshExample(Args _arg)
{
    real r;
    ;
    r = cosh(0.1);
    print "The hyperbolic cosine of 0.1 is " + num2Str(r, 2, 2, 1, 1);
    pause;
}

decRound

将数字舍入到指定的小数位数。

Syntax

real decRound(real figure, int decimals)

参数

参数 Description
数字 要舍入的数值。
小数 要舍入到的小数位数。

返回值

指定数字的值,舍入为指定小数位数。

注解

十进制参数的值可以是正、0(零)或负。

  • decRound(1234.6574,2) 返回值 1234.66
  • decRound(1234.6574,0) 返回值 1235
  • decRound(1234.6574,-2) 返回值 1200
  • decRound(12345.6789,1) 返回值 12345.70
  • decRound(12345.6789,-1) 返回值 12350.00

exp

检索指定实数的自然反对数。

Syntax

real exp(real arg)

参数

参数 Description
参数 要计算其自然反对数的实数。

返回值

指定实数的自然反对数。

注解

计算的自然反对数是自然对数 e 提升到 arg 参数指示的幂。

Example

static void expExample(Args _arg)
{
    real r1;
    real r2;
    ;
    r1 = exp(2.302585093);
    r2 = exp10(2.302585093);
    print strFmt("exp of 2.302585093 is %1", r1);
    print strFmt("exp10 of 230258 is %1", r2);
    pause;
}

exp10

检索指定实数的 base-10 反对数。

Syntax

real exp10(real decimal)

参数

参数 Description
十进制 要计算基数 10 反对数的实数。

返回值

进制 参数值的基于 10 的反对数。

Example

static void exp10Example(Args _arg)
{
    real r1;
    real r2;
    ;
    r1 = exp(2.302585093);
    r2 = exp10(2.302585093);
    print strFmt("exp of 2.302585093 is %1", r1);
    print strFmt("exp10 of 230258 is %1", r2);
    pause;
}

frac

检索实数的十进制部分。

Syntax

real frac(real decimal)

参数

参数 Description
十进制 要检索其小数部分的实数。

返回值

指定数字的十进制部分。

注解

frac(12.345) 返回值 0.345

log10

检索实数的 10 位对数。

Syntax

real log10(real arg)

参数

参数 Description
参数 要计算其对数的数字。

返回值

指定数字的 base-10 对数。

注解

log10(200) 返回值 2.30

logN

检索指定实数的自然对数。

Syntax

real logN(real arg)

参数

参数 Description
参数 要计算其自然对数的数字。

返回值

指定数字的自然对数。

注解

logN(45) 返回值 3.81

最大值

检索两个指定值中的较大值。

anytype max(anytype object1, anytype object2)

参数

参数 Description
object1 第一个值。
object2 第二个值。

返回值

object1object2 参数指定的两个值中的较大值。

注解

  • max(12.0,12.1) 返回值 12.1
  • max(2,33) 返回值 33

分钟

检索两个指定值中的较小值。

anytype min(anytype object1, anytype object2)

参数

参数 Description
object1 第一个值。
object2 第二个值。

返回值

由 object1object2 参数指定的两个值的较小值。

注解

min(2,33) 返回值 2

Example

static void minExample(Args _arg)
{
    anytype a;
    real r = 3.0;
    real s = 2.0;

    a = min(r, s);
    print num2Str(a, 1, 2, 1, 1) + " is less than the other number.";
}

权力

将实数提升到另一个实数的幂。

Syntax

real power(real arg, real exponent)

参数

参数 Description
参数 要计算其幂的数字。
指数 要引发 arg 参数指定的数字的数字。

返回值

实数,即 arg 参数指定的数字与 指数 参数所指定的数字的幂。

注解

  • power(5.0,2.0) 返回值 25.0
  • power(4.0,0.5) 返回值 2.0

四舍五入

将实数舍入到另一个实数的最接近的倍数。

Syntax

real round(real _arg, real _decimals)

参数

参数 Description
_精 氨 酸 原始数字。
_小数 _arg参数的值必须舍入为倍数的数字。

返回值

该数字是 _decimals 参数指定的值的倍数,并且最接近 由_arg 参数指定的值。

注解

若要将实数舍入到指定的小数位数,请使用 解序函数

注解

  • round(123.45,5.00) 返回值 125.00
  • round(7.45,1.05) 返回值 7.35
  • round(23.9,5.0) 返回值 25.00
  • round(26.1,5.0) 返回值 25.00

sin

检索实数的正弦值。

Syntax

real sin(real _arg)

参数

参数 Description
_精 氨 酸 要计算正弦值的数字。

返回值

指定实数的正弦值。

注解

_arg 参数的值必须以弧度为单位。

Example

static void sinExample(Args _arg)
{
    real angleDegrees = 15.0;
    real angleRadians;
    real pi = 3.14;
    real r;
    ;
    angleRadians = pi * angleDegrees / 180;
    r = sin(angleRadians);
    print "sin of a "
        + num2Str(angleDegrees, 2, 2, 1, 1)
        + " degree angle is "
        + num2Str(r, 2, 10, 1, 1);
    pause;
}

sinh

检索实数的双曲正弦值。

Syntax

real sinh(real _arg)

参数

参数 Description
_精 氨 酸 要计算其双曲正弦值的数字。

返回值

指定实数的双曲正弦值。

注解

-250 范围之外的 _arg 参数的值会导致以下运行时错误:“三角函数的参数超出范围。

Example

下面的示例演示 sinh 函数。

static void sinhExample(Args _arg)
{
    real angleDegrees = 45.0;
    real angleRadians;
    real pi = 3.14;
    real r;
    ;
    angleRadians = pi * angleDegrees / 180;
    r = sinh(angleRadians);
    print "sinh of a "
    + num2Str(angleDegrees, 2, 2, 1, 1)
    + " degree angle is "
    + num2Str(r, 2, 15, 1, 1);
    pause;
}

检索实数的正切值。

Syntax

real tan(real arg)

参数

参数 Description
参数 要计算其正切的实数。

返回值

指定实数的正切值。

注解

超出 -250 到 250 范围的 arg 参数的值会导致以下运行时错误:“三角函数的参数超出范围。

Example

以下示例演示 tan 函数。

static void tanExample(Args _arg)
{
    real r;
    ;
    r = tan(250);
    print strFmt("Tan of 250 is %1", r);
    pause;
}

tanh

检索实数的双曲正切值。

Syntax

real tanh(real _arg)

参数

参数 Description
_精 氨 酸 要计算其双曲正切数的数字。

返回值

指定实数的双曲正切值。

Example

以下示例演示 tanh 函数。

static void tanhExample(Args _arg)
{
    real r;
    ;
    r = tanh(0.1);
    print "The hyperbolic tangent of angle 0.1 is "
    + num2Str(r, 2, 10, 1, 1);
    pause;
}

trunc

通过删除任何小数位来截断实数。

Syntax

real trunc(real _decimal)

参数

参数 Description
_十进制 要截断的数字。

返回值

删除小数位数后等效于 _decimal 参数的值的数字。

注解

此函数始终将数字向下舍入为完整的整数。

Example

以下示例截断 2.7147 到 2.00。

static void truncExample(Args _arg)
{
    real r;
    ;
    r = trunc(2.7147);
    print strFmt("r = %1",  r);
    pause;
}