当前位置:网站首页>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 .
边栏推荐
- The performance and efficiency of the model that can do three segmentation tasks at the same time is better than maskformer! Meta & UIUC proposes a general segmentation model with better performance t
- Flipping game (enumeration)
- App capture of charles+drony
- Review of network attack and defense
- [Base64 notes] [suggestions collection]
- 来了!GaussDB(for Cassandra)新特性亮相
- 【Base64笔记】「建议收藏」
- [tpm2.0 principle and Application guide] Chapter 9, 10 and 11
- 鸿蒙智能家居【1.0】
- ES6笔记一
猜你喜欢

多个kubernetes集群如何实现共享同一个存储

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

【塔望方法论】塔望3W消费战略 - U&A研究法

Version 2.0 of tapdata, the open source live data platform, has been released

如何选择合适的自动化测试工具?
![[Blue Bridge Cup training 100 questions] sort scratch from small to large. Blue Bridge Cup scratch competition special prediction programming question centralized training simulation exercise question](/img/08/5f4b4e2700606554516807c01454fd.png)
[Blue Bridge Cup training 100 questions] sort scratch from small to large. Blue Bridge Cup scratch competition special prediction programming question centralized training simulation exercise question

【软件测试】从企业版BOSS直聘,看求职简历,你没被面上是有原因的

二叉树的基本概念和性质
![Learn open62541 -- [67] add custom enum and display name](/img/98/e5e25af90b3f98c2be11d7d21e5ea6.png)
Learn open62541 -- [67] add custom enum and display name

Micro service remote debug, nocalhost + rainbow micro service development second bullet
随机推荐
In the first half of 2022, I found 10 books that have been passed around by my circle of friends
PTA 1101 B是A的多少倍
链式二叉树的基本操作(C语言实现)
我感觉被骗了,微信内测 “大小号” 功能,同一手机号可注册两个微信
2022.07.02
Charles+Postern的APP抓包
Redis publishing and subscription
Micro service remote debug, nocalhost + rainbow micro service development second bullet
ip netns 命令(备忘)
虚拟数字人里的生意经
50亿,福建又诞生一只母基金
2022上半年朋友圈都在传的10本书,找到了
POJ 1182: food chain (parallel search) [easy to understand]
Redis cluster and expansion
Cloud security daily 220707: Cisco Expressway series and telepresence video communication server have found remote attack vulnerabilities and need to be upgraded as soon as possible
2022年推荐免费在线接收短信平台(国内、国外)
2022-07-04 matlab读取视频帧并保存
SD_ DATA_ SEND_ SHIFT_ REGISTER
[software test] from the direct employment of the boss of the enterprise version, looking at the resume, there is a reason why you are not covered
UVALive – 4621 Cav 贪心 + 分析「建议收藏」