本章主要展示有关数值计算的代码参考,比如空值判断、随机数、各种类型的常数、数的符号、乘方与开方、截断小数与四舍五入、连乘与阶乘、累加、最大公约数与最小公倍数、排列和组合、π、三角函数、对角函数、根据条件计算不同的表达式、在表达式内使用临时变量、逻辑运算等。
|
A |
|
1 |
=null |
|
2 |
=0 |
0 |
3 |
=if(A1==null,"null","not null") |
null |
4 |
=if(!A1,"null","not null") |
null |
5 |
=if(A2!=null,"not null","null") |
not null |
6 |
=[,1,2,3].ifn() |
1 |
7 |
=["",,,0,3].nvl() |
0 |
|
A |
|
1 |
=rand() |
0到1之间的随机数 |
2 |
=rand(1000) |
0到1000之内的随机整数 |
|
A |
|
1 |
time |
字符串"time" |
2 |
-3415 |
32位整数-3415 |
3 |
3.1415927 |
浮点数3.1415927 |
4 |
1101022000L |
64位长整数1101022000 |
5 |
12345678901 |
超过32位整数允许范围,自动解析为64位长整数12345678901 |
6 |
35% |
0.35,用百分数表示的浮点数 |
7 |
0x33 |
0x开头为16进制表示的长整数,值为51 |
8 |
'345+6 |
'开头表示字符串常数,值为字符串"345+6" |
|
A |
|
1 |
=sign(45) |
正数返回1 |
2 |
=sign(-100.34) |
负数返回-1 |
3 |
=sign(0) |
0返回0 |
4 |
=abs(-4.6) |
返回-4.6的绝对值 |
|
A |
|
1 |
=power(2,3) |
立方 |
2 |
=power(-2,3) |
立方 |
3 |
=power(4,0.5) |
平方根 |
4 |
=sqrt(8,2) |
平方根 |
5 |
=power(27,1/3) |
立方根 |
6 |
=sqrt(8,3) |
立方根 |
|
A |
|
1 |
=round(3451251.274,1) |
四舍五入保留1位小数 |
2 |
=round(3451251.274,2) |
四舍五入保留2位小数 |
3 |
=ceil(3450001.003,-2) |
全进位精确到100 |
4 |
=ceil(3450001.003,2) |
全进位保留2位小数 |
5 |
=floor(3451291.234,-2) |
全舍去精确到100 |
6 |
=floor(3451281.238,2) |
全舍去保留2位小数 |
|
A |
|
1 |
=product(2, 3, 5, 7) |
210,计算2*3*5*7的结果 |
2 |
=product([7, 4, 4]) |
112,计算序列内各数的连乘积 |
3 |
=fact(5) |
120,5的阶乘 |
4 |
=fact(0) |
1 |
|
A |
|
1 |
=[1,2,3,4].(cum(~)) |
[1,3,6,10],循环累加 |
|
A |
|
1 |
=gcd(2000, 875, 325) |
25,计算几个数的最大公约数 |
2 |
=gcd([1001, 28]) |
7,计算序列中成员的最大公约数 |
3 |
=gcd(20005, 1234) |
1,两数互质 |
4 |
=lcm(10, 35, 28) |
140,计算几个数的最小公倍数 |
5 |
=lcm(1001, 111) |
111111,计算序列中成员的最小公倍数 |
|
A |
|
1 |
=combin(10, 3) |
120,10选3的组合数 |
2 |
=combin(5, 4) |
5,5选4的组合数 |
3 |
=permut(10, 3) |
720,10选3的排列数 |
4 |
=permut(5, 4) |
120,5选4的排列数 |
|
A |
|
1 |
=pi() |
π |
2 |
=pi(4) |
4*π |
|
A |
|
1 |
=inf() |
正无穷 |
2 |
=-inf() |
负无穷 |
|
A |
|
1 |
=sin(pi(30/180)) |
正弦 |
2 |
=cos(pi()/2) |
余弦 |
3 |
=tan(pi()/4) |
正切 |
4 |
=asin(0.5) |
反正弦 |
5 |
=acos(-0.5) |
反余弦 |
6 |
=atan(1) |
反正切 |
7 |
=sinh(1) |
双曲正弦 |
8 |
=cosh(4) |
双曲余弦 |
9 |
=tanh(0.5) |
双曲正切 |
10 |
=asinh(10) |
反双曲正弦 |
11 |
=acosh(10) |
反双曲余弦 |
12 |
=atanh(0.5) |
反双曲正切 |
|
A |
|
1 |
=lg(10000) |
以10为底的对数 |
2 |
=lg(8,2) |
以2为底的对数 |
3 |
=ln(1000) |
自然对数 |
4 |
=exp(A2) |
e的n次幂 |
|
A |
|
1 |
3000 |
|
2 |
=if(A1>10000:1*0.45+450, A1>5000:A1*0.15+150;A1*0.05) |
150.0 |
3 |
manager |
|
4 |
=case(A3,"president":500,"manager":300,"employee":150) |
300 |
|
A |
|
1 |
=(a=1,b=a*3,b+4) |
7 |
2 |
=a |
1 |
3 |
=b |
3 |
|
A |
|
1 |
=and(6,10) |
2,按位与 |
2 |
=or(3,5) |
7,按位或 |
3 |
=not(6) |
-7,按位取反 |
4 |
=xor(6,11) |
13,按位异或 |
5 |
=shift(13,2) |
3,右移2位 |
6 |
=shift(13,-2) |
52,左移2位 |