Vim技能修炼教程(16) - 浮点数计算函数
生活随笔
收集整理的這篇文章主要介紹了
Vim技能修炼教程(16) - 浮点数计算函数
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
浮點(diǎn)數(shù)計(jì)算函數(shù)
這一節(jié)的所有函數(shù),只有在vim編譯時(shí)支持了+float時(shí)才有效。
三角函數(shù)
- sin() : sine正弦函數(shù)
- cos() : cosine余弦函數(shù)
- tan() : tangent正切函數(shù)
- asin() : arc sine反正弦函數(shù)
- acos() : arc cosine反余弦函數(shù)
- atan() : arc tangent反正切函數(shù)
- atan2({X坐標(biāo)},{Y坐標(biāo)}) : arc tangent反正切函數(shù)
- sinh() : hyperbolic sine 雙曲正弦函數(shù)
- cosh() : hyperbolic cosine雙曲余弦函數(shù)
- tanh() : hyperbolic tangent雙曲正切函數(shù)
這些函數(shù)基本上都是對(duì)應(yīng)的C函數(shù)的封裝。比如對(duì)于雙曲正弦不熟悉的話,可以參看man sinh. 如果不理解atan2,可以man atan2.
數(shù)學(xué)計(jì)算
- abs(): 絕對(duì)值
- fmod(): 浮點(diǎn)余數(shù)
- exp(): e的乘方
- log(): 自然對(duì)數(shù)
- log10(): 以10為底的對(duì)數(shù)
- pow(): 階乘
- sqrt(): 平方根,如果求負(fù)數(shù)的平方根,返回NaN.
- isnan(): 判斷是否為NaN。比如isnan(0.0/0.0)為真。
浮點(diǎn)數(shù)轉(zhuǎn)整數(shù)
- float2nr() : 將浮點(diǎn)數(shù)轉(zhuǎn)成整數(shù)。
- round() : round off, 四舍五入
- ceil(): round up, 上舍入
- floor(): round down,下舍入
- trunc(): 簡(jiǎn)單截?cái)嘈?shù)點(diǎn)后面的數(shù)
我們來(lái)寫(xiě)個(gè)函數(shù)測(cè)試下它們的功能:
function Float2Number(arg)echo "Orginal value:"echo a:argecho "float2nr:"echo float2nr(a:arg)echo "round:"echo round(a:arg)echo "ceil:"echo ceil(a:arg)echo "floor:"echo floor(a:arg)echo "trunc:"echo trunc(a:arg) endfunction我們先試試2.06:
Orginal value: 2.06 float2nr: 2 round: 2.0 ceil: 3.0 floor: 2.0 trunc: 2.0我們?cè)僭囋?22.667:
Orginal value: 122.667 float2nr: 122 round: 123.0 ceil: 123.0 floor: 122.0 trunc: 122.0我們?cè)倏匆粋€(gè)負(fù)數(shù):-9.08
Orginal value: -9.08 float2nr: -9 round: -9.0 ceil: -9.0 floor: -10.0 trunc: -9.0最后來(lái)一個(gè)五入的負(fù)數(shù):
Orginal value: -65.96 float2nr: -65 round: -66.0 ceil: -65.0 floor: -66.0 trunc: -65.0我們總結(jié)一下:
- 除了float2nr,其它所有截?cái)嗟慕Y(jié)果還是浮點(diǎn)數(shù)
- float2nr的策略跟trunc一致,也就是說(shuō),如果要想四舍五入的話,先做round再float2nr.
- round是四舍五入,不管正負(fù),都是四舍五入。
- ceil取大于等于它的最小整數(shù)。
- floor取小于等于它的最大整數(shù)。
- trunc就是簡(jiǎn)單去掉小數(shù)部分。
總結(jié)
以上是生活随笔為你收集整理的Vim技能修炼教程(16) - 浮点数计算函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: AliSQL 20170716版本发布
- 下一篇: zookeeper 运维