当前位置:网站首页>Number - number (Lua)
Number - number (Lua)
2022-07-07 19:14:00 【Just be interesting】
The number - number
stay Lua 5.3 The previous version ,number There is only one numerical form , Double precision floating point type . from Lua 5.3 After version ,Lua Of number Data types introduce shaping , Thus, there are two numerical representations , One is 64 position integer integer and Double precision floating point float.
-- As follows
a = 1 --integer
b = 1.0 --float
c = 1e4 --float
When the numerical constant is decimal or Index time ,number I'll take it as float, The rest are integers
Arithmetic operations
number Because of the distinction between integer and floating point , Therefore, we should pay attention to distinguish the differences in arithmetic operations .
| The operator | describe |
|---|---|
| + | Add |
| - | Subtraction |
| * | Multiplication |
| / | division , Keep decimal places |
| % | Remainder |
| ^ | Power |
| - | Minus sign |
| //(Lua5.3 Only after that ) | division , Don't keep decimal places ( Whether it's an integer or a floating point number ) |
+ Add Integers are added into integers , In addition, floating point numbers
- Subtraction Integers are subtracted into integers , In addition, floating point numbers
* Multiplication Multiply integers into integers , In addition, floating point numbers
\ division ( Keep decimal places ), Whether it's an integer or a floating point number , The results are all floating-point numbers
^ Power , Whether it's an integer or a floating point number , The result is a floating-point number
\\ division ( Don't keep decimal places ), Divide an integer by an integer , The rest are floating point numbers
Math library
- Judgment type
math.type: Judge number The type is integer still float (Lua 5.3)
- integer
math.floor: Rounding down
math.ceil: Rounding up
math.modf: Round to zero , Returns two values , One is an integer , One is a decimal ( The fractional part )
a, b = 1.5, -1.5
print(math.floor(a), math.floor(b)) --1 -2
print(math.ceil(a), math.ceil(b)) -- 2 -1
print(math.modf(a)) -- 1 0.5
print(math.modf(b)) -- -1 -0.5
math.maxintegerandmath.minintegerNamely Maximum integer and Minimum integer , If the integer exceeds the expression ( Value overflow ), There will be a loop .Generally, it will not overflow , But we still need to pay attention to .
边栏推荐
- SD_ DATA_ SEND_ SHIFT_ REGISTER
- Scientists have observed for the first time that the "electron vortex" helps to design more efficient electronic products
- 线程池中的线程工厂
- 学习open62541 --- [67] 添加自定义Enum并显示名字
- [HDU] 5248 sequence transformation (greedy + dichotomy) [recommended collection]
- ES6 note 1
- 6. About JWT
- "Decryption" Huawei machine vision Corps: Huawei is moving up and the industry is moving forward
- IP netns command (memo)
- 直播预约通道开启!解锁音视频应用快速上线的秘诀
猜你喜欢

微信网页调试8.0.19换掉X5内核,改用xweb,所以x5调试方式已经不能用了,现在有了解决方案

cmd命令进入MySQL时报服务名或者命令错误(傻瓜式教学)

6. About JWT

Realize payment function in applet

Multimodal point cloud fusion and visual location based on image and laser

Numpy——2.数组的形状

Borui data was selected in the 2022 love analysis - Panoramic report of it operation and maintenance manufacturers

RISCV64

3.关于cookie

10 schemes to ensure interface data security
随机推荐
testing and SQA_ Dynamic white box test [easy to understand]
从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks
数据验证框架 Apache BVal 再使用
完整的电商系统
企业MES制造执行系统的分类与应用
Reject policy of thread pool
UVALive – 4621 Cav 贪心 + 分析「建议收藏」
Former richest man, addicted to farming
Basic concepts and properties of binary tree
For friends who are not fat at all, nature tells you the reason: it is a genetic mutation
LeetCode1051(C#)
[HDU] 5248 sequence transformation (greedy + dichotomy) [recommended collection]
testing and SQA_动态白盒測试[通俗易懂]
Borui data was selected in the 2022 love analysis - Panoramic report of it operation and maintenance manufacturers
數據驗證框架 Apache BVal 再使用
虚拟数字人里的生意经
Golang client server login
如何选择合适的自动化测试工具?
鸿蒙智能家居【1.0】
How to choose the appropriate automated testing tools?